Search in sources :

Example 1 with XmlSchema

use of org.eclipse.persistence.jaxb.xmlmodel.XmlSchema in project eclipselink by eclipse-ee4j.

the class XMLProcessor method processXmlSchema.

/**
 * Process an XmlSchema. This involves creating a NamespaceInfo instance and
 * populating it based on the given XmlSchema.
 *
 * @see NamespaceInfo
 * @see AnnotationsProcessor
 * @return newly created namespace info, or null if schema is null
 */
private NamespaceInfo processXmlSchema(XmlBindings xmlBindings, String packageName) {
    XmlSchema schema = xmlBindings.getXmlSchema();
    if (schema == null) {
        return null;
    }
    // create NamespaceInfo
    NamespaceInfo nsInfo = this.aProcessor.findInfoForNamespace(schema.getNamespace());
    if (nsInfo == null) {
        nsInfo = new NamespaceInfo();
    }
    // process XmlSchema
    XmlNsForm form = schema.getAttributeFormDefault();
    nsInfo.setAttributeFormQualified(form.equals(XmlNsForm.QUALIFIED));
    form = schema.getElementFormDefault();
    nsInfo.setElementFormQualified(form.equals(XmlNsForm.QUALIFIED));
    if (!nsInfo.isElementFormQualified() || nsInfo.isAttributeFormQualified()) {
        aProcessor.setDefaultNamespaceAllowed(false);
    }
    // make sure defaults are set, not null
    nsInfo.setLocation(schema.getLocation() == null ? GENERATE : schema.getLocation());
    String namespace = schema.getNamespace();
    if (namespace == null) {
        namespace = this.aProcessor.getDefaultTargetNamespace();
    }
    nsInfo.setNamespace(namespace == null ? "" : schema.getNamespace());
    NamespaceResolver nsr = new NamespaceResolver();
    // process XmlNs
    for (XmlNs xmlns : schema.getXmlNs()) {
        nsr.put(xmlns.getPrefix(), xmlns.getNamespaceUri());
    }
    nsInfo.setNamespaceResolver(nsr);
    return nsInfo;
}
Also used : XmlSchema(org.eclipse.persistence.jaxb.xmlmodel.XmlSchema) XmlNsForm(org.eclipse.persistence.jaxb.xmlmodel.XmlNsForm) XmlNs(org.eclipse.persistence.jaxb.xmlmodel.XmlSchema.XmlNs) NamespaceResolver(org.eclipse.persistence.oxm.NamespaceResolver)

Example 2 with XmlSchema

use of org.eclipse.persistence.jaxb.xmlmodel.XmlSchema in project eclipselink by eclipse-ee4j.

the class XMLBindingsPopulatedTestCases method getControlObject.

