Search in sources :

Example 6 with TypeUse

use of com.sun.tools.xjc.model.TypeUse in project jaxb-ri by eclipse-ee4j.

the class TypeUseBinder method onContainer.

private TypeUse onContainer(DContainerPattern p) {
    TypeUse t = null;
    for (DPattern child : p) {
        TypeUse s = child.accept(this);
        if (t != null && t != s)
            // heterogenous
            return CBuiltinLeafInfo.STRING;
        t = s;
    }
    return t;
}
Also used : TypeUse(com.sun.tools.xjc.model.TypeUse) DPattern(com.sun.tools.rngom.digested.DPattern)

Example 7 with TypeUse

use of com.sun.tools.xjc.model.TypeUse in project jaxb-ri by eclipse-ee4j.

the class STDerivedComplexTypeBuilder method build.

@Override
public void build(XSComplexType ct) {
    assert ct.getDerivationMethod() == XSType.EXTENSION;
    // base type is a simple type
    XSSimpleType baseType = ct.getBaseType().asSimpleType();
    // determine the binding of this complex type.
    builder.recordBindingMode(ct, ComplexTypeBindingMode.NORMAL);
    simpleTypeBuilder.refererStack.push(ct);
    TypeUse use = simpleTypeBuilder.build(baseType);
    simpleTypeBuilder.refererStack.pop();
    BIProperty prop = BIProperty.getCustomization(ct);
    CPropertyInfo p = prop.createValueProperty("Value", false, baseType, use, BGMBuilder.getName(baseType));
    selector.getCurrentBean().addProperty(p);
    // adds attributes and we are through.
    green.attContainer(ct);
}
Also used : TypeUse(com.sun.tools.xjc.model.TypeUse) XSSimpleType(com.sun.xml.xsom.XSSimpleType) BIProperty(com.sun.tools.xjc.reader.xmlschema.bindinfo.BIProperty) CPropertyInfo(com.sun.tools.xjc.model.CPropertyInfo)

Example 8 with TypeUse

use of com.sun.tools.xjc.model.TypeUse in project jaxb-ri by eclipse-ee4j.

the class FreshComplexTypeBuilder method build.

@Override
public void build(final XSComplexType ct) {
    XSContentType contentType = ct.getContentType();
    contentType.visit(new XSContentTypeVisitor() {

        @Override
        public void simpleType(XSSimpleType st) {
            builder.recordBindingMode(ct, ComplexTypeBindingMode.NORMAL);
            simpleTypeBuilder.refererStack.push(ct);
            TypeUse use = simpleTypeBuilder.build(st);
            simpleTypeBuilder.refererStack.pop();
            BIProperty prop = BIProperty.getCustomization(ct);
            CPropertyInfo p = prop.createValueProperty("Value", false, ct, use, BGMBuilder.getName(st));
            selector.getCurrentBean().addProperty(p);
        }

        @Override
        public void particle(XSParticle p) {
            // determine the binding of this complex type.
            builder.recordBindingMode(ct, bgmBuilder.getParticleBinder().checkFallback(p) ? FALLBACK_CONTENT : NORMAL);
            bgmBuilder.getParticleBinder().build(p);
            XSTerm term = p.getTerm();
            if (term.isModelGroup() && term.asModelGroup().getCompositor() == XSModelGroup.ALL)
                selector.getCurrentBean().setOrdered(false);
        }

        @Override
        public void empty(XSContentType e) {
            builder.recordBindingMode(ct, NORMAL);
        }
    });
    // adds attributes and we are through.
    green.attContainer(ct);
}
Also used : XSContentType(com.sun.xml.xsom.XSContentType) TypeUse(com.sun.tools.xjc.model.TypeUse) XSSimpleType(com.sun.xml.xsom.XSSimpleType) XSParticle(com.sun.xml.xsom.XSParticle) XSTerm(com.sun.xml.xsom.XSTerm) BIProperty(com.sun.tools.xjc.reader.xmlschema.bindinfo.BIProperty) XSContentTypeVisitor(com.sun.xml.xsom.visitor.XSContentTypeVisitor) CPropertyInfo(com.sun.tools.xjc.model.CPropertyInfo)

