Search in sources :

Example 11 with XSElementDecl

use of com.sun.xml.xsom.XSElementDecl in project jaxb-ri by eclipse-ee4j.

the class ComplexTypeImpl method getElementDecls.

public List<XSElementDecl> getElementDecls() {
    ArrayList declList = new ArrayList();
    XSSchemaSet schemaSet = getRoot();
    for (XSSchema sch : schemaSet.getSchemas()) {
        for (XSElementDecl decl : sch.getElementDecls().values()) {
            if (decl.getType().equals(this)) {
                declList.add(decl);
            }
        }
    }
    return declList;
}
Also used : XSSchemaSet(com.sun.xml.xsom.XSSchemaSet) ArrayList(java.util.ArrayList) XSElementDecl(com.sun.xml.xsom.XSElementDecl) XSSchema(com.sun.xml.xsom.XSSchema)

Example 12 with XSElementDecl

use of com.sun.xml.xsom.XSElementDecl in project jaxb-ri by eclipse-ee4j.

the class DefaultClassBinder method complexType.

@Override
public CElement complexType(XSComplexType type) {
    CElement ci = allow(type, type.getName());
    if (ci != null)
        return ci;
    // no customization is given -- do as the default binding.
    BindInfo bi = builder.getBindInfo(type);
    if (type.isGlobal()) {
        QName tagName = null;
        String className = deriveName(type);
        Locator loc = type.getLocator();
        if (getGlobalBinding().isSimpleMode()) {
            // in the simple mode, we may optimize it away
            XSElementDecl referer = getSoleElementReferer(type);
            if (referer != null && isCollapsable(referer)) {
                // if a global element contains
                // a collpsable complex type, we bind this element to a named one
                // and collapses element and complex type.
                tagName = getName(referer);
                className = deriveName(referer);
                loc = referer.getLocator();
            }
        }
        // by default, global ones get their own classes.
        JPackage pkg = selector.getPackage(type.getTargetNamespace());
        return new CClassInfo(model, pkg, className, loc, getTypeName(type), tagName, type, bi.toCustomizationList());
    } else {
        XSElementDecl element = type.getScope();
        if (element.isGlobal() && isCollapsable(element)) {
            if (builder.getBindInfo(element).get(BIClass.class) != null)
                // cause unnecessary wrapping
                return null;
            // which creates unnecessary classes
            return new CClassInfo(model, selector.getClassScope(), deriveName(element), element.getLocator(), null, getName(element), element, bi.toCustomizationList());
        }
        CElement parentType = selector.isBound(element, type);
        String className;
        CClassInfoParent scope;
        if (parentType != null && parentType instanceof CElementInfo && ((CElementInfo) parentType).hasClass()) {
            // special case where we put a nested 'Type' element
            scope = (CElementInfo) parentType;
            className = "Type";
        } else {
            // since the parent element isn't bound to a type, merge the customizations associated to it, too.
            // custs = CCustomizations.merge( custs, builder.getBindInfo(type.getScope()).toCustomizationList());
            className = builder.getNameConverter().toClassName(element.getName());
            BISchemaBinding sb = builder.getBindInfo(type.getOwnerSchema()).get(BISchemaBinding.class);
            if (sb != null)
                className = sb.mangleAnonymousTypeClassName(className);
            scope = selector.getClassScope();
        }
        return new CClassInfo(model, scope, className, type.getLocator(), null, null, type, bi.toCustomizationList());
    }
}
Also used : Locator(org.xml.sax.Locator) CClassInfo(com.sun.tools.xjc.model.CClassInfo) CElement(com.sun.tools.xjc.model.CElement) CClassInfoParent(com.sun.tools.xjc.model.CClassInfoParent) QName(javax.xml.namespace.QName) BISchemaBinding(com.sun.tools.xjc.reader.xmlschema.bindinfo.BISchemaBinding) JPackage(com.sun.codemodel.JPackage) CElementInfo(com.sun.tools.xjc.model.CElementInfo) XSElementDecl(com.sun.xml.xsom.XSElementDecl) BIClass(com.sun.tools.xjc.reader.xmlschema.bindinfo.BIClass) BindInfo(com.sun.tools.xjc.reader.xmlschema.bindinfo.BindInfo)

Example 13 with XSElementDecl

use of com.sun.xml.xsom.XSElementDecl in project jaxb-ri by eclipse-ee4j.

the class DefaultClassBinder method isCollapsable.

/**
 * Returns true if the complex type of the given element can be "optimized away"
 * and unified with its parent element decl to form a single class.
 */
