Search in sources :

Example 1 with CElementPropertyInfo

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

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

the class AbstractField method writeXmlElementAnnotation.

/**
 * Generate the simplest XmlElement annotation possible taking all semantic optimizations
 * into account.  This method is essentially equivalent to:
 *
 *     xew.name(ctype.getTagName().getLocalPart())
 *        .namespace(ctype.getTagName().getNamespaceURI())
 *        .type(jtype)
 *        .defaultValue(ctype.getDefaultValue());
 *
 * @param checkWrapper true if the method might need to generate XmlElements
 */
private void writeXmlElementAnnotation(JAnnotatable field, CTypeRef ctype, JType jtype, boolean checkWrapper) {
    // lazily create - we don't know if we need to generate anything yet
    XmlElementWriter xew = null;
    // these values are used to determine how to optimize the generated annotation
    XmlNsForm formDefault = parent()._package().getElementFormDefault();
    String propName = prop.getName(false);
    String enclosingTypeNS;
    if (parent().target.getTypeName() == null)
        enclosingTypeNS = parent()._package().getMostUsedNamespaceURI();
    else
        enclosingTypeNS = parent().target.getTypeName().getNamespaceURI();
    // generate the name property?
    String generatedName = ctype.getTagName().getLocalPart();
    if (!generatedName.equals(propName)) {
        if (xew == null)
            xew = getXew(checkWrapper, field);
        xew.name(generatedName);
    }
    // generate the namespace property?
    String generatedNS = ctype.getTagName().getNamespaceURI();
    if (((formDefault == XmlNsForm.QUALIFIED) && !generatedNS.equals(enclosingTypeNS)) || ((formDefault == XmlNsForm.UNQUALIFIED) && !generatedNS.equals(""))) {
        if (xew == null)
            xew = getXew(checkWrapper, field);
        xew.namespace(generatedNS);
    }
    // generate the required() property?
    CElementPropertyInfo ep = (CElementPropertyInfo) prop;
    if (ep.isRequired() && exposedType.isReference()) {
        if (xew == null)
            xew = getXew(checkWrapper, field);
        xew.required(true);
    }
    // if it's a collection, we can't use a primitive, however.
    if (ep.isRequired() && !prop.isCollection())
        jtype = jtype.unboxify();
    // generate @XmlElement(type=...)
    if (!jtype.equals(exposedType) || (getOptions().runtime14 && prop.isCollection())) {
        if (xew == null)
            xew = getXew(checkWrapper, field);
        xew.type(jtype);
    }
    // generate defaultValue property?
    final String defaultValue = ctype.getDefaultValue();
    if (defaultValue != null) {
        if (xew == null)
            xew = getXew(checkWrapper, field);
        xew.defaultValue(defaultValue);
    }
    // generate the nillable property?
    if (ctype.isNillable()) {
        if (xew == null)
            xew = getXew(checkWrapper, field);
        xew.nillable(true);
    }
}
Also used : CElementPropertyInfo(com.sun.tools.xjc.model.CElementPropertyInfo) XmlNsForm(jakarta.xml.bind.annotation.XmlNsForm) XmlElementWriter(com.sun.tools.xjc.generator.annotation.spec.XmlElementWriter)

Example 3 with CElementPropertyInfo

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

the class ElementMappingImpl method calcDrilldown.

@Override
public List<Property> calcDrilldown() {
    CElementPropertyInfo p = clazz.getProperty();
    if (p.getAdapter() != null)
        // if adapted, avoid drill down
        return null;
    if (p.isCollection())
        // things like <xs:element name="foo" type="xs:NMTOKENS" /> is not eligible.
        return null;
    CTypeInfo typeClass = p.ref().get(0);
    if (!(typeClass instanceof CClassInfo))
        // things like <xs:element name="foo" type="xs:string" /> is not eligible.
        return null;
    CClassInfo ci = (CClassInfo) typeClass;
    // if the type is abstract we can't use it.
    if (ci.isAbstract())
        return null;
    // the 'all' compositor doesn't qualify
    if (!ci.isOrdered())
        return null;
    return buildDrilldown(ci);
}
Also used : CElementPropertyInfo(com.sun.tools.xjc.model.CElementPropertyInfo) CClassInfo(com.sun.tools.xjc.model.CClassInfo) CTypeInfo(com.sun.tools.xjc.model.CTypeInfo)

Example 4 with CElementPropertyInfo

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

the class BIProperty method createElementProperty.

/**
 * @param defaultName
 *      If the name is not customized, this name will be used
 *      as the default. Note that the name conversion <b>MUST</b>
 *      be applied before this method is called if necessary.
 * @param source
 *      Source schema component from which a field is built.
 */
public CElementPropertyInfo createElementProperty(String defaultName, boolean forConstant, XSParticle source, RawTypeSet types) {
    if (!types.refs.isEmpty())
        // if this property is empty, don't acknowleedge the customization
        // this allows pointless property customization to be reported as an error
        markAsAcknowledged();
    constantPropertyErrorCheck();
    String name = getPropertyName(forConstant);
    if (name == null)
        name = defaultName;
    CElementPropertyInfo prop = wrapUp(new CElementPropertyInfo(name, types.getCollectionMode(), types.id(), types.getExpectedMimeType(), source, getCustomizations(source), source.getLocator(), types.isRequired()), source);
    types.addTo(prop);
    BIInlineBinaryData.handle(source.getTerm(), prop);
    return prop;
}
Also used : CElementPropertyInfo(com.sun.tools.xjc.model.CElementPropertyInfo)

Example 5 with CElementPropertyInfo

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

the class ContentModelBinder method onRepeated.

private Void onRepeated(DPattern p, boolean optional) {
    RawTypeSet rts = RawTypeSetBuilder.build(compiler, p, optional ? Multiplicity.STAR : Multiplicity.PLUS);
    if (rts.canBeTypeRefs == RawTypeSet.Mode.SHOULD_BE_TYPEREF) {
        CElementPropertyInfo prop = new CElementPropertyInfo(calcName(p), REPEATED_ELEMENT, ID.NONE, null, null, null, p.getLocation(), !optional);
        rts.addTo(prop);
        clazz.addProperty(prop);
    } else {
        CReferencePropertyInfo prop = new CReferencePropertyInfo(calcName(p), true, !optional, false, /*TODO*/
        null, null, p.getLocation(), false, false, false);
        rts.addTo(prop);
        clazz.addProperty(prop);
    }
    return null;
}
Also used : CElementPropertyInfo(com.sun.tools.xjc.model.CElementPropertyInfo) CReferencePropertyInfo(com.sun.tools.xjc.model.CReferencePropertyInfo) RawTypeSet(com.sun.tools.xjc.reader.RawTypeSet)

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