@Override
protected Object getControlObject() {
    XmlBindings xmlBindings = new XmlBindings();
    xmlBindings.setPackageName("test.model");
    xmlBindings.setXmlAccessorType(XmlAccessType.PUBLIC_MEMBER);
    xmlBindings.setXmlAccessorOrder(org.eclipse.persistence.jaxb.xmlmodel.XmlAccessOrder.ALPHABETICAL);
    XmlEnums enums = new XmlEnums();
    XmlEnum e1 = new XmlEnum();
    e1.setJavaEnum("A");
    e1.setValue("A_Value");
    XmlEnum e2 = new XmlEnum();
    e2.setJavaEnum("B");
    e2.setValue("B_Value");
    enums.getXmlEnum().add(e1);
    enums.getXmlEnum().add(e2);
    xmlBindings.setXmlEnums(enums);
    xmlBindings.setXmlNameTransformer("test.someNameTransformer");
    XmlSchema xmlSchema = new XmlSchema();
    xmlSchema.setAttributeFormDefault(XmlNsForm.UNQUALIFIED);
    xmlSchema.setElementFormDefault(XmlNsForm.UNQUALIFIED);
    xmlSchema.setLocation("someLocation");
    xmlSchema.setNamespace("testnamespace");
    xmlBindings.setXmlSchema(xmlSchema);
    XmlSchemaTypes xmlSchemaTypes = new XmlSchemaTypes();
    XmlSchemaType xmlSchemaType = new XmlSchemaType();
    xmlSchemaType.setName("someSchemaType");
    xmlSchemaType.setNamespace("someSchemaTypeNamespace");
    xmlSchemaType.setType("someSchemaType");
    XmlSchemaType xmlSchemaType2 = new XmlSchemaType();
    xmlSchemaType2.setName("someSchemaType2");
    xmlSchemaType2.setNamespace("someSchemaTypeNamespace2");
    xmlSchemaType2.setType("someSchemaType2");
    xmlSchemaTypes.getXmlSchemaType().add(xmlSchemaType);
    xmlSchemaTypes.getXmlSchemaType().add(xmlSchemaType2);
    xmlBindings.setXmlSchemaTypes(xmlSchemaTypes);
    xmlBindings.setXmlMappingMetadataComplete(Boolean.FALSE);
    XmlRegistries xmlRegistries = new XmlRegistries();
    XmlRegistry r1 = new XmlRegistry();
    r1.setName("someRegistry");
    xmlRegistries.getXmlRegistry().add(r1);
    xmlBindings.setXmlRegistries(xmlRegistries);
    XmlJavaTypeAdapters xmlJavaTypeAdapters = new XmlJavaTypeAdapters();
    XmlJavaTypeAdapter a1 = new XmlJavaTypeAdapter();
    a1.setType("someAdapterType");
    a1.setValue("someAdapterValue");
    a1.setValueType("somValueType");
    a1.setJavaAttribute("someJavaAttribute");
    xmlJavaTypeAdapters.getXmlJavaTypeAdapter().add(a1);
    xmlBindings.setXmlJavaTypeAdapters(xmlJavaTypeAdapters);
    JavaTypes types = new JavaTypes();
    JavaType javaType = new JavaType();
    javaType.setName("myType");
    javaType.setXmlTransient(Boolean.FALSE);
    javaType.setXmlAccessorOrder(org.eclipse.persistence.jaxb.xmlmodel.XmlAccessOrder.ALPHABETICAL);
    XmlProperties xmlProperties = new XmlProperties();
    XmlProperty p1 = new XmlProperty();
    p1.setName("prop1");
    p1.setValue("propValue");
    p1.setValueType("propValueType");
    xmlProperties.getXmlProperty().add(p1);
    javaType.setXmlProperties(xmlProperties);
    javaType.setXmlDiscriminatorNode("descriminator node");
    javaType.setXmlDiscriminatorValue("discriminator value");
    XmlClassExtractor extractor = new XmlClassExtractor();
    extractor.setClazz("a.b.c.someClass");
    javaType.setXmlClassExtractor(extractor);
    javaType.setXmlInlineBinaryData(Boolean.FALSE);
    XmlRootElement root = new XmlRootElement();
    root.setName("someRoot");
    root.setNamespace("someNamespace");
    javaType.setXmlRootElement(root);
    XmlType xmlType = new XmlType();
    xmlType.setFactoryClass("somepackage.someFactoryclass");
    xmlType.setName("someName");
    xmlType.setFactoryMethod("someMethod");
    xmlType.getPropOrder().add("p2");
    xmlType.getPropOrder().add("p1");
    javaType.setXmlType(xmlType);
    JavaAttributes javaAttributes = new JavaAttributes();
    XmlElement javaAttribute = new XmlElement();
    javaAttribute.setName("elementName");
    javaAttribute.setJavaAttribute("theJavaAttributeValue");
    JAXBElement<XmlElement> jbe = new JAXBElement<XmlElement>(new QName("http://www.eclipse.org/eclipselink/xsds/persistence/oxm", "xml-element"), XmlElement.class, javaAttribute);
    XmlElement javaAttribute2 = new XmlElement();
    javaAttribute2.setName("elementName2");
    javaAttribute2.setJavaAttribute("theJavaAttributeValue2");
    JAXBElement<XmlElement> jbe2 = new JAXBElement<XmlElement>(new QName("http://www.eclipse.org/eclipselink/xsds/persistence/oxm", "xml-element"), XmlElement.class, javaAttribute2);
    XmlAttribute javaAttribute3 = new XmlAttribute();
    javaAttribute3.setContainerType("someContainerType");
    javaAttribute3.setJavaAttribute("javaAttribute");
    javaAttribute3.setNamespace("somenamespace");
    javaAttribute3.setName("attributename1");
    javaAttribute3.setReadOnly(Boolean.TRUE);
    javaAttribute3.setRequired(Boolean.TRUE);
    JAXBElement<XmlAttribute> jbe3 = new JAXBElement<XmlAttribute>(new QName("http://www.eclipse.org/eclipselink/xsds/persistence/oxm", "xml-attribute"), XmlAttribute.class, javaAttribute3);
    javaAttributes.getJavaAttribute().add(jbe);
    javaAttributes.getJavaAttribute().add(jbe3);
    javaAttributes.getJavaAttribute().add(jbe2);
    javaType.setJavaAttributes(javaAttributes);
    types.getJavaType().add(javaType);
    xmlBindings.setJavaTypes(types);
    return xmlBindings;
}
Also used : JavaTypes(org.eclipse.persistence.jaxb.xmlmodel.XmlBindings.JavaTypes) XmlBindings(org.eclipse.persistence.jaxb.xmlmodel.XmlBindings) XmlEnums(org.eclipse.persistence.jaxb.xmlmodel.XmlBindings.XmlEnums) XmlRootElement(org.eclipse.persistence.jaxb.xmlmodel.XmlRootElement) XmlProperties(org.eclipse.persistence.jaxb.xmlmodel.XmlProperties) XmlAttribute(org.eclipse.persistence.jaxb.xmlmodel.XmlAttribute) XmlProperty(org.eclipse.persistence.jaxb.xmlmodel.XmlProperties.XmlProperty) QName(javax.xml.namespace.QName) XmlJavaTypeAdapter(org.eclipse.persistence.jaxb.xmlmodel.XmlJavaTypeAdapter) JAXBElement(jakarta.xml.bind.JAXBElement) XmlSchemaType(org.eclipse.persistence.jaxb.xmlmodel.XmlSchemaType) XmlRegistry(org.eclipse.persistence.jaxb.xmlmodel.XmlRegistry) XmlSchemaTypes(org.eclipse.persistence.jaxb.xmlmodel.XmlSchemaTypes) XmlEnum(org.eclipse.persistence.jaxb.xmlmodel.XmlEnum) XmlClassExtractor(org.eclipse.persistence.jaxb.xmlmodel.XmlClassExtractor) XmlType(org.eclipse.persistence.jaxb.xmlmodel.XmlType) JavaType(org.eclipse.persistence.jaxb.xmlmodel.JavaType) JavaAttributes(org.eclipse.persistence.jaxb.xmlmodel.JavaType.JavaAttributes) XmlSchema(org.eclipse.persistence.jaxb.xmlmodel.XmlSchema) XmlRegistries(org.eclipse.persistence.jaxb.xmlmodel.XmlBindings.XmlRegistries) XmlElement(org.eclipse.persistence.jaxb.xmlmodel.XmlElement) XmlJavaTypeAdapters(org.eclipse.persistence.jaxb.xmlmodel.XmlJavaTypeAdapters)

