Search in sources :

Example 6 with CElementPropertyInfo

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

the class AbstractField method annotateElement.

/**
 * Annotate the element property 'field'
 */
private void annotateElement(JAnnotatable field) {
    CElementPropertyInfo ep = (CElementPropertyInfo) prop;
    List<CTypeRef> types = ep.getTypes();
    if (ep.isValueList()) {
        field.annotate(XmlList.class);
    }
    assert ep.getXmlName() == null;
    if (types.size() == 1) {
        CTypeRef t = types.get(0);
        writeXmlElementAnnotation(field, t, resolve(t, IMPLEMENTATION), false);
    } else {
        for (CTypeRef t : types) {
            // generate @XmlElements
            writeXmlElementAnnotation(field, t, resolve(t, IMPLEMENTATION), true);
        }
        xesw = null;
    }
}
Also used : CElementPropertyInfo(com.sun.tools.xjc.model.CElementPropertyInfo) CTypeRef(com.sun.tools.xjc.model.CTypeRef)

Example 7 with CElementPropertyInfo

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

the class AbstractField method annotate.

/**
 * Annotate the field according to the recipes given as {@link CPropertyInfo}.
 */
protected void annotate(JAnnotatable field) {
    assert (field != null);
    // TODO: consider a visitor
    if (prop instanceof CAttributePropertyInfo) {
        annotateAttribute(field);
    } else if (prop instanceof CElementPropertyInfo) {
        annotateElement(field);
    } else if (prop instanceof CValuePropertyInfo) {
        field.annotate(XmlValue.class);
    } else if (prop instanceof CReferencePropertyInfo) {
        annotateReference(field);
    }
    outline.parent().generateAdapterIfNecessary(prop, field);
    QName st = prop.getSchemaType();
    if (st != null)
        field.annotate2(XmlSchemaTypeWriter.class).name(st.getLocalPart()).namespace(st.getNamespaceURI());
    if (prop.inlineBinaryData())
        field.annotate(XmlInlineBinaryData.class);
}
Also used : CElementPropertyInfo(com.sun.tools.xjc.model.CElementPropertyInfo) CValuePropertyInfo(com.sun.tools.xjc.model.CValuePropertyInfo) QName(javax.xml.namespace.QName) XmlSchemaTypeWriter(com.sun.tools.xjc.generator.annotation.spec.XmlSchemaTypeWriter) CAttributePropertyInfo(com.sun.tools.xjc.model.CAttributePropertyInfo) CReferencePropertyInfo(com.sun.tools.xjc.model.CReferencePropertyInfo) XmlInlineBinaryData(jakarta.xml.bind.annotation.XmlInlineBinaryData)

Example 8 with CElementPropertyInfo

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

the class AbstractMappingImpl method buildDrilldown.

/**
 * Derived classes can use this method to implement {@link #calcDrilldown}.
 */
