src/share/jaxws_classes/com/sun/tools/internal/xjc/reader/xmlschema/DefaultClassBinder.java

changeset 0
373ffda63c9a
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/jaxws_classes/com/sun/tools/internal/xjc/reader/xmlschema/DefaultClassBinder.java	Wed Apr 27 01:27:09 2016 +0800
     1.3 @@ -0,0 +1,558 @@
     1.4 +/*
     1.5 + * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.  Oracle designates this
    1.11 + * particular file as subject to the "Classpath" exception as provided
    1.12 + * by Oracle in the LICENSE file that accompanied this code.
    1.13 + *
    1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.17 + * version 2 for more details (a copy is included in the LICENSE file that
    1.18 + * accompanied this code).
    1.19 + *
    1.20 + * You should have received a copy of the GNU General Public License version
    1.21 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.23 + *
    1.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.25 + * or visit www.oracle.com if you need additional information or have any
    1.26 + * questions.
    1.27 + */
    1.28 +
    1.29 +package com.sun.tools.internal.xjc.reader.xmlschema;
    1.30 +import static com.sun.tools.internal.xjc.reader.xmlschema.BGMBuilder.getName;
    1.31 +
    1.32 +import java.util.Set;
    1.33 +
    1.34 +import javax.xml.namespace.QName;
    1.35 +
    1.36 +import com.sun.codemodel.internal.JJavaName;
    1.37 +import com.sun.codemodel.internal.JPackage;
    1.38 +import com.sun.istack.internal.NotNull;
    1.39 +import com.sun.istack.internal.Nullable;
    1.40 +import com.sun.tools.internal.xjc.ErrorReceiver;
    1.41 +import com.sun.tools.internal.xjc.model.CClassInfo;
    1.42 +import com.sun.tools.internal.xjc.model.CClassInfoParent;
    1.43 +import com.sun.tools.internal.xjc.model.CClassRef;
    1.44 +import com.sun.tools.internal.xjc.model.CCustomizations;
    1.45 +import com.sun.tools.internal.xjc.model.CElement;
    1.46 +import com.sun.tools.internal.xjc.model.CElementInfo;
    1.47 +import com.sun.tools.internal.xjc.model.Model;
    1.48 +import com.sun.tools.internal.xjc.reader.Ring;
    1.49 +import com.sun.tools.internal.xjc.reader.xmlschema.bindinfo.BIClass;
    1.50 +import com.sun.tools.internal.xjc.reader.xmlschema.bindinfo.BIGlobalBinding;
    1.51 +import com.sun.tools.internal.xjc.reader.xmlschema.bindinfo.BISchemaBinding;
    1.52 +import com.sun.tools.internal.xjc.reader.xmlschema.bindinfo.BindInfo;
    1.53 +import com.sun.tools.internal.xjc.reader.xmlschema.bindinfo.BIXSubstitutable;
    1.54 +import com.sun.tools.internal.xjc.reader.xmlschema.ct.ComplexTypeFieldBuilder;
    1.55 +import com.sun.tools.internal.xjc.reader.xmlschema.ct.ComplexTypeBindingMode;
    1.56 +import com.sun.xml.internal.xsom.XSAnnotation;
    1.57 +import com.sun.xml.internal.xsom.XSAttGroupDecl;
    1.58 +import com.sun.xml.internal.xsom.XSAttributeDecl;
    1.59 +import com.sun.xml.internal.xsom.XSAttributeUse;
    1.60 +import com.sun.xml.internal.xsom.XSComplexType;
    1.61 +import com.sun.xml.internal.xsom.XSComponent;
    1.62 +import com.sun.xml.internal.xsom.XSContentType;
    1.63 +import com.sun.xml.internal.xsom.XSDeclaration;
    1.64 +import com.sun.xml.internal.xsom.XSElementDecl;
    1.65 +import com.sun.xml.internal.xsom.XSFacet;
    1.66 +import com.sun.xml.internal.xsom.XSIdentityConstraint;
    1.67 +import com.sun.xml.internal.xsom.XSModelGroup;
    1.68 +import com.sun.xml.internal.xsom.XSModelGroupDecl;
    1.69 +import com.sun.xml.internal.xsom.XSNotation;
    1.70 +import com.sun.xml.internal.xsom.XSParticle;
    1.71 +import com.sun.xml.internal.xsom.XSSchema;
    1.72 +import com.sun.xml.internal.xsom.XSSchemaSet;
    1.73 +import com.sun.xml.internal.xsom.XSSimpleType;
    1.74 +import com.sun.xml.internal.xsom.XSType;
    1.75 +import com.sun.xml.internal.xsom.XSWildcard;
    1.76 +import com.sun.xml.internal.xsom.XSXPath;
    1.77 +
    1.78 +import org.xml.sax.Locator;
    1.79 +
    1.80 +/**
    1.81 + * Default classBinder implementation. Honors <jaxb:class> customizations
    1.82 + * and default bindings.
    1.83 + */
    1.84 +final class DefaultClassBinder implements ClassBinder
    1.85 +{
    1.86 +    private final SimpleTypeBuilder stb = Ring.get(SimpleTypeBuilder.class);
    1.87 +    private final Model model = Ring.get(Model.class);
    1.88 +
    1.89 +    protected final BGMBuilder builder = Ring.get(BGMBuilder.class);
    1.90 +    protected final ClassSelector selector = Ring.get(ClassSelector.class);
    1.91 +
    1.92 +    protected final XSSchemaSet schemas = Ring.get(XSSchemaSet.class);
    1.93 +
    1.94 +    public CElement attGroupDecl(XSAttGroupDecl decl) {
    1.95 +        return allow(decl,decl.getName());
    1.96 +    }
    1.97 +
    1.98 +    public CElement attributeDecl(XSAttributeDecl decl) {
    1.99 +        return allow(decl,decl.getName());
   1.100 +    }
   1.101 +
   1.102 +    public CElement modelGroup(XSModelGroup mgroup) {
   1.103 +        return never();
   1.104 +    }
   1.105 +
   1.106 +    public CElement modelGroupDecl(XSModelGroupDecl decl) {
   1.107 +        return never();
   1.108 +    }
   1.109 +
   1.110 +
   1.111 +    public CElement complexType(XSComplexType type) {
   1.112 +        CElement ci = allow(type,type.getName());
   1.113 +        if(ci!=null)    return ci;
   1.114 +
   1.115 +        // no customization is given -- do as the default binding.
   1.116 +
   1.117 +        BindInfo bi = builder.getBindInfo(type);
   1.118 +
   1.119 +        if(type.isGlobal()) {
   1.120 +            QName tagName = null;
   1.121 +            String className = deriveName(type);
   1.122 +            Locator loc = type.getLocator();
   1.123 +
   1.124 +            if(getGlobalBinding().isSimpleMode()) {
   1.125 +                // in the simple mode, we may optimize it away
   1.126 +                XSElementDecl referer = getSoleElementReferer(type);
   1.127 +                if(referer!=null && isCollapsable(referer)) {
   1.128 +                    // if a global element contains
   1.129 +                    // a collpsable complex type, we bind this element to a named one
   1.130 +                    // and collapses element and complex type.
   1.131 +                    tagName = getName(referer);
   1.132 +                    className = deriveName(referer);
   1.133 +                    loc = referer.getLocator();
   1.134 +                }
   1.135 +            }
   1.136 +
   1.137 +            // by default, global ones get their own classes.
   1.138 +
   1.139 +            JPackage pkg = selector.getPackage(type.getTargetNamespace());
   1.140 +
   1.141 +            return new CClassInfo(model,pkg,className, loc,getTypeName(type),tagName,type,bi.toCustomizationList());
   1.142 +        } else {
   1.143 +            XSElementDecl element = type.getScope();
   1.144 +
   1.145 +            if( element.isGlobal() && isCollapsable(element)) {
   1.146 +                if(builder.getBindInfo(element).get(BIClass.class)!=null)
   1.147 +                    // the parent element was bound to a class. Don't bind this again to
   1.148 +                    // cause unnecessary wrapping
   1.149 +                    return null;
   1.150 +
   1.151 +                // generate one class from element and complex type together.
   1.152 +                // this needs to be done before selector.isBound to avoid infinite recursion.
   1.153 +
   1.154 +                // but avoid doing so when the element is mapped to a class,
   1.155 +                // which creates unnecessary classes
   1.156 +                return new CClassInfo( model, selector.getClassScope(),
   1.157 +                    deriveName(element), element.getLocator(), null,
   1.158 +                    getName(element), element, bi.toCustomizationList() );
   1.159 +            }
   1.160 +
   1.161 +
   1.162 +            CElement parentType = selector.isBound(element,type);
   1.163 +
   1.164 +            String className;
   1.165 +            CClassInfoParent scope;
   1.166 +
   1.167 +
   1.168 +            if( parentType!=null
   1.169 +             && parentType instanceof CElementInfo
   1.170 +             && ((CElementInfo)parentType).hasClass() ) {
   1.171 +                // special case where we put a nested 'Type' element
   1.172 +                scope = (CElementInfo)parentType;
   1.173 +                className = "Type";
   1.174 +            } else {
   1.175 +                // since the parent element isn't bound to a type, merge the customizations associated to it, too.
   1.176 +//                custs = CCustomizations.merge( custs, builder.getBindInfo(type.getScope()).toCustomizationList());
   1.177 +                className = builder.getNameConverter().toClassName(element.getName());
   1.178 +
   1.179 +                BISchemaBinding sb = builder.getBindInfo(
   1.180 +                    type.getOwnerSchema() ).get(BISchemaBinding.class);
   1.181 +                if(sb!=null)    className = sb.mangleAnonymousTypeClassName(className);
   1.182 +                scope = selector.getClassScope();
   1.183 +            }
   1.184 +
   1.185 +            return new CClassInfo(model, scope, className, type.getLocator(), null, null, type, bi.toCustomizationList() );
   1.186 +        }
   1.187 +    }
   1.188 +
   1.189 +    private QName getTypeName(XSComplexType type) {
   1.190 +        if(type.getRedefinedBy()!=null)
   1.191 +            return null;
   1.192 +        else
   1.193 +            return getName(type);
   1.194 +    }
   1.195 +
   1.196 +    /**
   1.197 +     * Returns true if the complex type of the given element can be "optimized away"
   1.198 +     * and unified with its parent element decl to form a single class.
   1.199 +     */
   1.200 +    private boolean isCollapsable(XSElementDecl decl) {
   1.201 +        XSType type = decl.getType();
   1.202 +
   1.203 +        if(!type.isComplexType())
   1.204 +            return false;   // not a complex type
   1.205 +
   1.206 +        if(decl.getSubstitutables().size()>1 || decl.getSubstAffiliation()!=null)
   1.207 +            // because element substitution calls for a proper JAXBElement hierarchy
   1.208 +            return false;
   1.209 +
   1.210 +        if(decl.isNillable())
   1.211 +            // because nillable needs JAXBElement to represent correctly
   1.212 +            return false;
   1.213 +
   1.214 +        BIXSubstitutable bixSubstitutable = builder.getBindInfo(decl).get(BIXSubstitutable.class);
   1.215 +        if(bixSubstitutable !=null) {
   1.216 +            // see https://jaxb.dev.java.net/issues/show_bug.cgi?id=289
   1.217 +            // this customization forces non-collapsing behavior.
   1.218 +            bixSubstitutable.markAsAcknowledged();
   1.219 +            return false;
   1.220 +        }
   1.221 +
   1.222 +        if( getGlobalBinding().isSimpleMode() && decl.isGlobal()) {
   1.223 +            // in the simple mode, we do more aggressive optimization, and get rid of
   1.224 +            // a complex type class if it's only used once from a global element
   1.225 +            XSElementDecl referer = getSoleElementReferer(decl.getType());
   1.226 +            if(referer!=null) {
   1.227 +                assert referer==decl;  // I must be the sole referer
   1.228 +                return true;
   1.229 +            }
   1.230 +        }
   1.231 +
   1.232 +        if(!type.isLocal() || !type.isComplexType())
   1.233 +            return false;
   1.234 +
   1.235 +        return true;
   1.236 +    }
   1.237 +
   1.238 +    /**
   1.239 +     * If only one global {@link XSElementDecl} is refering to {@link XSType},
   1.240 +     * return that element, otherwise null.
   1.241 +     */
   1.242 +    private @Nullable XSElementDecl getSoleElementReferer(@NotNull XSType t) {
   1.243 +        Set<XSComponent> referer = builder.getReferer(t);
   1.244 +
   1.245 +        XSElementDecl sole = null;
   1.246 +        for (XSComponent r : referer) {
   1.247 +            if(r instanceof XSElementDecl) {
   1.248 +                XSElementDecl x = (XSElementDecl) r;
   1.249 +                if(!x.isGlobal())
   1.250 +                    // local element references can be ignored, as their names are either given
   1.251 +                    // by the property, or by the JAXBElement (for things like mixed contents)
   1.252 +                    continue;
   1.253 +                if(sole==null)  sole=x;
   1.254 +                else            return null;    // more than one
   1.255 +            } else {
   1.256 +                // if another type refers to this type, that means
   1.257 +                // this type has a sub-type, so type substitution is possible now.
   1.258 +                return null;
   1.259 +            }
   1.260 +        }
   1.261 +
   1.262 +        return sole;
   1.263 +    }
   1.264 +
   1.265 +    public CElement elementDecl(XSElementDecl decl) {
   1.266 +        CElement r = allow(decl,decl.getName());
   1.267 +
   1.268 +        if(r==null) {
   1.269 +            QName tagName = getName(decl);
   1.270 +            CCustomizations custs = builder.getBindInfo(decl).toCustomizationList();
   1.271 +
   1.272 +            if(decl.isGlobal()) {
   1.273 +                if(isCollapsable(decl)) {
   1.274 +                    // we want the returned type to be built as a complex type,
   1.275 +                    // so the binding cannot be delayed.
   1.276 +                    return selector.bindToType(decl.getType().asComplexType(),decl,true);
   1.277 +                } else {
   1.278 +                    String className = null;
   1.279 +                    if(getGlobalBinding().isGenerateElementClass())
   1.280 +                        className = deriveName(decl);
   1.281 +
   1.282 +                    // otherwise map global elements to JAXBElement
   1.283 +                    CElementInfo cei = new CElementInfo(
   1.284 +                        model, tagName, selector.getClassScope(), className, custs, decl.getLocator());
   1.285 +                    selector.boundElements.put(decl,cei);
   1.286 +
   1.287 +                    stb.refererStack.push(decl);    // referer is element
   1.288 +                    cei.initContentType( selector.bindToType(decl.getType(),decl), decl, decl.getDefaultValue() );
   1.289 +                    stb.refererStack.pop();
   1.290 +                    r = cei;
   1.291 +                }
   1.292 +            }
   1.293 +        }
   1.294 +
   1.295 +        // have the substitution member derive from the substitution head
   1.296 +        XSElementDecl top = decl.getSubstAffiliation();
   1.297 +        if(top!=null) {
   1.298 +            CElement topci = selector.bindToType(top,decl);
   1.299 +
   1.300 +            if(r instanceof CClassInfo && topci instanceof CClassInfo)
   1.301 +                ((CClassInfo)r).setBaseClass((CClassInfo)topci);
   1.302 +            if (r instanceof CElementInfo && topci instanceof CElementInfo)
   1.303 +                ((CElementInfo)r).setSubstitutionHead((CElementInfo)topci);
   1.304 +        }
   1.305 +
   1.306 +        return r;
   1.307 +    }
   1.308 +
   1.309 +    public CClassInfo empty( XSContentType ct ) { return null; }
   1.310 +
   1.311 +    public CClassInfo identityConstraint(XSIdentityConstraint xsIdentityConstraint) {
   1.312 +        return never();
   1.313 +    }
   1.314 +
   1.315 +    public CClassInfo xpath(XSXPath xsxPath) {
   1.316 +        return never();
   1.317 +    }
   1.318 +
   1.319 +    public CClassInfo attributeUse(XSAttributeUse use) {
   1.320 +        return never();
   1.321 +    }
   1.322 +
   1.323 +    public CElement simpleType(XSSimpleType type) {
   1.324 +        CElement c = allow(type,type.getName());
   1.325 +        if(c!=null) return c;
   1.326 +
   1.327 +        if(getGlobalBinding().isSimpleTypeSubstitution() && type.isGlobal()) {
   1.328 +            return new CClassInfo(model,selector.getClassScope(),
   1.329 +                    deriveName(type), type.getLocator(), getName(type), null, type, null );
   1.330 +        }
   1.331 +
   1.332 +        return never();
   1.333 +    }
   1.334 +
   1.335 +    public CClassInfo particle(XSParticle particle) {
   1.336 +        return never();
   1.337 +    }
   1.338 +
   1.339 +    public CClassInfo wildcard(XSWildcard wc) {
   1.340 +        return never();
   1.341 +    }
   1.342 +
   1.343 +
   1.344 +    // these methods won't be used
   1.345 +    public CClassInfo annotation(XSAnnotation annon) {
   1.346 +        assert false;
   1.347 +        return null;
   1.348 +    }
   1.349 +
   1.350 +    public CClassInfo notation(XSNotation not) {
   1.351 +        assert false;
   1.352 +        return null;
   1.353 +    }
   1.354 +
   1.355 +    public CClassInfo facet(XSFacet decl) {
   1.356 +        assert false;
   1.357 +        return null;
   1.358 +    }
   1.359 +    public CClassInfo schema(XSSchema schema) {
   1.360 +        assert false;
   1.361 +        return null;
   1.362 +    }
   1.363 +
   1.364 +
   1.365 +
   1.366 +
   1.367 +
   1.368 +    /**
   1.369 +     * Makes sure that the component doesn't carry a {@link BIClass}
   1.370 +     * customization.
   1.371 +     *
   1.372 +     * @return
   1.373 +     *      return value is unused. Since most of the caller needs to
   1.374 +     *      return null, to make the code a little bit shorter, this
   1.375 +     *      method always return null (so that the caller can always
   1.376 +     *      say <code>return never(sc);</code>.
   1.377 +     */
   1.378 +    private CClassInfo never() {
   1.379 +        // all we need to do here is just not to acknowledge
   1.380 +        // any class customization. Then this class customization
   1.381 +        // will be reported as an error later when we check all
   1.382 +        // unacknowledged customizations.
   1.383 +
   1.384 +
   1.385 +//        BIDeclaration cust=owner.getBindInfo(component).get(BIClass.NAME);
   1.386 +//        if(cust!=null) {
   1.387 +//            // error
   1.388 +//            owner.errorReporter.error(
   1.389 +//                cust.getLocation(),
   1.390 +//                "test {0}", NameGetter.get(component) );
   1.391 +//        }
   1.392 +        return null;
   1.393 +    }
   1.394 +
   1.395 +    /**
   1.396 +     * Checks if a component carries a customization to map it to a class.
   1.397 +     * If so, make it a class.
   1.398 +     *
   1.399 +     * @param defaultBaseName
   1.400 +     *      The token which will be used as the basis of the class name
   1.401 +     *      if the class name is not specified in the customization.
   1.402 +     *      This is usually the name of an element declaration, and so on.
   1.403 +     *
   1.404 +     *      This parameter can be null, in that case it would be an error
   1.405 +     *      if a name is not given by the customization.
   1.406 +     */
   1.407 +    private CElement allow( XSComponent component, String defaultBaseName ) {
   1.408 +
   1.409 +        BIClass decl = null;
   1.410 +
   1.411 +        if(component instanceof XSComplexType) {
   1.412 +            XSType complexType = (XSType)component;
   1.413 +
   1.414 +            BIClass lastFoundRecursiveBiClass = null;
   1.415 +
   1.416 +            if(complexType.getName() != null) {
   1.417 +                while( ! schemas.getAnyType().equals(complexType)) {
   1.418 +                    BindInfo bindInfo = builder.getBindInfo(complexType);
   1.419 +                    BIClass biClass = bindInfo.get(BIClass.class);
   1.420 +
   1.421 +                    if(biClass != null && "true".equals(biClass.getRecursive()))
   1.422 +                        lastFoundRecursiveBiClass = biClass;
   1.423 +
   1.424 +                    complexType = complexType.getBaseType();
   1.425 +                }
   1.426 +            }
   1.427 +
   1.428 +            // use this as biclass for current component
   1.429 +            decl = lastFoundRecursiveBiClass;
   1.430 +
   1.431 +        }
   1.432 +
   1.433 +        BindInfo bindInfo = builder.getBindInfo(component);
   1.434 +        if(decl == null) {
   1.435 +            decl = bindInfo.get(BIClass.class);
   1.436 +            if(decl==null)  return null;
   1.437 +        }
   1.438 +
   1.439 +        decl.markAsAcknowledged();
   1.440 +
   1.441 +        // first consider binding to the class reference.
   1.442 +        String ref = decl.getExistingClassRef();
   1.443 +        if(ref!=null) {
   1.444 +            if(!JJavaName.isFullyQualifiedClassName(ref)) {
   1.445 +                Ring.get(ErrorReceiver.class).error( decl.getLocation(),
   1.446 +                    Messages.format(Messages.ERR_INCORRECT_CLASS_NAME,ref) );
   1.447 +                // recover by ignoring @ref
   1.448 +            } else {
   1.449 +                if(component instanceof XSComplexType) {
   1.450 +                    // UGLY UGLY UGLY
   1.451 +                    // since we are not going to bind this complex type, we need to figure out
   1.452 +                    // its binding mode without actually binding it (and also expose this otherwise
   1.453 +                    // hidden mechanism into this part of the code.)
   1.454 +                    //
   1.455 +                    // this code is potentially dangerous as the base class might have been bound
   1.456 +                    // in different ways. To be correct, we need to figure out how the content type
   1.457 +                    // would have been bound, from the schema.
   1.458 +                    Ring.get(ComplexTypeFieldBuilder.class).recordBindingMode(
   1.459 +                        (XSComplexType)component, ComplexTypeBindingMode.NORMAL
   1.460 +                    );
   1.461 +                }
   1.462 +                return new CClassRef(model, component, decl, bindInfo.toCustomizationList() );
   1.463 +            }
   1.464 +        }
   1.465 +
   1.466 +        String clsName = decl.getClassName();
   1.467 +        if(clsName==null) {
   1.468 +            // if the customiztion doesn't give us a name, derive one
   1.469 +            // from the current component.
   1.470 +            if( defaultBaseName==null ) {
   1.471 +                Ring.get(ErrorReceiver.class).error( decl.getLocation(),
   1.472 +                    Messages.format(Messages.ERR_CLASS_NAME_IS_REQUIRED) );
   1.473 +
   1.474 +                // recover by generating a pseudo-random name
   1.475 +                defaultBaseName = "undefined"+component.hashCode();
   1.476 +            }
   1.477 +            clsName = builder.deriveName( defaultBaseName, component );
   1.478 +        } else {
   1.479 +            if( !JJavaName.isJavaIdentifier(clsName) ) {
   1.480 +                // not a valid Java class name
   1.481 +                Ring.get(ErrorReceiver.class).error( decl.getLocation(),
   1.482 +                    Messages.format( Messages.ERR_INCORRECT_CLASS_NAME, clsName ));
   1.483 +                // recover by a dummy name
   1.484 +                clsName = "Undefined"+component.hashCode();
   1.485 +            }
   1.486 +        }
   1.487 +
   1.488 +        QName typeName = null;
   1.489 +        QName elementName = null;
   1.490 +
   1.491 +        if(component instanceof XSType) {
   1.492 +            XSType t = (XSType) component;
   1.493 +            typeName = getName(t);
   1.494 +        }
   1.495 +
   1.496 +        if (component instanceof XSElementDecl) {
   1.497 +            XSElementDecl e = (XSElementDecl) component;
   1.498 +            elementName = getName(e);
   1.499 +        }
   1.500 +
   1.501 +        if (component instanceof XSElementDecl && !isCollapsable((XSElementDecl)component)) {
   1.502 +            XSElementDecl e = ((XSElementDecl)component);
   1.503 +
   1.504 +            CElementInfo cei = new CElementInfo(model, elementName,
   1.505 +                    selector.getClassScope(), clsName,
   1.506 +                    bindInfo.toCustomizationList(), decl.getLocation() );
   1.507 +            selector.boundElements.put(e,cei);
   1.508 +
   1.509 +            stb.refererStack.push(component);    // referer is element
   1.510 +            cei.initContentType(
   1.511 +                selector.bindToType(e.getType(),e),
   1.512 +                e,e.getDefaultValue());
   1.513 +            stb.refererStack.pop();
   1.514 +            return cei;
   1.515 +            // TODO: support javadoc and userSpecifiedImplClass
   1.516 +        } else {
   1.517 +            CClassInfo bt = new CClassInfo(model,selector.getClassScope(),
   1.518 +                    clsName, decl.getLocation(), typeName, elementName, component, bindInfo.toCustomizationList() );
   1.519 +
   1.520 +            // set javadoc class comment.
   1.521 +            if(decl.getJavadoc()!=null )
   1.522 +                bt.javadoc = decl.getJavadoc()+"\n\n";
   1.523 +                // add extra blank lines so that the schema fragment
   1.524 +                // and user-specified javadoc would be separated
   1.525 +
   1.526 +
   1.527 +            // if the implClass is given, set it to ClassItem
   1.528 +            String implClass = decl.getUserSpecifiedImplClass();
   1.529 +            if( implClass!=null )
   1.530 +                bt.setUserSpecifiedImplClass( implClass );
   1.531 +
   1.532 +            return bt;
   1.533 +        }
   1.534 +    }
   1.535 +
   1.536 +    private BIGlobalBinding getGlobalBinding() {
   1.537 +        return builder.getGlobalBinding();
   1.538 +    }
   1.539 +
   1.540 +    /**
   1.541 +     * Derives a name from a schema component.
   1.542 +     * Use the name of the schema component as the default name.
   1.543 +     */
   1.544 +    private String deriveName( XSDeclaration comp ) {
   1.545 +        return builder.deriveName( comp.getName(), comp );
   1.546 +    }
   1.547 +
   1.548 +    /**
   1.549 +     * Derives a name from a schema component.
   1.550 +     * For complex types, we take redefinition into account when
   1.551 +     * deriving a default name.
   1.552 +     */
   1.553 +    private String deriveName( XSComplexType comp ) {
   1.554 +        String seed = builder.deriveName( comp.getName(), comp );
   1.555 +        int cnt = comp.getRedefinedCount();
   1.556 +        for( ; cnt>0; cnt-- )
   1.557 +            seed = "Original"+seed;
   1.558 +        return seed;
   1.559 +    }
   1.560 +
   1.561 +}

mercurial