Search in sources :

Example 6 with JavaClassImpl

use of org.eclipse.persistence.jaxb.javamodel.reflection.JavaClassImpl in project eclipselink by eclipse-ee4j.

the class CompilerHelper method createAccessorFor.

public static Object createAccessorFor(JavaClass jClass, Property property, Helper helper, AccessorFactoryWrapper accessorFactory) {
    if (!(jClass.getClass() == JavaClassImpl.class)) {
        return null;
    }
    Class<?> beanClass = ((JavaClassImpl) jClass).getJavaClass();
    if (property.isMethodProperty()) {
        try {
            Method getMethod = null;
            Method setMethod = null;
            if (property.getGetMethodName() != null) {
                getMethod = PrivilegedAccessHelper.getMethod(beanClass, property.getGetMethodName(), new Class<?>[] {}, true);
            }
            if (property.getSetMethodName() != null) {
                String setMethodParamTypeName = property.getType().getName();
                JavaClassImpl paramType = (JavaClassImpl) helper.getJavaClass(setMethodParamTypeName);
                Class<?>[] setMethodParams = new Class<?>[] { paramType.getJavaClass() };
                setMethod = PrivilegedAccessHelper.getMethod(beanClass, property.getSetMethodName(), setMethodParams, true);
            }
            return accessorFactory.createPropertyAccessor(beanClass, getMethod, setMethod);
        } catch (Exception ex) {
        }
    } else {
        try {
            Field field = PrivilegedAccessHelper.getField(beanClass, ((JavaField) property.getElement()).getName(), true);
            return accessorFactory.createFieldAccessor(beanClass, field, property.isReadOnly());
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
    return null;
}
Also used : JavaClassImpl(org.eclipse.persistence.jaxb.javamodel.reflection.JavaClassImpl) JavaField(org.eclipse.persistence.jaxb.javamodel.JavaField) Field(java.lang.reflect.Field) JavaClass(org.eclipse.persistence.jaxb.javamodel.JavaClass) Method(java.lang.reflect.Method) JavaMethod(org.eclipse.persistence.jaxb.javamodel.JavaMethod) JAXBException(jakarta.xml.bind.JAXBException)

Example 7 with JavaClassImpl

use of org.eclipse.persistence.jaxb.javamodel.reflection.JavaClassImpl 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 8 with JavaClassImpl

use of org.eclipse.persistence.jaxb.javamodel.reflection.JavaClassImpl in project eclipselink by eclipse-ee4j.

the class OXMJavaModelImpl method getClass.

/**
 * Obtain the <code>JavaClass</code> given the corresponding Java <code>Class'</code> name.
 *
 * @param className - the name of the Java <code>Class</code> to search for.
 *
 * @return the <code>JavaClass</code> corresponding to <code>className</code>.
 */
@Override
public JavaClass getClass(String className) {
    if (className == null) {
        return null;
    }
    // jakarta.xml.bind.annotation.XmlElement.DEFAULT
    if (className.contains(DEFAULT)) {
        return getClass(JAVA_LANG_OBJECT);
    }
    JavaClass cachedClass = this.javaModelClasses.get(className);
    if (cachedClass != null) {
        return cachedClass;
    }
    // try actually finding the class, might be concrete
    try {
        Class<?> realClass = PrivilegedAccessHelper.getClassForName(className, true, classLoader);
        if (realClass != null) {
            JavaModelImpl jm = new JavaModelImpl(this.classLoader);
            JavaClassImpl jc = new JavaClassImpl(realClass, jm);
            return jc;
        }
    } catch (Exception e) {
    }
    return new OXMJavaClassImpl(className);
}
Also used : JavaClassImpl(org.eclipse.persistence.jaxb.javamodel.reflection.JavaClassImpl) JavaClass(org.eclipse.persistence.jaxb.javamodel.JavaClass) JavaModelImpl(org.eclipse.persistence.jaxb.javamodel.reflection.JavaModelImpl)

Aggregations

JavaClassImpl (org.eclipse.persistence.jaxb.javamodel.reflection.JavaClassImpl)8 JavaClass (org.eclipse.persistence.jaxb.javamodel.JavaClass)6 JAXBException (jakarta.xml.bind.JAXBException)2 ParameterizedType (java.lang.reflect.ParameterizedType)2 ArrayList (java.util.ArrayList)2 OXMJavaClassImpl (org.eclipse.persistence.jaxb.javamodel.oxm.OXMJavaClassImpl)2 JavaModelImpl (org.eclipse.persistence.jaxb.javamodel.reflection.JavaModelImpl)2 JavaType (org.eclipse.persistence.jaxb.xmlmodel.JavaType)2 XmlBindings (org.eclipse.persistence.jaxb.xmlmodel.XmlBindings)2 XmlEnum (org.eclipse.persistence.jaxb.xmlmodel.XmlEnum)2 XmlEnumValue (org.eclipse.persistence.jaxb.xmlmodel.XmlEnumValue)2 XmlRegistry (org.eclipse.persistence.jaxb.xmlmodel.XmlRegistry)2 Field (java.lang.reflect.Field)1 GenericArrayType (java.lang.reflect.GenericArrayType)1 Method (java.lang.reflect.Method)1 Type (java.lang.reflect.Type)1 TypeVariable (java.lang.reflect.TypeVariable)1 java.util (java.util)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1