Search in sources :

Example 1 with ClassInfo

use of org.glassfish.jaxb.core.v2.model.core.ClassInfo in project jaxb-ri by eclipse-ee4j.

the class XmlSchemaGenerator method add.

/**
 * Adds a new class to the list of classes to be written.
 *
 * <p>
 * A {@link ClassInfo} may have two namespaces --- one for the element name
 * and the other for the type name. If they are different, we put the same
 * {@link ClassInfo} to two {@link Namespace}s.
 */
public void add(ClassInfo<T, C> clazz) {
    assert clazz != null;
    String nsUri = null;
    if (clazz.getClazz() == navigator.asDecl(CompositeStructure.class))
        // this is a special class we introduced for JAX-WS that we *don't* want in the schema
        return;
    if (clazz.isElement()) {
        // put element -> type reference
        nsUri = clazz.getElementName().getNamespaceURI();
        Namespace ns = getNamespace(nsUri);
        ns.classes.add(clazz);
        ns.addDependencyTo(clazz.getTypeName());
        // schedule writing this global element
        add(clazz.getElementName(), false, clazz);
    }
    QName tn = clazz.getTypeName();
    if (tn != null) {
        nsUri = tn.getNamespaceURI();
    } else {
        // anonymous type
        if (nsUri == null)
            return;
    }
    Namespace n = getNamespace(nsUri);
    n.classes.add(clazz);
    // search properties for foreign namespace references
    for (PropertyInfo<T, C> p : clazz.getProperties()) {
        n.processForeignNamespaces(p, 1);
        if (p instanceof AttributePropertyInfo) {
            AttributePropertyInfo<T, C> ap = (AttributePropertyInfo<T, C>) p;
            String aUri = ap.getXmlName().getNamespaceURI();
            if (aUri.length() > 0) {
                // global attribute
                getNamespace(aUri).addGlobalAttribute(ap);
                n.addDependencyTo(ap.getXmlName());
            }
        }
        if (p instanceof ElementPropertyInfo) {
            ElementPropertyInfo<T, C> ep = (ElementPropertyInfo<T, C>) p;
            for (TypeRef<T, C> tref : ep.getTypes()) {
                String eUri = tref.getTagName().getNamespaceURI();
                if (eUri.length() > 0 && !eUri.equals(n.uri)) {
                    getNamespace(eUri).addGlobalElement(tref);
                    n.addDependencyTo(tref.getTagName());
                }
            }
        }
        if (generateSwaRefAdapter(p))
            n.useSwaRef = true;
        MimeType mimeType = p.getExpectedMimeType();
        if (mimeType != null) {
            n.useMimeNs = true;
        }
    }
    // recurse on baseTypes to make sure that we can refer to them in the schema
    ClassInfo<T, C> bc = clazz.getBaseClass();
    if (bc != null) {
        add(bc);
        n.addDependencyTo(bc.getTypeName());
    }
}
Also used : QName(javax.xml.namespace.QName) WellKnownNamespace(org.glassfish.jaxb.core.v2.WellKnownNamespace) MimeType(jakarta.activation.MimeType) CompositeStructure(org.glassfish.jaxb.runtime.api.CompositeStructure)

Example 2 with ClassInfo

use of org.glassfish.jaxb.core.v2.model.core.ClassInfo in project jaxb-ri by eclipse-ee4j.

the class AbstractMappingImpl method buildDrilldown.

/**
 * Derived classes can use this method to implement {@link #calcDrilldown}.
 */
