Search in sources :

Example 41 with XSElementDecl

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

the class ParticleBinder method getSpecDefaultName.

/**
 * Computes a name from unnamed model group by following the spec.
 *
 * Taking first three elements and combine them.
 *
 * @param repeated
 *      if the said model group is repeated more than once
 *
 * @exception ParseException
 *      If the method cannot generate a name. For example, when
 *      a model group doesn't contain any element reference/declaration
 *      at all.
 */
protected final String getSpecDefaultName(XSModelGroup mg, final boolean repeated) throws ParseException {
    final StringBuilder name = new StringBuilder();
    mg.visit(new XSTermVisitor() {

        /**
         * Count the number of tokens we combined.
         * We will concat up to 3.
         */
        private int count = 0;

        /**
         * Is the current particple/term repeated?
         */
        private boolean rep = repeated;

        @Override
        public void wildcard(XSWildcard wc) {
            append("any");
        }

        @Override
        public void modelGroupDecl(XSModelGroupDecl mgd) {
            modelGroup(mgd.getModelGroup());
        }

        @Override
        public void modelGroup(XSModelGroup mg) {
            String operator;
            if (mg.getCompositor() == XSModelGroup.CHOICE)
                operator = "Or";
            else
                operator = "And";
            int size = mg.getSize();
            for (int i = 0; i < size; i++) {
                XSParticle p = mg.getChild(i);
                boolean oldRep = rep;
                rep |= p.isRepeated();
                p.getTerm().visit(this);
                rep = oldRep;
                // we have enough
                if (count == 3)
                    return;
                if (i != size - 1)
                    name.append(operator);
            }
        }

        @Override
        public void elementDecl(XSElementDecl ed) {
            append(ed.getName());
        }

        private void append(String token) {
            if (count < 3) {
                name.append(makeJavaName(rep, token));
                count++;
            }
        }
    });
    if (name.length() == 0)
        throw new ParseException("no element", -1);
    return name.toString();
}
Also used : XSParticle(com.sun.xml.xsom.XSParticle) XSModelGroupDecl(com.sun.xml.xsom.XSModelGroupDecl) XSWildcard(com.sun.xml.xsom.XSWildcard) XSElementDecl(com.sun.xml.xsom.XSElementDecl) ParseException(java.text.ParseException) XSTermVisitor(com.sun.xml.xsom.visitor.XSTermVisitor) XSModelGroup(com.sun.xml.xsom.XSModelGroup)

Example 42 with XSElementDecl

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

the class SimpleTypeBuilder method checkRefererCustomization.

/**
 * Checks if the referer has a conversion customization or not.
 * If it does, use it to bind this simple type. Otherwise
 * return null;
 */
private TypeUse checkRefererCustomization(XSSimpleType type) {
    // assertion check. referer must be set properly
    // before the build method is called.
    // since the handling of the simple type point-of-reference
    // customization is very error prone, it deserves a strict
    // assertion check.
    // UGLY CODE WARNING
    XSComponent top = getReferer();
    if (top instanceof XSElementDecl) {
        // if the parent is element type, its content type must be us.
        XSElementDecl eref = (XSElementDecl) top;
        assert eref.getType() == type;
        // for elements, you can't use <property>,
        // so we allow javaType to appear directly.
        BindInfo info = builder.getBindInfo(top);
        BIConversion conv = info.get(BIConversion.class);
        if (conv != null) {
            conv.markAsAcknowledged();
            // the conversion is given.
            return conv.getTypeUse(type);
        }
        detectJavaTypeCustomization();
    } else if (top instanceof XSAttributeDecl) {
        XSAttributeDecl aref = (XSAttributeDecl) top;
        assert aref.getType() == type;
        detectJavaTypeCustomization();
    } else if (top instanceof XSComplexType) {
        XSComplexType tref = (XSComplexType) top;
        assert tref.getBaseType() == type || tref.getContentType() == type;
        detectJavaTypeCustomization();
    } else if (top == type) {
    // this means the simple type is built by itself and
    // not because it's referenced by something.
    } else
        // unexpected referer type.
        assert false;
    // now we are certain that the referer is OK.
    // see if it has a conversion customization.
    BIConversion conv = getRefererCustomization();
    if (conv != null) {
        conv.markAsAcknowledged();
        // the conversion is given.
        return conv.getTypeUse(type);
    } else
        // not found
        return null;
}
Also used : BIConversion(com.sun.tools.xjc.reader.xmlschema.bindinfo.BIConversion) XSComplexType(com.sun.xml.xsom.XSComplexType) XSAttributeDecl(com.sun.xml.xsom.XSAttributeDecl) XSElementDecl(com.sun.xml.xsom.XSElementDecl) XSComponent(com.sun.xml.xsom.XSComponent) BindInfo(com.sun.tools.xjc.reader.xmlschema.bindinfo.BindInfo)

