Search in sources :

Example 1 with CValuePropertyInfo

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

the class PackageOutlineImpl method calcDefaultValues.

/**
 * Compute the most common namespace URI in this package
 * (to put into {@link XmlSchema#namespace()} and what value
 * we should put into {@link XmlSchema#elementFormDefault()}.
 *
 * This method is called after {@link #classes} field is filled up.
 */
public void calcDefaultValues() {
    // package-info.java
    if (!_model.isPackageLevelAnnotations()) {
        mostUsedNamespaceURI = "";
        elementFormDefault = XmlNsForm.UNQUALIFIED;
        return;
    }
    // used to visit properties
    CPropertyVisitor<Void> propVisitor = new CPropertyVisitor<>() {

        @Override
        public Void onElement(CElementPropertyInfo p) {
            for (CTypeRef tr : p.getTypes()) {
                countURI(propUriCountMap, tr.getTagName());
            }
            return null;
        }

        @Override
        public Void onReference(CReferencePropertyInfo p) {
            for (CElement e : p.getElements()) {
                countURI(propUriCountMap, e.getElementName());
            }
            return null;
        }

        @Override
        public Void onAttribute(CAttributePropertyInfo p) {
            return null;
        }

        @Override
        public Void onValue(CValuePropertyInfo p) {
            return null;
        }
    };
    for (ClassOutlineImpl co : classes) {
        CClassInfo ci = co.target;
        countURI(uriCountMap, ci.getTypeName());
        countURI(uriCountMap, ci.getElementName());
        for (CPropertyInfo p : ci.getProperties()) p.accept(propVisitor);
    }
    mostUsedNamespaceURI = getMostUsedURI(uriCountMap);
    elementFormDefault = getFormDefault();
    attributeFormDefault = XmlNsForm.UNQUALIFIED;
    try {
        XmlNsForm modelValue = _model.getAttributeFormDefault(mostUsedNamespaceURI);
        attributeFormDefault = modelValue;
    } catch (Exception e) {
    // ignore and accept default
    }
    // we won't get this far if the user specified -npa
    if (!mostUsedNamespaceURI.equals("") || elementFormDefault == XmlNsForm.QUALIFIED || (attributeFormDefault == XmlNsForm.QUALIFIED)) {
        XmlSchemaWriter w = _model.strategy.getPackage(_package, Aspect.IMPLEMENTATION).annotate2(XmlSchemaWriter.class);
        if (!mostUsedNamespaceURI.equals(""))
            w.namespace(mostUsedNamespaceURI);
        if (elementFormDefault == XmlNsForm.QUALIFIED)
            w.elementFormDefault(elementFormDefault);
        if (attributeFormDefault == XmlNsForm.QUALIFIED)
            w.attributeFormDefault(attributeFormDefault);
    }
}
Also used : XmlSchemaWriter(com.sun.tools.xjc.generator.annotation.spec.XmlSchemaWriter) CPropertyVisitor(com.sun.tools.xjc.model.CPropertyVisitor) CAttributePropertyInfo(com.sun.tools.xjc.model.CAttributePropertyInfo) CPropertyInfo(com.sun.tools.xjc.model.CPropertyInfo) CElementPropertyInfo(com.sun.tools.xjc.model.CElementPropertyInfo) CClassInfo(com.sun.tools.xjc.model.CClassInfo) CElement(com.sun.tools.xjc.model.CElement) CValuePropertyInfo(com.sun.tools.xjc.model.CValuePropertyInfo) XmlNsForm(jakarta.xml.bind.annotation.XmlNsForm) CTypeRef(com.sun.tools.xjc.model.CTypeRef) CReferencePropertyInfo(com.sun.tools.xjc.model.CReferencePropertyInfo)

Example 2 with CValuePropertyInfo

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

the class BIProperty method createValueProperty.

public CValuePropertyInfo createValueProperty(String defaultName, boolean forConstant, XSComponent source, TypeUse tu, QName typeName) {
    markAsAcknowledged();
    constantPropertyErrorCheck();
    String name = getPropertyName(forConstant);
    if (name == null) {
        name = defaultName;
        if (tu.isCollection() && getBuilder().getGlobalBinding().isSimpleMode())
            name = JJavaName.getPluralForm(name);
    }
    CValuePropertyInfo prop = wrapUp(new CValuePropertyInfo(name, source, getCustomizations(source), source.getLocator(), tu, typeName), source);
    BIInlineBinaryData.handle(source, prop);
    return prop;
}
Also used : CValuePropertyInfo(com.sun.tools.xjc.model.CValuePropertyInfo)

Example 3 with CValuePropertyInfo

use of com.sun.tools.xjc.model.CValuePropertyInfo 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 4 with CValuePropertyInfo

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

CValuePropertyInfo (com.sun.tools.xjc.model.CValuePropertyInfo)4 CElementPropertyInfo (com.sun.tools.xjc.model.CElementPropertyInfo)3 CReferencePropertyInfo (com.sun.tools.xjc.model.CReferencePropertyInfo)3 CAttributePropertyInfo (com.sun.tools.xjc.model.CAttributePropertyInfo)2 CClassInfo (com.sun.tools.xjc.model.CClassInfo)2 CPropertyInfo (com.sun.tools.xjc.model.CPropertyInfo)2 CTypeRef (com.sun.tools.xjc.model.CTypeRef)2 QName (javax.xml.namespace.QName)2 XmlSchemaTypeWriter (com.sun.tools.xjc.generator.annotation.spec.XmlSchemaTypeWriter)1 XmlSchemaWriter (com.sun.tools.xjc.generator.annotation.spec.XmlSchemaWriter)1 CElement (com.sun.tools.xjc.model.CElement)1 CPropertyVisitor (com.sun.tools.xjc.model.CPropertyVisitor)1 TypeUse (com.sun.tools.xjc.model.TypeUse)1 BIElement (com.sun.tools.xjc.reader.dtd.bindinfo.BIElement)1 XmlInlineBinaryData (jakarta.xml.bind.annotation.XmlInlineBinaryData)1 XmlNsForm (jakarta.xml.bind.annotation.XmlNsForm)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1