Example 9 with TypeUse

use of com.sun.tools.xjc.model.TypeUse in project jaxb-ri by eclipse-ee4j.

the class Element method bind.

void bind() {
    CClassInfo ci = getClassInfo();
    assert ci != null || attributes.isEmpty();
    for (CPropertyInfo p : attributes) ci.addProperty(p);
    switch(contentModelType) {
        case DTDEventListener.CONTENT_MODEL_ANY:
            CReferencePropertyInfo rp = new CReferencePropertyInfo("Content", true, false, true, null, null, /*TODO*/
            locator, false, false, false);
            rp.setWildcard(WildcardMode.SKIP);
            ci.addProperty(rp);
            return;
        case DTDEventListener.CONTENT_MODEL_CHILDREN:
            // handling follows
            break;
        case DTDEventListener.CONTENT_MODEL_MIXED:
            if (contentModel != Term.EMPTY)
                throw new UnsupportedOperationException("mixed content model unsupported yet");
            if (ci != null) {
                // if this element is mapped to a class, just put one property
                CValuePropertyInfo p = new CValuePropertyInfo("value", null, null, /*TODO*/
                locator, getConversion(), null);
                ci.addProperty(p);
            }
            return;
        case DTDEventListener.CONTENT_MODEL_EMPTY:
            // no content model
            assert ci != null;
            return;
    }
    // normalize
    List<Block> n = new ArrayList<>();
    contentModel.normalize(n, false);
    {
        // check collision among Blocks
        Set<String> names = new HashSet<>();
        boolean collision = false;
        OUTER: for (Block b : n) for (Element e : b.elements) if (!names.add(e.name)) {
            collision = true;
            break OUTER;
        }
        if (collision) {
            // collapse all blocks into one
            Block all = new Block(true, true);
            for (Block b : n) all.elements.addAll(b.elements);
            n.clear();
            n.add(all);
        }
    }
    for (Block b : n) {
        CElementPropertyInfo p;
        if (b.isRepeated || b.elements.size() > 1) {
            // collection
            StringBuilder name = new StringBuilder();
            for (Element e : b.elements) {
                if (name.length() > 0)
                    name.append("Or");
                name.append(owner.model.getNameConverter().toPropertyName(e.name));
            }
            p = new CElementPropertyInfo(name.toString(), REPEATED_ELEMENT, ID.NONE, null, null, null, /*TODO*/
            locator, !b.isOptional);
            for (Element e : b.elements) {
                CClassInfo child = owner.getOrCreateElement(e.name).getClassInfo();
                // we are requiring them to be classes.
                assert child != null;
                p.getTypes().add(new CTypeRef(child, new QName("", e.name), null, false, null));
            }
        } else {
            // single property
            String name = b.elements.iterator().next().name;
            String propName = owner.model.getNameConverter().toPropertyName(name);
            TypeUse refType;
            Element ref = owner.getOrCreateElement(name);
            if (ref.getClassInfo() != null)
                refType = ref.getClassInfo();
            else {
                refType = ref.getConversion().getInfo();
            }
            p = new CElementPropertyInfo(propName, refType.isCollection() ? REPEATED_VALUE : NOT_REPEATED, ID.NONE, null, null, null, /*TODO*/
            locator, !b.isOptional);
            p.getTypes().add(new CTypeRef(refType.getInfo(), new QName("", name), null, false, null));
        }
        ci.addProperty(p);
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) QName(javax.xml.namespace.QName) BIElement(com.sun.tools.xjc.reader.dtd.bindinfo.BIElement) ArrayList(java.util.ArrayList) CPropertyInfo(com.sun.tools.xjc.model.CPropertyInfo) CClassInfo(com.sun.tools.xjc.model.CClassInfo) CElementPropertyInfo(com.sun.tools.xjc.model.CElementPropertyInfo) TypeUse(com.sun.tools.xjc.model.TypeUse) CValuePropertyInfo(com.sun.tools.xjc.model.CValuePropertyInfo) CTypeRef(com.sun.tools.xjc.model.CTypeRef) CReferencePropertyInfo(com.sun.tools.xjc.model.CReferencePropertyInfo)

Example 10 with TypeUse

use of com.sun.tools.xjc.model.TypeUse in project jaxb-ri by eclipse-ee4j.

the class TDTDReader method createAttribute.

protected CPropertyInfo createAttribute(String elementName, String attributeName, String attributeType, String[] enums, short attributeUse, String defaultValue) throws SAXException {
    boolean required = attributeUse == USE_REQUIRED;
    // get the attribute-property declaration
    BIElement edecl = bindInfo.element(elementName);
    BIAttribute decl = null;
    if (edecl != null)
        decl = edecl.attribute(attributeName);
    String propName;
    if (decl == null)
        propName = model.getNameConverter().toPropertyName(attributeName);
    else
        propName = decl.getPropertyName();
    QName qname = new QName("", attributeName);
    // if no declaration is specified, just wrap it by
    // a FieldItem and let the normalizer handle its content.
    TypeUse use;
    if (decl != null && decl.getConversion() != null)
        use = decl.getConversion().getTransducer();
    else
        use = builtinConversions.get(attributeType);
    CPropertyInfo r = new CAttributePropertyInfo(propName, null, null, /*TODO*/
    copyLocator(), qname, use, null, required);
    if (defaultValue != null)
        r.defaultValue = CDefaultValue.create(use, new XmlString(defaultValue));
    return r;
}
Also used : TypeUse(com.sun.tools.xjc.model.TypeUse) BIElement(com.sun.tools.xjc.reader.dtd.bindinfo.BIElement) BIAttribute(com.sun.tools.xjc.reader.dtd.bindinfo.BIAttribute) QName(javax.xml.namespace.QName) XmlString(com.sun.xml.xsom.XmlString) XmlString(com.sun.xml.xsom.XmlString) CAttributePropertyInfo(com.sun.tools.xjc.model.CAttributePropertyInfo) CPropertyInfo(com.sun.tools.xjc.model.CPropertyInfo)

Aggregations

TypeUse (com.sun.tools.xjc.model.TypeUse)10 CPropertyInfo (com.sun.tools.xjc.model.CPropertyInfo)5 XSSimpleType (com.sun.xml.xsom.XSSimpleType)4 BIProperty (com.sun.tools.xjc.reader.xmlschema.bindinfo.BIProperty)3 CClassInfo (com.sun.tools.xjc.model.CClassInfo)2 CNonElement (com.sun.tools.xjc.model.CNonElement)2 BIElement (com.sun.tools.xjc.reader.dtd.bindinfo.BIElement)2 BIConversion (com.sun.tools.xjc.reader.xmlschema.bindinfo.BIConversion)2 QName (javax.xml.namespace.QName)2 JavadocEscapeWriter (com.sun.codemodel.util.JavadocEscapeWriter)1 DPattern (com.sun.tools.rngom.digested.DPattern)1 ErrorReceiver (com.sun.tools.xjc.ErrorReceiver)1 CAttributePropertyInfo (com.sun.tools.xjc.model.CAttributePropertyInfo)1 CClassInfoParent (com.sun.tools.xjc.model.CClassInfoParent)1 CClassRef (com.sun.tools.xjc.model.CClassRef)1 CElementPropertyInfo (com.sun.tools.xjc.model.CElementPropertyInfo)1 CEnumConstant (com.sun.tools.xjc.model.CEnumConstant)1 CEnumLeafInfo (com.sun.tools.xjc.model.CEnumLeafInfo)1 CReferencePropertyInfo (com.sun.tools.xjc.model.CReferencePropertyInfo)1 CTypeRef (com.sun.tools.xjc.model.CTypeRef)1