Example 3 with XmlSchema

use of org.eclipse.persistence.jaxb.xmlmodel.XmlSchema in project eclipselink by eclipse-ee4j.

the class XmlBindingsGenerator method generateXmlBindings.

/**
 * Generate an XmlBindings instance based on a list of XML descriptors.
 *
 * OXM metadata files are processed on a per package basis, hence it is
 * assumed that the given list of descriptors are from the same package.
 */
public static XmlBindings generateXmlBindings(String packageName, List<XMLDescriptor> descriptors) {
    String defaultNamespace = null;
    Map<String, String> prefixMap = new HashMap<String, String>();
    JavaTypes jTypes = new JavaTypes();
    for (XMLDescriptor xdesc : descriptors) {
        // mappings to the map
        if (xdesc.getNamespaceResolver() != null) {
            if (defaultNamespace == null) {
                defaultNamespace = xdesc.getNamespaceResolver().getDefaultNamespaceURI();
            }
            Map<String, String> preMap = xdesc.getNamespaceResolver().getPrefixesToNamespaces();
            for (String pfx : preMap.keySet()) {
                // ignore mime prefix/url for now
                if (!pfx.equals(XML_MIME_PREFIX)) {
                    prefixMap.put(pfx, preMap.get(pfx));
                }
            }
        }
        // generate a JavaType instance for the XML descriptor
        jTypes.getJavaType().add(generateJavaType(xdesc));
    }
    XmlBindings xmlBindings = null;
    // if there are no JavaTypes, there's nothing to do
    if (jTypes.getJavaType().size() > 0) {
        xmlBindings = new XmlBindings();
        xmlBindings.setJavaTypes(jTypes);
        xmlBindings.setPackageName(packageName);
        // handle XmlSchema
        if (defaultNamespace != null || !prefixMap.isEmpty()) {
            XmlSchema xSchema = new XmlSchema();
            xSchema.setNamespace(defaultNamespace == null ? EMPTY_STRING : defaultNamespace);
            xSchema.setElementFormDefault(XmlNsForm.QUALIFIED);
            // handle XmlNs
            if (!prefixMap.isEmpty()) {
                XmlNs xmlNs;
                for (String pfx : prefixMap.keySet()) {
                    xmlNs = new XmlNs();
                    xmlNs.setNamespaceUri(prefixMap.get(pfx));
                    xmlNs.setPrefix(pfx);
                    xSchema.getXmlNs().add(xmlNs);
                }
            }
            xmlBindings.setXmlSchema(xSchema);
        }
    }
    return xmlBindings;
}
Also used : JavaTypes(org.eclipse.persistence.jaxb.xmlmodel.XmlBindings.JavaTypes) XmlBindings(org.eclipse.persistence.jaxb.xmlmodel.XmlBindings) XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) HashMap(java.util.HashMap) XmlSchema(org.eclipse.persistence.jaxb.xmlmodel.XmlSchema) XmlNs(org.eclipse.persistence.jaxb.xmlmodel.XmlSchema.XmlNs)