private boolean isCollapsable(XSElementDecl decl) {
    XSType type = decl.getType();
    if (!type.isComplexType())
        // not a complex type
        return false;
    if (decl.getSubstitutables().size() > 1 || decl.getSubstAffiliation() != null)
        // because element substitution calls for a proper JAXBElement hierarchy
        return false;
    if (decl.isNillable())
        // because nillable needs JAXBElement to represent correctly
        return false;
    BIXSubstitutable bixSubstitutable = builder.getBindInfo(decl).get(BIXSubstitutable.class);
    if (bixSubstitutable != null) {
        // see https://jaxb.dev.java.net/issues/show_bug.cgi?id=289
        // this customization forces non-collapsing behavior.
        bixSubstitutable.markAsAcknowledged();
        return false;
    }
    if (getGlobalBinding().isSimpleMode() && decl.isGlobal()) {
        // in the simple mode, we do more aggressive optimization, and get rid of
        // a complex type class if it's only used once from a global element
        XSElementDecl referer = getSoleElementReferer(decl.getType());
        if (referer != null) {
            // I must be the sole referer
            assert referer == decl;
            return true;
        }
    }
    if (!type.isLocal() || !type.isComplexType())
        return false;
    return true;
}
Also used : XSType(com.sun.xml.xsom.XSType) BIXSubstitutable(com.sun.tools.xjc.reader.xmlschema.bindinfo.BIXSubstitutable) XSElementDecl(com.sun.xml.xsom.XSElementDecl)

Example 14 with XSElementDecl

use of com.sun.xml.xsom.XSElementDecl in project jaxb-ri by eclipse-ee4j.

the class DefaultClassBinder method allow.

/**
 * Checks if a component carries a customization to map it to a class.
 * If so, make it a class.
 *
 * @param defaultBaseName
 *      The token which will be used as the basis of the class name
 *      if the class name is not specified in the customization.
 *      This is usually the name of an element declaration, and so on.
 *
 *      This parameter can be null, in that case it would be an error
 *      if a name is not given by the customization.
 */
private CElement allow(XSComponent component, String defaultBaseName) {
    BIClass decl = null;
    if (component instanceof XSComplexType) {
        XSType complexType = (XSType) component;
        BIClass lastFoundRecursiveBiClass = null;
        if (complexType.getName() != null) {
            while (!schemas.getAnyType().equals(complexType)) {
                BindInfo bindInfo = builder.getBindInfo(complexType);
                BIClass biClass = bindInfo.get(BIClass.class);
                if (biClass != null && "true".equals(biClass.getRecursive()))
                    lastFoundRecursiveBiClass = biClass;
                complexType = complexType.getBaseType();
            }
        }
        // use this as biclass for current component
        decl = lastFoundRecursiveBiClass;
    }
    BindInfo bindInfo = builder.getBindInfo(component);
    if (decl == null) {
        decl = bindInfo.get(BIClass.class);
        if (decl == null)
            return null;
    }
    decl.markAsAcknowledged();
    // first consider binding to the class reference.
    String ref = decl.getExistingClassRef();
    if (ref != null) {
        if (!JJavaName.isFullyQualifiedClassName(ref)) {
            Ring.get(ErrorReceiver.class).error(decl.getLocation(), Messages.format(Messages.ERR_INCORRECT_CLASS_NAME, ref));
        // recover by ignoring @ref
        } else {
            if (component instanceof XSComplexType) {
                // UGLY UGLY UGLY
                // since we are not going to bind this complex type, we need to figure out
                // its binding mode without actually binding it (and also expose this otherwise
                // hidden mechanism into this part of the code.)
                // 
                // this code is potentially dangerous as the base class might have been bound
                // in different ways. To be correct, we need to figure out how the content type
                // would have been bound, from the schema.
                Ring.get(ComplexTypeFieldBuilder.class).recordBindingMode((XSComplexType) component, ComplexTypeBindingMode.NORMAL);
            }
            return new CClassRef(model, component, decl, bindInfo.toCustomizationList());
        }
    }
    String clsName = decl.getClassName();
    if (clsName == null) {
        // from the current component.
        if (defaultBaseName == null) {
            Ring.get(ErrorReceiver.class).error(decl.getLocation(), Messages.format(Messages.ERR_CLASS_NAME_IS_REQUIRED));
            // recover by generating a pseudo-random name
            defaultBaseName = "undefined" + component.hashCode();
        }
        clsName = builder.deriveName(defaultBaseName, component);
    } else {
        if (!JJavaName.isJavaIdentifier(clsName)) {
            // not a valid Java class name
            Ring.get(ErrorReceiver.class).error(decl.getLocation(), Messages.format(Messages.ERR_INCORRECT_CLASS_NAME, clsName));
            // recover by a dummy name
            clsName = "Undefined" + component.hashCode();
        }
    }
    QName typeName = null;
    QName elementName = null;
    if (component instanceof XSType) {
        XSType t = (XSType) component;
        typeName = getName(t);
    }
    if (component instanceof XSElementDecl) {
        XSElementDecl e = (XSElementDecl) component;
        elementName = getName(e);
    }
    if (component instanceof XSElementDecl && !isCollapsable((XSElementDecl) component)) {
        XSElementDecl e = ((XSElementDecl) component);
        CElementInfo cei = new CElementInfo(model, elementName, selector.getClassScope(), clsName, bindInfo.toCustomizationList(), decl.getLocation());
        selector.boundElements.put(e, cei);
        // referer is element
        stb.refererStack.push(component);
        cei.initContentType(selector.bindToType(e.getType(), e), e, e.getDefaultValue());
        stb.refererStack.pop();
        return cei;
    // TODO: support javadoc and userSpecifiedImplClass
    } else {
        CClassInfo bt = new CClassInfo(model, selector.getClassScope(), clsName, decl.getLocation(), typeName, elementName, component, bindInfo.toCustomizationList());
        // set javadoc class comment.
        if (decl.getJavadoc() != null)
            bt.javadoc = decl.getJavadoc() + "\n\n";
        // add extra blank lines so that the schema fragment
        // and user-specified javadoc would be separated
        // if the implClass is given, set it to ClassItem
        String implClass = decl.getUserSpecifiedImplClass();
        if (implClass != null)
            bt.setUserSpecifiedImplClass(implClass);
        return bt;
    }
}
Also used : ComplexTypeFieldBuilder(com.sun.tools.xjc.reader.xmlschema.ct.ComplexTypeFieldBuilder) XSType(com.sun.xml.xsom.XSType) CClassInfo(com.sun.tools.xjc.model.CClassInfo) XSComplexType(com.sun.xml.xsom.XSComplexType) CClassRef(com.sun.tools.xjc.model.CClassRef) QName(javax.xml.namespace.QName) CElementInfo(com.sun.tools.xjc.model.CElementInfo) XSElementDecl(com.sun.xml.xsom.XSElementDecl) ErrorReceiver(com.sun.tools.xjc.ErrorReceiver) BIClass(com.sun.tools.xjc.reader.xmlschema.bindinfo.BIClass) BindInfo(com.sun.tools.xjc.reader.xmlschema.bindinfo.BindInfo)

