001: /*
002: * Copyright 2006 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025:
026: package com.sun.tools.internal.xjc.reader.xmlschema.ct;
027:
028: import com.sun.tools.internal.xjc.model.CPropertyInfo;
029: import com.sun.tools.internal.xjc.model.TypeUse;
030: import com.sun.tools.internal.xjc.reader.xmlschema.bindinfo.BIProperty;
031: import static com.sun.tools.internal.xjc.reader.xmlschema.ct.ComplexTypeBindingMode.FALLBACK_CONTENT;
032: import static com.sun.tools.internal.xjc.reader.xmlschema.ct.ComplexTypeBindingMode.NORMAL;
033: import com.sun.xml.internal.xsom.XSComplexType;
034: import com.sun.xml.internal.xsom.XSContentType;
035: import com.sun.xml.internal.xsom.XSModelGroup;
036: import com.sun.xml.internal.xsom.XSParticle;
037: import com.sun.xml.internal.xsom.XSSimpleType;
038: import com.sun.xml.internal.xsom.XSTerm;
039: import com.sun.xml.internal.xsom.visitor.XSContentTypeVisitor;
040:
041: /**
042: * Builds a complex type that inherits from the anyType complex type.
043: *
044: * @author
045: * Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
046: */
047: final class FreshComplexTypeBuilder extends CTBuilder {
048:
049: public boolean isApplicable(XSComplexType ct) {
050: return ct.getBaseType() == schemas.getAnyType()
051: && !ct.isMixed(); // not mixed
052: }
053:
054: public void build(final XSComplexType ct) {
055: XSContentType contentType = ct.getContentType();
056:
057: contentType.visit(new XSContentTypeVisitor() {
058: public void simpleType(XSSimpleType st) {
059: builder.recordBindingMode(ct,
060: ComplexTypeBindingMode.NORMAL);
061:
062: simpleTypeBuilder.refererStack.push(ct);
063: TypeUse use = simpleTypeBuilder.build(st);
064: simpleTypeBuilder.refererStack.pop();
065:
066: BIProperty prop = BIProperty.getCustomization(ct);
067: CPropertyInfo p = prop.createValueProperty("Value",
068: false, ct, use);
069: selector.getCurrentBean().addProperty(p);
070: }
071:
072: public void particle(XSParticle p) {
073: // determine the binding of this complex type.
074:
075: builder
076: .recordBindingMode(
077: ct,
078: bgmBuilder.getParticleBinder()
079: .checkFallback(p) ? FALLBACK_CONTENT
080: : NORMAL);
081:
082: bgmBuilder.getParticleBinder().build(p);
083:
084: XSTerm term = p.getTerm();
085: if (term.isModelGroup()
086: && term.asModelGroup().getCompositor() == XSModelGroup.ALL)
087: selector.getCurrentBean().setOrdered(false);
088:
089: }
090:
091: public void empty(XSContentType e) {
092: builder.recordBindingMode(ct, NORMAL);
093: }
094: });
095:
096: // adds attributes and we are through.
097: green.attContainer(ct);
098: }
099:
100: }
|