Search in sources :

Example 1 with CReferencePropertyInfo

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

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

the class DefaultParticleBinder method build.

@Override
public void build(XSParticle p, Collection<XSParticle> forcedProps) {
    Checker checker = checkCollision(p, forcedProps);
    if (checker.hasNameCollision()) {
        CReferencePropertyInfo prop = new CReferencePropertyInfo(getCurrentBean().getBaseClass() == null ? "Content" : "Rest", true, false, false, p, builder.getBindInfo(p).toCustomizationList(), p.getLocator(), false, false, false);
        RawTypeSetBuilder.build(p, false).addTo(prop);
        prop.javadoc = Messages.format(Messages.MSG_FALLBACK_JAVADOC, checker.getCollisionInfo().toString());
        getCurrentBean().addProperty(prop);
    } else {
        new Builder(checker.markedParticles).particle(p);
    }
}
Also used : CReferencePropertyInfo(com.sun.tools.xjc.model.CReferencePropertyInfo)

Example 3 with CReferencePropertyInfo

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

the class BIProperty method createReferenceProperty.

public CReferencePropertyInfo createReferenceProperty(String defaultName, boolean forConstant, XSComponent source, RawTypeSet types, boolean isMixed, boolean dummy, boolean content, boolean isMixedExtended) {
    if (types == null) {
        // this is a special case where we need to generate content because potential subtypes would need to be able to override what's store inside
        content = true;
    } else {
        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;
    CReferencePropertyInfo prop = wrapUp(new CReferencePropertyInfo(name, types == null || types.getCollectionMode().isRepeated() || isMixed, types != null && types.isRequired(), isMixed, source, getCustomizations(source), source.getLocator(), dummy, content, isMixedExtended), source);
    if (types != null) {
        types.addTo(prop);
    }
    BIInlineBinaryData.handle(source, prop);
    return prop;
}
Also used : CReferencePropertyInfo(com.sun.tools.xjc.model.CReferencePropertyInfo)

Example 4 with CReferencePropertyInfo

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

Example 5 with CReferencePropertyInfo

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

the class BeanGenerator method generateClassBody.

/**
 * Generates the body of a class.
 */
private void generateClassBody(ClassOutlineImpl cc) {
    CClassInfo target = cc.target;
    // used to simplify the generated annotations
    String mostUsedNamespaceURI = cc._package().getMostUsedNamespaceURI();
    // [RESULT]
    // @XmlType(name="foo", targetNamespace="bar://baz")
    XmlTypeWriter xtw = cc.implClass.annotate2(XmlTypeWriter.class);
    writeTypeName(cc.target.getTypeName(), xtw, mostUsedNamespaceURI);
    // @XmlSeeAlso
    Iterator<CClassInfo> subclasses = cc.target.listSubclasses();
    if (subclasses.hasNext()) {
        XmlSeeAlsoWriter saw = cc.implClass.annotate2(XmlSeeAlsoWriter.class);
        while (subclasses.hasNext()) {
            CClassInfo s = subclasses.next();
            saw.value(getClazz(s).implRef);
        }
    }
    if (target.isElement()) {
        String namespaceURI = target.getElementName().getNamespaceURI();
        String localPart = target.getElementName().getLocalPart();
        // [RESULT]
        // @XmlRootElement(name="foo", targetNamespace="bar://baz")
        XmlRootElementWriter xrew = cc.implClass.annotate2(XmlRootElementWriter.class);
        xrew.name(localPart);
        if (// only generate if necessary
        !namespaceURI.equals(mostUsedNamespaceURI)) {
            xrew.namespace(namespaceURI);
        }
    }
    if (target.isOrdered()) {
        for (CPropertyInfo p : target.getProperties()) {
            if (!(p instanceof CAttributePropertyInfo)) {
                if (!((p instanceof CReferencePropertyInfo) && ((CReferencePropertyInfo) p).isDummy())) {
                    xtw.propOrder(p.getName(false));
                }
            }
        }
    } else {
        // produce empty array
        xtw.getAnnotationUse().paramArray("propOrder");
    }
    for (CPropertyInfo prop : target.getProperties()) {
        generateFieldDecl(cc, prop);
    }
    if (target.declaresAttributeWildcard()) {
        generateAttributeWildcard(cc);
    }
    // generate some class level javadoc
    cc.ref.javadoc().append(target.javadoc);
    cc._package().objectFactoryGenerator().populate(cc);
}
Also used : XmlRootElementWriter(com.sun.tools.xjc.generator.annotation.spec.XmlRootElementWriter) CClassInfo(com.sun.tools.xjc.model.CClassInfo) XmlTypeWriter(com.sun.tools.xjc.generator.annotation.spec.XmlTypeWriter) XmlString(com.sun.xml.xsom.XmlString) XmlSeeAlsoWriter(com.sun.tools.xjc.generator.annotation.spec.XmlSeeAlsoWriter) CAttributePropertyInfo(com.sun.tools.xjc.model.CAttributePropertyInfo) CReferencePropertyInfo(com.sun.tools.xjc.model.CReferencePropertyInfo) CPropertyInfo(com.sun.tools.xjc.model.CPropertyInfo)

Aggregations

CReferencePropertyInfo (com.sun.tools.xjc.model.CReferencePropertyInfo)9 CElementPropertyInfo (com.sun.tools.xjc.model.CElementPropertyInfo)5 CClassInfo (com.sun.tools.xjc.model.CClassInfo)4 CPropertyInfo (com.sun.tools.xjc.model.CPropertyInfo)4 CAttributePropertyInfo (com.sun.tools.xjc.model.CAttributePropertyInfo)3 CElement (com.sun.tools.xjc.model.CElement)3 CValuePropertyInfo (com.sun.tools.xjc.model.CValuePropertyInfo)3 CTypeRef (com.sun.tools.xjc.model.CTypeRef)2 QName (javax.xml.namespace.QName)2 JClass (com.sun.codemodel.JClass)1 Property (com.sun.tools.xjc.api.Property)1 XmlAnyElementWriter (com.sun.tools.xjc.generator.annotation.spec.XmlAnyElementWriter)1 XmlElementRefWriter (com.sun.tools.xjc.generator.annotation.spec.XmlElementRefWriter)1 XmlElementRefsWriter (com.sun.tools.xjc.generator.annotation.spec.XmlElementRefsWriter)1 XmlRootElementWriter (com.sun.tools.xjc.generator.annotation.spec.XmlRootElementWriter)1 XmlSchemaTypeWriter (com.sun.tools.xjc.generator.annotation.spec.XmlSchemaTypeWriter)1 XmlSchemaWriter (com.sun.tools.xjc.generator.annotation.spec.XmlSchemaWriter)1 XmlSeeAlsoWriter (com.sun.tools.xjc.generator.annotation.spec.XmlSeeAlsoWriter)1 XmlTypeWriter (com.sun.tools.xjc.generator.annotation.spec.XmlTypeWriter)1 CElementInfo (com.sun.tools.xjc.model.CElementInfo)1