Search in sources :

Example 6 with JavaType

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

the class OXMMetadata method createClassModelFromOXM.

private JavaClass[] createClassModelFromOXM(DynamicClassLoader dynamicClassLoader) throws JAXBException {
    List<JavaClass> oxmJavaClasses = new ArrayList<JavaClass>();
    Iterator<String> keys = bindings.keySet().iterator();
    while (keys.hasNext()) {
        String pkgName = keys.next();
        XmlBindings b = bindings.get(pkgName);
        if (b.getJavaTypes() != null) {
            List<JavaType> javaTypes = b.getJavaTypes().getJavaType();
            for (Iterator<JavaType> iterator = javaTypes.iterator(); iterator.hasNext(); ) {
                JavaType type = iterator.next();
                // Check to see if it's a static class or if should be treated as dynamic
                try {
                    Class<?> staticClass = dynamicClassLoader.getParent().loadClass(Helper.getQualifiedJavaTypeName(type.getName(), pkgName));
                    oxmJavaClasses.add(new JavaClassImpl(staticClass, null));
                } catch (Exception ex) {
                    type.setName(Helper.getQualifiedJavaTypeName(type.getName(), pkgName));
                    oxmJavaClasses.add(new OXMJavaClassImpl(type));
                }
            }
        }
        if (b.getXmlRegistries() != null) {
            List<XmlRegistry> registries = b.getXmlRegistries().getXmlRegistry();
            for (Iterator<XmlRegistry> iterator = registries.iterator(); iterator.hasNext(); ) {
                XmlRegistry reg = iterator.next();
                oxmJavaClasses.add(new OXMObjectFactoryImpl(reg));
            }
        }
        if (b.getXmlEnums() != null) {
            List<XmlEnum> enums = b.getXmlEnums().getXmlEnum();
            for (Iterator<XmlEnum> iterator = enums.iterator(); iterator.hasNext(); ) {
                XmlEnum xmlEnum = iterator.next();
                List<XmlEnumValue> enumValues = xmlEnum.getXmlEnumValue();
                List<String> enumValueStrings = new ArrayList<String>();
                for (Iterator<XmlEnumValue> iterator2 = enumValues.iterator(); iterator2.hasNext(); ) {
                    XmlEnumValue xmlEnumValue = iterator2.next();
                    enumValueStrings.add(xmlEnumValue.getJavaEnumValue());
                }
                oxmJavaClasses.add(new OXMJavaClassImpl(xmlEnum.getJavaEnum(), enumValueStrings));
                // Trigger a dynamic class generation, because we won't
                // be creating a descriptor for this
                dynamicClassLoader.addEnum(xmlEnum.getJavaEnum(), enumValueStrings.toArray());
            }
        }
    }
    JavaClass[] javaClasses = new JavaClass[oxmJavaClasses.size()];
    for (int i = 0; i < javaClasses.length; i++) {
        javaClasses[i] = oxmJavaClasses.get(i);
    }
    return javaClasses;
}
Also used : XmlBindings(org.eclipse.persistence.jaxb.xmlmodel.XmlBindings) ArrayList(java.util.ArrayList) OXMObjectFactoryImpl(org.eclipse.persistence.jaxb.javamodel.oxm.OXMObjectFactoryImpl) OXMJavaClassImpl(org.eclipse.persistence.jaxb.javamodel.oxm.OXMJavaClassImpl) JavaClassImpl(org.eclipse.persistence.jaxb.javamodel.reflection.JavaClassImpl) XmlRegistry(org.eclipse.persistence.jaxb.xmlmodel.XmlRegistry) JAXBException(jakarta.xml.bind.JAXBException) XmlEnum(org.eclipse.persistence.jaxb.xmlmodel.XmlEnum) JavaType(org.eclipse.persistence.jaxb.xmlmodel.JavaType) JavaClass(org.eclipse.persistence.jaxb.javamodel.JavaClass) XmlEnumValue(org.eclipse.persistence.jaxb.xmlmodel.XmlEnumValue) OXMJavaClassImpl(org.eclipse.persistence.jaxb.javamodel.oxm.OXMJavaClassImpl)

Example 7 with JavaType

use of org.eclipse.persistence.jaxb.xmlmodel.JavaType 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 8 with JavaType

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

the class XMLBindingsTestCases method getControlObject.

@Override
protected Object getControlObject() {
    XmlBindings xmlBindings = new XmlBindings();
    xmlBindings.setPackageName("myPackage");
    JavaTypes types = new JavaTypes();
    JavaType javaType = new JavaType();
    javaType.setName("myType");
    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);
    javaAttributes.getJavaAttribute().add(jbe);
    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) JavaType(org.eclipse.persistence.jaxb.xmlmodel.JavaType) JavaAttributes(org.eclipse.persistence.jaxb.xmlmodel.JavaType.JavaAttributes) QName(javax.xml.namespace.QName) XmlElement(org.eclipse.persistence.jaxb.xmlmodel.XmlElement) JAXBElement(jakarta.xml.bind.JAXBElement)