Example 43 with XSElementDecl

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

the class DefaultClassBinder method getSoleElementReferer.

/**
 * If only one global {@link XSElementDecl} is refering to {@link XSType},
 * return that element, otherwise null.
 */
@Nullable
private XSElementDecl getSoleElementReferer(@NotNull XSType t) {
    Set<XSComponent> referer = builder.getReferer(t);
    XSElementDecl sole = null;
    for (XSComponent r : referer) {
        if (r instanceof XSElementDecl) {
            XSElementDecl x = (XSElementDecl) r;
            if (!x.isGlobal())
                // by the property, or by the JAXBElement (for things like mixed contents)
                continue;
            if (sole == null)
                sole = x;
            else
                // more than one
                return null;
        } else {
            // this type has a sub-type, so type substitution is possible now.
            return null;
        }
    }
    return sole;
}
Also used : XSElementDecl(com.sun.xml.xsom.XSElementDecl) XSComponent(com.sun.xml.xsom.XSComponent) Nullable(com.sun.istack.Nullable)

Example 44 with XSElementDecl

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

the class DefaultClassBinder method elementDecl.

@Override
public CElement elementDecl(XSElementDecl decl) {
    CElement r = allow(decl, decl.getName());
    if (r == null) {
        QName tagName = getName(decl);
        CCustomizations custs = builder.getBindInfo(decl).toCustomizationList();
        if (decl.isGlobal()) {
            if (isCollapsable(decl)) {
                // so the binding cannot be delayed.
                return selector.bindToType(decl.getType().asComplexType(), decl, true);
            } else {
                String className = null;
                if (getGlobalBinding().isGenerateElementClass())
                    className = deriveName(decl);
                // otherwise map global elements to JAXBElement
                CElementInfo cei = new CElementInfo(model, tagName, selector.getClassScope(), className, custs, decl.getLocator());
                selector.boundElements.put(decl, cei);
                // referer is element
                stb.refererStack.push(decl);
                cei.initContentType(selector.bindToType(decl.getType(), decl), decl, decl.getDefaultValue());
                stb.refererStack.pop();
                r = cei;
            }
        }
    }
    // have the substitution member derive from the substitution head
    XSElementDecl top = decl.getSubstAffiliation();
    if (top != null) {
        CElement topci = selector.bindToType(top, decl);
        if (r instanceof CClassInfo && topci instanceof CClassInfo)
            ((CClassInfo) r).setBaseClass((CClassInfo) topci);
        if (r instanceof CElementInfo && topci instanceof CElementInfo)
            ((CElementInfo) r).setSubstitutionHead((CElementInfo) topci);
    }
    return r;
}
Also used : CCustomizations(com.sun.tools.xjc.model.CCustomizations) CClassInfo(com.sun.tools.xjc.model.CClassInfo) CElement(com.sun.tools.xjc.model.CElement) QName(javax.xml.namespace.QName) CElementInfo(com.sun.tools.xjc.model.CElementInfo) XSElementDecl(com.sun.xml.xsom.XSElementDecl)

Example 45 with XSElementDecl

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

the class SchemaTreeTraverser method schema.

/* (non-Javadoc)
     * @see com.sun.xml.xsom.visitor.XSVisitor#schema(com.sun.xml.xsom.XSSchema)
     */
public void schema(XSSchema s) {
    // QUICK HACK: don't print the built-in components
    if (s.getTargetNamespace().equals(Const.schemaNamespace)) {
        return;
    }
    SchemaTreeNode newNode = new SchemaTreeNode("Schema " + s.getLocator().getSystemId(), s.getLocator());
    this.currNode = newNode;
    this.model.addSchemaNode(newNode);
    for (XSAttGroupDecl groupDecl : s.getAttGroupDecls().values()) {
        attGroupDecl(groupDecl);
    }
    for (XSAttributeDecl attrDecl : s.getAttributeDecls().values()) {
        attributeDecl(attrDecl);
    }
    for (XSComplexType complexType : s.getComplexTypes().values()) {
        complexType(complexType);
    }
    for (XSElementDecl elementDecl : s.getElementDecls().values()) {
        elementDecl(elementDecl);
    }
    for (XSModelGroupDecl modelGroupDecl : s.getModelGroupDecls().values()) {
        modelGroupDecl(modelGroupDecl);
    }
    for (XSSimpleType simpleType : s.getSimpleTypes().values()) {
        simpleType(simpleType);
    }
}
Also used : XSAttGroupDecl(com.sun.xml.xsom.XSAttGroupDecl) XSSimpleType(com.sun.xml.xsom.XSSimpleType) XSComplexType(com.sun.xml.xsom.XSComplexType) XSModelGroupDecl(com.sun.xml.xsom.XSModelGroupDecl) XSAttributeDecl(com.sun.xml.xsom.XSAttributeDecl) 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