Search in sources :

Example 1 with OXMJavaClassImpl

use of org.eclipse.persistence.jaxb.javamodel.oxm.OXMJavaClassImpl in project eclipselink by eclipse-ee4j.

the class OXMMetadata method getJavaModelInput.

@Override
public JavaModelInput getJavaModelInput() throws JAXBException {
    JavaClass[] elinkClasses = createClassModelFromOXM(dynamicClassLoader);
    // Use the JavaModel to setup a Generator to generate an EclipseLink project
    OXMJavaModelImpl javaModel = new OXMJavaModelImpl(dynamicClassLoader, elinkClasses);
    for (JavaClass javaClass : elinkClasses) {
        try {
            ((OXMJavaClassImpl) javaClass).setJavaModel(javaModel);
        } catch (ClassCastException cce) {
            try {
                ((OXMObjectFactoryImpl) javaClass).setJavaModel(javaModel);
                ((OXMObjectFactoryImpl) javaClass).init();
            } catch (ClassCastException cce2) {
                ((JavaClassImpl) javaClass).setJavaModelImpl(javaModel);
            }
        }
    }
    return new OXMJavaModelInputImpl(elinkClasses, javaModel);
}
Also used : OXMJavaClassImpl(org.eclipse.persistence.jaxb.javamodel.oxm.OXMJavaClassImpl) JavaClassImpl(org.eclipse.persistence.jaxb.javamodel.reflection.JavaClassImpl) JavaClass(org.eclipse.persistence.jaxb.javamodel.JavaClass) OXMJavaModelImpl(org.eclipse.persistence.jaxb.javamodel.oxm.OXMJavaModelImpl) OXMJavaClassImpl(org.eclipse.persistence.jaxb.javamodel.oxm.OXMJavaClassImpl) OXMJavaModelInputImpl(org.eclipse.persistence.jaxb.javamodel.oxm.OXMJavaModelInputImpl)

Example 2 with OXMJavaClassImpl

use of org.eclipse.persistence.jaxb.javamodel.oxm.OXMJavaClassImpl 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)

Aggregations

JavaClass (org.eclipse.persistence.jaxb.javamodel.JavaClass)2 OXMJavaClassImpl (org.eclipse.persistence.jaxb.javamodel.oxm.OXMJavaClassImpl)2 JavaClassImpl (org.eclipse.persistence.jaxb.javamodel.reflection.JavaClassImpl)2 JAXBException (jakarta.xml.bind.JAXBException)1 ArrayList (java.util.ArrayList)1 OXMJavaModelImpl (org.eclipse.persistence.jaxb.javamodel.oxm.OXMJavaModelImpl)1 OXMJavaModelInputImpl (org.eclipse.persistence.jaxb.javamodel.oxm.OXMJavaModelInputImpl)1 OXMObjectFactoryImpl (org.eclipse.persistence.jaxb.javamodel.oxm.OXMObjectFactoryImpl)1 JavaType (org.eclipse.persistence.jaxb.xmlmodel.JavaType)1 XmlBindings (org.eclipse.persistence.jaxb.xmlmodel.XmlBindings)1 XmlEnum (org.eclipse.persistence.jaxb.xmlmodel.XmlEnum)1 XmlEnumValue (org.eclipse.persistence.jaxb.xmlmodel.XmlEnumValue)1 XmlRegistry (org.eclipse.persistence.jaxb.xmlmodel.XmlRegistry)1