Search in sources :

Example 1 with XmlSchemaWriter

use of com.sun.tools.xjc.generator.annotation.spec.XmlSchemaWriter 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)

Aggregations

XmlSchemaWriter (com.sun.tools.xjc.generator.annotation.spec.XmlSchemaWriter)1 CAttributePropertyInfo (com.sun.tools.xjc.model.CAttributePropertyInfo)1 CClassInfo (com.sun.tools.xjc.model.CClassInfo)1 CElement (com.sun.tools.xjc.model.CElement)1 CElementPropertyInfo (com.sun.tools.xjc.model.CElementPropertyInfo)1 CPropertyInfo (com.sun.tools.xjc.model.CPropertyInfo)1 CPropertyVisitor (com.sun.tools.xjc.model.CPropertyVisitor)1 CReferencePropertyInfo (com.sun.tools.xjc.model.CReferencePropertyInfo)1 CTypeRef (com.sun.tools.xjc.model.CTypeRef)1 CValuePropertyInfo (com.sun.tools.xjc.model.CValuePropertyInfo)1 XmlNsForm (jakarta.xml.bind.annotation.XmlNsForm)1