Example 9 with JavaType

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

the class XmlBindingsGenerator method generateJavaType.

/**
 * Process a given XMLDescriptor and return a JavaType instance.
 */
protected static JavaType generateJavaType(XMLDescriptor xdesc) {
    String defaultNamespace = null;
    if (xdesc.getNamespaceResolver() != null) {
        defaultNamespace = xdesc.getNamespaceResolver().getDefaultNamespaceURI();
    }
    String schemaContext = null;
    if (xdesc.getSchemaReference() != null) {
        schemaContext = xdesc.getSchemaReference().getSchemaContext();
    }
    JavaType jType = new JavaType();
    jType.setName(getClassName(xdesc.getJavaClassName()));
    jType.setXmlAccessorType(XmlAccessType.FIELD);
    // handle XmlType
    if (schemaContext != null) {
        XmlType xType = new XmlType();
        xType.setName(schemaContext.substring(1, schemaContext.length()));
        if (defaultNamespace != null) {
            xType.setNamespace(defaultNamespace);
        }
        jType.setXmlType(xType);
    }
    // handle XmlRootElement
    XmlRootElement xmlRootElt = new XmlRootElement();
    xmlRootElt.setName(xdesc.getDefaultRootElement());
    if (defaultNamespace != null) {
        xmlRootElt.setNamespace(defaultNamespace);
    }
    jType.setXmlRootElement(xmlRootElt);
    jType.setJavaAttributes(new JavaAttributes());
    // generate an XmlAttribute or XmlElement for each mapping
    for (Iterator<DatabaseMapping> xmapIt = xdesc.getMappings().iterator(); xmapIt.hasNext(); ) {
        XMLMapping xMap = (XMLMapping) xmapIt.next();
        if (((XMLField) xMap.getField()).getXPathFragment().isAttribute()) {
            JAXBElement<XmlAttribute> jAtt = generateXmlAttribute(xMap);
            if (jAtt != null) {
                jType.getJavaAttributes().getJavaAttribute().add(jAtt);
            }
        } else {
            JAXBElement<XmlElement> jElt = generateXmlElement(xMap);
            if (jElt != null) {
                jType.getJavaAttributes().getJavaAttribute().add(jElt);
            }
        }
    }
    return jType;
}
Also used : XmlRootElement(org.eclipse.persistence.jaxb.xmlmodel.XmlRootElement) JavaType(org.eclipse.persistence.jaxb.xmlmodel.JavaType) JavaAttributes(org.eclipse.persistence.jaxb.xmlmodel.JavaType.JavaAttributes) XmlAttribute(org.eclipse.persistence.jaxb.xmlmodel.XmlAttribute) XMLMapping(org.eclipse.persistence.oxm.mappings.XMLMapping) XmlElement(org.eclipse.persistence.jaxb.xmlmodel.XmlElement) DatabaseMapping(org.eclipse.persistence.mappings.DatabaseMapping) XmlType(org.eclipse.persistence.jaxb.xmlmodel.XmlType)

Aggregations

JavaType (org.eclipse.persistence.jaxb.xmlmodel.JavaType)9 JavaAttributes (org.eclipse.persistence.jaxb.xmlmodel.JavaType.JavaAttributes)5 XmlBindings (org.eclipse.persistence.jaxb.xmlmodel.XmlBindings)5 XmlElement (org.eclipse.persistence.jaxb.xmlmodel.XmlElement)5 JavaTypes (org.eclipse.persistence.jaxb.xmlmodel.XmlBindings.JavaTypes)4 XmlEnum (org.eclipse.persistence.jaxb.xmlmodel.XmlEnum)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 JavaClass (org.eclipse.persistence.jaxb.javamodel.JavaClass)3 XmlEnums (org.eclipse.persistence.jaxb.xmlmodel.XmlBindings.XmlEnums)3 XmlJavaTypeAdapter (org.eclipse.persistence.jaxb.xmlmodel.XmlJavaTypeAdapter)3 XmlRegistry (org.eclipse.persistence.jaxb.xmlmodel.XmlRegistry)3 DatabaseMapping (org.eclipse.persistence.mappings.DatabaseMapping)3 JAXBElement (jakarta.xml.bind.JAXBElement)2 QName (javax.xml.namespace.QName)2 JavaClassImpl (org.eclipse.persistence.jaxb.javamodel.reflection.JavaClassImpl)2 XmlAttribute (org.eclipse.persistence.jaxb.xmlmodel.XmlAttribute)2 XmlRegistries (org.eclipse.persistence.jaxb.xmlmodel.XmlBindings.XmlRegistries)2 XmlEnumValue (org.eclipse.persistence.jaxb.xmlmodel.XmlEnumValue)2 XmlProperty (org.eclipse.persistence.jaxb.xmlmodel.XmlProperties.XmlProperty)2