Aggregations

XmlSchema (org.eclipse.persistence.jaxb.xmlmodel.XmlSchema)3 XmlBindings (org.eclipse.persistence.jaxb.xmlmodel.XmlBindings)2 JavaTypes (org.eclipse.persistence.jaxb.xmlmodel.XmlBindings.JavaTypes)2 XmlNs (org.eclipse.persistence.jaxb.xmlmodel.XmlSchema.XmlNs)2 JAXBElement (jakarta.xml.bind.JAXBElement)1 HashMap (java.util.HashMap)1 QName (javax.xml.namespace.QName)1 JavaType (org.eclipse.persistence.jaxb.xmlmodel.JavaType)1 JavaAttributes (org.eclipse.persistence.jaxb.xmlmodel.JavaType.JavaAttributes)1 XmlAttribute (org.eclipse.persistence.jaxb.xmlmodel.XmlAttribute)1 XmlEnums (org.eclipse.persistence.jaxb.xmlmodel.XmlBindings.XmlEnums)1 XmlRegistries (org.eclipse.persistence.jaxb.xmlmodel.XmlBindings.XmlRegistries)1 XmlClassExtractor (org.eclipse.persistence.jaxb.xmlmodel.XmlClassExtractor)1 XmlElement (org.eclipse.persistence.jaxb.xmlmodel.XmlElement)1 XmlEnum (org.eclipse.persistence.jaxb.xmlmodel.XmlEnum)1 XmlJavaTypeAdapter (org.eclipse.persistence.jaxb.xmlmodel.XmlJavaTypeAdapter)1 XmlJavaTypeAdapters (org.eclipse.persistence.jaxb.xmlmodel.XmlJavaTypeAdapters)1 XmlNsForm (org.eclipse.persistence.jaxb.xmlmodel.XmlNsForm)1 XmlProperties (org.eclipse.persistence.jaxb.xmlmodel.XmlProperties)1 XmlProperty (org.eclipse.persistence.jaxb.xmlmodel.XmlProperties.XmlProperty)1