Example 15 with XSElementDecl

use of com.sun.xml.xsom.XSElementDecl in project midpoint by Evolveum.

the class SchemaProcessor method getComplexTypeToElementName.

private Map<QName, List<QName>> getComplexTypeToElementName(ClassOutline classOutline) {
    Map<QName, List<QName>> complexTypeToElementName = new HashMap<QName, List<QName>>();
    XSSchemaSet schemaSet = classOutline.target.getSchemaComponent().getRoot();
    for (XSSchema schema : schemaSet.getSchemas()) {
        Map<String, XSElementDecl> elemDecls = schema.getElementDecls();
        for (Entry<String, XSElementDecl> entry : elemDecls.entrySet()) {
            XSElementDecl decl = entry.getValue();
            XSType xsType = decl.getType();
            if (xsType.getName() == null) {
                continue;
            }
            QName type = new QName(xsType.getTargetNamespace(), xsType.getName());
            List<QName> qnames = complexTypeToElementName.get(type);
            if (qnames == null) {
                qnames = new ArrayList<QName>();
                complexTypeToElementName.put(type, qnames);
            }
            qnames.add(new QName(decl.getTargetNamespace(), decl.getName()));
        }
    }
    return complexTypeToElementName;
}
Also used : HashMap(java.util.HashMap) QName(javax.xml.namespace.QName) XSSchemaSet(com.sun.xml.xsom.XSSchemaSet) XSSchema(com.sun.xml.xsom.XSSchema) XSType(com.sun.xml.xsom.XSType) PrismReferenceArrayList(com.evolveum.midpoint.prism.xjc.PrismReferenceArrayList) List(java.util.List) ArrayList(java.util.ArrayList) PrismContainerArrayList(com.evolveum.midpoint.prism.xjc.PrismContainerArrayList) XSElementDecl(com.sun.xml.xsom.XSElementDecl)

Aggregations

XSElementDecl (com.sun.xml.xsom.XSElementDecl)48 XSModelGroupDecl (com.sun.xml.xsom.XSModelGroupDecl)18 XSComplexType (com.sun.xml.xsom.XSComplexType)16 XSModelGroup (com.sun.xml.xsom.XSModelGroup)16 XSSchema (com.sun.xml.xsom.XSSchema)12 XSSimpleType (com.sun.xml.xsom.XSSimpleType)11 XSAttributeDecl (com.sun.xml.xsom.XSAttributeDecl)10 XSType (com.sun.xml.xsom.XSType)10 XSWildcard (com.sun.xml.xsom.XSWildcard)10 XSTermVisitor (com.sun.xml.xsom.visitor.XSTermVisitor)10 XSAttGroupDecl (com.sun.xml.xsom.XSAttGroupDecl)9 XSSchemaSet (com.sun.xml.xsom.XSSchemaSet)8 XSParticle (com.sun.xml.xsom.XSParticle)7 XSTerm (com.sun.xml.xsom.XSTerm)7 ArrayList (java.util.ArrayList)7 BigInteger (java.math.BigInteger)6 QName (javax.xml.namespace.QName)6 XSContentType (com.sun.xml.xsom.XSContentType)4 Iterator (java.util.Iterator)4 CClassInfo (com.sun.tools.xjc.model.CClassInfo)3