protected List<Property> buildDrilldown(CClassInfo typeBean) {
    // they must not contain xsd:choice
    if (containingChoice(typeBean)) {
        return null;
    }
    List<Property> result;
    CClassInfo bc = typeBean.getBaseClass();
    if (bc != null) {
        result = buildDrilldown(bc);
        if (result == null) {
            // aborted
            return null;
        }
    } else {
        result = new ArrayList<>();
    }
    for (CPropertyInfo p : typeBean.getProperties()) {
        if (p instanceof CElementPropertyInfo) {
            CElementPropertyInfo ep = (CElementPropertyInfo) p;
            // wrong. A+,B,C is eligible for drill-down.
            // if(ep.isCollection())
            // // content model like A+,B,C is not eligible
            // return null;
            List<? extends CTypeRef> ref = ep.getTypes();
            if (ref.size() != 1) {
                // content model like (A|B),C is not eligible
                return null;
            }
            result.add(createPropertyImpl(ep, ref.get(0).getTagName()));
        } else if (p instanceof ReferencePropertyInfo) {
            CReferencePropertyInfo rp = (CReferencePropertyInfo) p;
            Collection<CElement> elements = rp.getElements();
            if (elements.size() != 1) {
                return null;
            }
            CElement ref = elements.iterator().next();
            if (ref instanceof ClassInfo) {
                result.add(createPropertyImpl(rp, ref.getElementName()));
            } else {
                CElementInfo eref = (CElementInfo) ref;
                if (!eref.getSubstitutionMembers().isEmpty()) {
                    // elements with a substitution group isn't qualified for the wrapper style
                    return null;
                }
                // JAX-WS doesn't want to see JAXBElement, so we have to hide it for them.
                ElementAdapter fr;
                if (rp.isCollection()) {
                    fr = new ElementCollectionAdapter(parent.outline.getField(rp), eref);
                } else {
                    fr = new ElementSingleAdapter(parent.outline.getField(rp), eref);
                }
                result.add(new PropertyImpl(this, fr, eref.getElementName()));
            }
        } else {
            // according to the JAX-RPC spec 2.3.1.2, element refs are disallowed
            return null;
        }
    }
    return result;
}
Also used : CElementInfo(com.sun.tools.xjc.model.CElementInfo) CPropertyInfo(com.sun.tools.xjc.model.CPropertyInfo) CClassInfo(com.sun.tools.xjc.model.CClassInfo) CElementPropertyInfo(com.sun.tools.xjc.model.CElementPropertyInfo) CElement(com.sun.tools.xjc.model.CElement) CReferencePropertyInfo(com.sun.tools.xjc.model.CReferencePropertyInfo) ReferencePropertyInfo(org.glassfish.jaxb.core.v2.model.core.ReferencePropertyInfo) Collection(java.util.Collection) CReferencePropertyInfo(com.sun.tools.xjc.model.CReferencePropertyInfo) Property(com.sun.tools.xjc.api.Property) CClassInfo(com.sun.tools.xjc.model.CClassInfo) ClassInfo(org.glassfish.jaxb.core.v2.model.core.ClassInfo)

Example 9 with CElementPropertyInfo

use of com.sun.tools.xjc.model.CElementPropertyInfo 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)

Aggregations

CElementPropertyInfo (com.sun.tools.xjc.model.CElementPropertyInfo)9 CReferencePropertyInfo (com.sun.tools.xjc.model.CReferencePropertyInfo)5 CClassInfo (com.sun.tools.xjc.model.CClassInfo)4 CPropertyInfo (com.sun.tools.xjc.model.CPropertyInfo)3 CTypeRef (com.sun.tools.xjc.model.CTypeRef)3 CValuePropertyInfo (com.sun.tools.xjc.model.CValuePropertyInfo)3 CAttributePropertyInfo (com.sun.tools.xjc.model.CAttributePropertyInfo)2 CElement (com.sun.tools.xjc.model.CElement)2 XmlNsForm (jakarta.xml.bind.annotation.XmlNsForm)2 QName (javax.xml.namespace.QName)2 Property (com.sun.tools.xjc.api.Property)1 XmlElementWriter (com.sun.tools.xjc.generator.annotation.spec.XmlElementWriter)1 XmlSchemaTypeWriter (com.sun.tools.xjc.generator.annotation.spec.XmlSchemaTypeWriter)1 XmlSchemaWriter (com.sun.tools.xjc.generator.annotation.spec.XmlSchemaWriter)1 CElementInfo (com.sun.tools.xjc.model.CElementInfo)1 CPropertyVisitor (com.sun.tools.xjc.model.CPropertyVisitor)1 CTypeInfo (com.sun.tools.xjc.model.CTypeInfo)1 TypeUse (com.sun.tools.xjc.model.TypeUse)1 RawTypeSet (com.sun.tools.xjc.reader.RawTypeSet)1 BIElement (com.sun.tools.xjc.reader.dtd.bindinfo.BIElement)1