protected List<Property> buildDrilldown(CClassInfo typeBean) {
    // they must not contain xsd:choice
    if (containingChoice(typeBean)) {
        return null;
    }
    List<Property> result;
    CClassInfo bc = typeBean.getBaseClass();
    if (bc != null) {
        result = buildDrilldown(bc);
        if (result == null) {
            // aborted
            return null;
        }
    } else {
        result = new ArrayList<>();
    }
    for (CPropertyInfo p : typeBean.getProperties()) {
        if (p instanceof CElementPropertyInfo) {
            CElementPropertyInfo ep = (CElementPropertyInfo) p;
            // wrong. A+,B,C is eligible for drill-down.
            // if(ep.isCollection())
            // // content model like A+,B,C is not eligible
            // return null;
            List<? extends CTypeRef> ref = ep.getTypes();
            if (ref.size() != 1) {
                // content model like (A|B),C is not eligible
                return null;
            }
            result.add(createPropertyImpl(ep, ref.get(0).getTagName()));
        } else if (p instanceof ReferencePropertyInfo) {
            CReferencePropertyInfo rp = (CReferencePropertyInfo) p;
            Collection<CElement> elements = rp.getElements();
            if (elements.size() != 1) {
                return null;
            }
            CElement ref = elements.iterator().next();
            if (ref instanceof ClassInfo) {
                result.add(createPropertyImpl(rp, ref.getElementName()));
            } else {
                CElementInfo eref = (CElementInfo) ref;
                if (!eref.getSubstitutionMembers().isEmpty()) {
                    // elements with a substitution group isn't qualified for the wrapper style
                    return null;
                }
                // JAX-WS doesn't want to see JAXBElement, so we have to hide it for them.
                ElementAdapter fr;
                if (rp.isCollection()) {
                    fr = new ElementCollectionAdapter(parent.outline.getField(rp), eref);
                } else {
                    fr = new ElementSingleAdapter(parent.outline.getField(rp), eref);
                }
                result.add(new PropertyImpl(this, fr, eref.getElementName()));
            }
        } else {
            // according to the JAX-RPC spec 2.3.1.2, element refs are disallowed
            return null;
        }
    }
    return result;
}
Also used : CElementInfo(com.sun.tools.xjc.model.CElementInfo) CPropertyInfo(com.sun.tools.xjc.model.CPropertyInfo) CClassInfo(com.sun.tools.xjc.model.CClassInfo) CElementPropertyInfo(com.sun.tools.xjc.model.CElementPropertyInfo) CElement(com.sun.tools.xjc.model.CElement) CReferencePropertyInfo(com.sun.tools.xjc.model.CReferencePropertyInfo) ReferencePropertyInfo(org.glassfish.jaxb.core.v2.model.core.ReferencePropertyInfo) Collection(java.util.Collection) CReferencePropertyInfo(com.sun.tools.xjc.model.CReferencePropertyInfo) Property(com.sun.tools.xjc.api.Property) CClassInfo(com.sun.tools.xjc.model.CClassInfo) ClassInfo(org.glassfish.jaxb.core.v2.model.core.ClassInfo)

Example 3 with ClassInfo

use of org.glassfish.jaxb.core.v2.model.core.ClassInfo in project jaxb-ri by eclipse-ee4j.

the class XmlSchemaGenerator method writeEpisodeFile.

/**
 * Writes out the episode file.
 */
public void writeEpisodeFile(XmlSerializer out) {
    Bindings root = TXW.create(Bindings.class, out);
    if (// otherwise jaxb binding NS should be the default namespace
    namespaces.containsKey(""))
        root._namespace(WellKnownNamespace.JAXB, "jaxb");
    root.version("2.1");
    // generate listing per schema
    for (Map.Entry<String, Namespace> e : namespaces.entrySet()) {
        Bindings group = root.bindings();
        String prefix;
        String tns = e.getKey();
        if (!tns.equals("")) {
            group._namespace(tns, "tns");
            prefix = "tns:";
        } else {
            prefix = "";
        }
        group.scd("x-schema::" + (tns.equals("") ? "" : "tns"));
        group.schemaBindings().map(false);
        for (ClassInfo<T, C> ci : e.getValue().classes) {
            // local type
            if (ci.getTypeName() == null)
                continue;
            if (ci.getTypeName().getNamespaceURI().equals(tns)) {
                Bindings child = group.bindings();
                child.scd('~' + prefix + ci.getTypeName().getLocalPart());
                child.klass().ref(ci.getName());
            }
            if (ci.isElement() && ci.getElementName().getNamespaceURI().equals(tns)) {
                Bindings child = group.bindings();
                child.scd(prefix + ci.getElementName().getLocalPart());
                child.klass().ref(ci.getName());
            }
        }
        for (EnumLeafInfo<T, C> en : e.getValue().enums) {
            // local type
            if (en.getTypeName() == null)
                continue;
            Bindings child = group.bindings();
            child.scd('~' + prefix + en.getTypeName().getLocalPart());
            child.klass().ref(navigator.getClassName(en.getClazz()));
        }
        group.commit(true);
    }
    root.commit();
}
Also used : Bindings(org.glassfish.jaxb.core.v2.schemagen.episode.Bindings) WellKnownNamespace(org.glassfish.jaxb.core.v2.WellKnownNamespace)

Aggregations

WellKnownNamespace (org.glassfish.jaxb.core.v2.WellKnownNamespace)2 Property (com.sun.tools.xjc.api.Property)1 CClassInfo (com.sun.tools.xjc.model.CClassInfo)1 CElement (com.sun.tools.xjc.model.CElement)1 CElementInfo (com.sun.tools.xjc.model.CElementInfo)1 CElementPropertyInfo (com.sun.tools.xjc.model.CElementPropertyInfo)1 CPropertyInfo (com.sun.tools.xjc.model.CPropertyInfo)1 CReferencePropertyInfo (com.sun.tools.xjc.model.CReferencePropertyInfo)1 MimeType (jakarta.activation.MimeType)1 Collection (java.util.Collection)1 QName (javax.xml.namespace.QName)1 ClassInfo (org.glassfish.jaxb.core.v2.model.core.ClassInfo)1 ReferencePropertyInfo (org.glassfish.jaxb.core.v2.model.core.ReferencePropertyInfo)1 Bindings (org.glassfish.jaxb.core.v2.schemagen.episode.Bindings)1 CompositeStructure (org.glassfish.jaxb.runtime.api.CompositeStructure)1