Search in sources :

Example 1 with XmlSeeAlsoWriter

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

XmlRootElementWriter (com.sun.tools.xjc.generator.annotation.spec.XmlRootElementWriter)1 XmlSeeAlsoWriter (com.sun.tools.xjc.generator.annotation.spec.XmlSeeAlsoWriter)1 XmlTypeWriter (com.sun.tools.xjc.generator.annotation.spec.XmlTypeWriter)1 CAttributePropertyInfo (com.sun.tools.xjc.model.CAttributePropertyInfo)1 CClassInfo (com.sun.tools.xjc.model.CClassInfo)1 CPropertyInfo (com.sun.tools.xjc.model.CPropertyInfo)1 CReferencePropertyInfo (com.sun.tools.xjc.model.CReferencePropertyInfo)1 XmlString (com.sun.xml.xsom.XmlString)1