Search in sources :

Example 1 with CoreProject

use of org.eclipse.persistence.core.sessions.CoreProject in project eclipselink by eclipse-ee4j.

the class PropertyTypeTestCases method testPropertyTypes.

public void testPropertyTypes() throws Exception {
    JaxbClassLoader classLoader = new JaxbClassLoader(Thread.currentThread().getContextClassLoader());
    Generator generator = new Generator(new JavaModelInputImpl(new Class<?>[] { TestObject.class }, new JavaModelImpl(this.classLoader)));
    CoreProject proj = generator.generateProject();
    TypeInfo info = generator.getAnnotationsProcessor().getTypeInfos().get("org.eclipse.persistence.testing.jaxb.annotations.TestObject");
    Property booleanProp = info.getProperties().get("booleanTest");
    JavaClass type = booleanProp.getType();
    assertEquals("java.lang.Boolean", type.getRawName());
    Property booleanListProp = info.getProperties().get("booleanListTest");
    type = booleanListProp.getType();
    assertEquals("java.util.List", type.getRawName());
    Property byteArrayProp = info.getProperties().get("byteArrayTest");
    type = byteArrayProp.getType();
    assertEquals("java.lang.String", type.getRawName());
    Property byteArrayListProp = info.getProperties().get("byteArrayListTest");
    type = byteArrayListProp.getType();
    assertEquals("java.util.List", type.getRawName());
    assertEquals("java.lang.String", byteArrayListProp.getGenericType().getRawName());
}
Also used : JavaModelInputImpl(org.eclipse.persistence.jaxb.javamodel.reflection.JavaModelInputImpl) CoreProject(org.eclipse.persistence.core.sessions.CoreProject) JavaModelImpl(org.eclipse.persistence.jaxb.javamodel.reflection.JavaModelImpl) JavaClass(org.eclipse.persistence.jaxb.javamodel.JavaClass) JavaClass(org.eclipse.persistence.jaxb.javamodel.JavaClass) TypeInfo(org.eclipse.persistence.jaxb.compiler.TypeInfo) Property(org.eclipse.persistence.jaxb.compiler.Property) JaxbClassLoader(org.eclipse.persistence.internal.jaxb.JaxbClassLoader) Generator(org.eclipse.persistence.jaxb.compiler.Generator)

Example 2 with CoreProject

use of org.eclipse.persistence.core.sessions.CoreProject in project eclipselink by eclipse-ee4j.

the class Generator method generateProject.

public CoreProject generateProject() throws Exception {
    mappingsGenerator.getClassToGeneratedClasses().putAll(annotationsProcessor.getArrayClassesToGeneratedClasses());
    CoreProject p = mappingsGenerator.generateProject(annotationsProcessor.getTypeInfoClasses(), annotationsProcessor.getTypeInfos(), annotationsProcessor.getUserDefinedSchemaTypes(), annotationsProcessor.getPackageToPackageInfoMappings(), annotationsProcessor.getGlobalElements(), annotationsProcessor.getLocalElements(), annotationsProcessor.getTypeMappingInfosToGeneratedClasses(), annotationsProcessor.getTypeMappingInfoToAdapterClasses(), annotationsProcessor.isDefaultNamespaceAllowed());
    annotationsProcessor.getArrayClassesToGeneratedClasses().putAll(mappingsGenerator.getClassToGeneratedClasses());
    return p;
}
Also used : CoreProject(org.eclipse.persistence.core.sessions.CoreProject)

Example 3 with CoreProject

use of org.eclipse.persistence.core.sessions.CoreProject in project eclipselink by eclipse-ee4j.

the class ExternalizedMetadataTestCases method createXmlContext.

/**
 * Convenience method that returns a newly created XMLContext based on an array of classes.
 */
protected XMLContext createXmlContext(Class<?>[] classes) {
    try {
        ClassLoader classLoader = new JaxbClassLoader(Thread.currentThread().getContextClassLoader());
        Generator generator = new Generator(new JavaModelInputImpl(classes, new JavaModelImpl(classLoader)));
        CoreProject proj = generator.generateProject();
        ConversionManager manager = new ConversionManager();
        manager.setLoader(classLoader);
        for (Iterator<ClassDescriptor> descriptorIt = proj.getOrderedDescriptors().iterator(); descriptorIt.hasNext(); ) {
            ClassDescriptor descriptor = descriptorIt.next();
            if (descriptor.getJavaClass() == null) {
                descriptor.setJavaClass(manager.convertClassNameToClass(descriptor.getJavaClassName()));
            }
        }
        return new XMLContext((Project) proj, classLoader);
    } catch (Exception e) {
        e.printStackTrace();
        fail("XmlContext creation failed");
    }
    return null;
}
Also used : JavaModelInputImpl(org.eclipse.persistence.jaxb.javamodel.reflection.JavaModelInputImpl) CoreProject(org.eclipse.persistence.core.sessions.CoreProject) JavaModelImpl(org.eclipse.persistence.jaxb.javamodel.reflection.JavaModelImpl) ClassDescriptor(org.eclipse.persistence.descriptors.ClassDescriptor) XMLContext(org.eclipse.persistence.oxm.XMLContext) JaxbClassLoader(org.eclipse.persistence.internal.jaxb.JaxbClassLoader) ConversionManager(org.eclipse.persistence.internal.helper.ConversionManager) JaxbClassLoader(org.eclipse.persistence.internal.jaxb.JaxbClassLoader) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) JAXBException(jakarta.xml.bind.JAXBException) Generator(org.eclipse.persistence.jaxb.compiler.Generator)

Example 4 with CoreProject

use of org.eclipse.persistence.core.sessions.CoreProject in project eclipselink by eclipse-ee4j.

the class MappingsGenerator method generateProject.

public CoreProject generateProject(List<JavaClass> typeInfoClasses, Map<String, TypeInfo> typeInfo, Map<String, QName> userDefinedSchemaTypes, Map<String, PackageInfo> packageToPackageInfoMappings, Map<QName, ElementDeclaration> globalElements, List<ElementDeclaration> localElements, Map<TypeMappingInfo, Class<?>> typeMappingInfoToGeneratedClass, Map<TypeMappingInfo, Class<?>> typeMappingInfoToAdapterClasses, boolean isDefaultNamespaceAllowed) throws Exception {
    this.typeInfo = typeInfo;
    this.userDefinedSchemaTypes = userDefinedSchemaTypes;
    this.packageToPackageInfoMappings = packageToPackageInfoMappings;
    this.isDefaultNamespaceAllowed = isDefaultNamespaceAllowed;
    this.globalElements = globalElements;
    this.localElements = localElements;
    this.typeMappingInfoToGeneratedClasses = typeMappingInfoToGeneratedClass;
    this.typeMappingInfoToAdapterClasses = typeMappingInfoToAdapterClasses;
    project = new Project();
    processDefaultNamespacePreferences(packageToPackageInfoMappings.values());
    // Generate descriptors
    for (JavaClass next : typeInfoClasses) {
        if (!next.isEnum()) {
            generateDescriptor(next, project);
        }
    }
    // Setup inheritance
    for (JavaClass next : typeInfoClasses) {
        if (!next.isEnum()) {
            setupInheritance(next);
        }
    }
    // Now create mappings
    generateMappings();
    // Setup AttributeGroups
    for (JavaClass next : typeInfoClasses) {
        setupAttributeGroups(next);
    }
    // apply customizers if necessary
    Set<Entry<String, TypeInfo>> entrySet = this.typeInfo.entrySet();
    for (Entry<String, TypeInfo> entry : entrySet) {
        TypeInfo tInfo = entry.getValue();
        if (tInfo.getXmlCustomizer() != null) {
            String customizerClassName = tInfo.getXmlCustomizer();
            try {
                Class<? extends DescriptorCustomizer> customizerClass = PrivilegedAccessHelper.getClassForName(customizerClassName, true, helper.getClassLoader());
                DescriptorCustomizer descriptorCustomizer = PrivilegedAccessHelper.newInstanceFromClass(customizerClass);
                descriptorCustomizer.customize((XMLDescriptor) tInfo.getDescriptor());
            } catch (ClassCastException cce) {
                throw JAXBException.invalidCustomizerClass(cce, customizerClassName);
            } catch (ReflectiveOperationException roe) {
                throw JAXBException.couldNotCreateCustomizerInstance(roe, customizerClassName);
            }
        }
    }
    processGlobalElements(project);
    return project;
}
Also used : Project(org.eclipse.persistence.sessions.Project) CoreProject(org.eclipse.persistence.core.sessions.CoreProject) Entry(java.util.Map.Entry) DescriptorCustomizer(org.eclipse.persistence.config.DescriptorCustomizer) JavaClass(org.eclipse.persistence.jaxb.javamodel.JavaClass)

Example 5 with CoreProject

use of org.eclipse.persistence.core.sessions.CoreProject in project eclipselink by eclipse-ee4j.

the class SessionEventTestCases method setupContext.

protected JAXBContext setupContext(Class<?>[] classesToBeBound, SessionEventListener sel) throws Exception {
    jakarta.xml.bind.JAXBContext jaxbContext = null;
    XMLContext xmlContext = null;
    JaxbClassLoader loader = new JaxbClassLoader(Thread.currentThread().getContextClassLoader());
    try {
        Generator generator = new Generator(new JavaModelInputImpl(classesToBeBound, new JavaModelImpl(loader)));
        CoreProject proj = generator.generateProject();
        ConversionManager conversionManager = null;
        conversionManager = new ConversionManager();
        conversionManager.setLoader(loader);
        proj.convertClassNamesToClasses(conversionManager.getLoader());
        for (Iterator<ClassDescriptor> descriptorIt = proj.getOrderedDescriptors().iterator(); descriptorIt.hasNext(); ) {
            ClassDescriptor descriptor = descriptorIt.next();
            if (descriptor.getJavaClass() == null) {
                descriptor.setJavaClass(conversionManager.convertClassNameToClass(descriptor.getJavaClassName()));
            }
        }
        xmlContext = new XMLContext((Project) proj, loader, sel);
        jaxbContext = new org.eclipse.persistence.jaxb.JAXBContext(xmlContext, generator, classesToBeBound);
    } catch (Exception ex) {
        throw ex;
    }
    return jaxbContext;
}
Also used : JAXBContext(jakarta.xml.bind.JAXBContext) JavaModelImpl(org.eclipse.persistence.jaxb.javamodel.reflection.JavaModelImpl) ClassDescriptor(org.eclipse.persistence.descriptors.ClassDescriptor) XMLContext(org.eclipse.persistence.oxm.XMLContext) JAXBException(jakarta.xml.bind.JAXBException) JavaModelInputImpl(org.eclipse.persistence.jaxb.javamodel.reflection.JavaModelInputImpl) CoreProject(org.eclipse.persistence.core.sessions.CoreProject) Project(org.eclipse.persistence.sessions.Project) CoreProject(org.eclipse.persistence.core.sessions.CoreProject) ConversionManager(org.eclipse.persistence.internal.helper.ConversionManager) JaxbClassLoader(org.eclipse.persistence.internal.jaxb.JaxbClassLoader) Generator(org.eclipse.persistence.jaxb.compiler.Generator)

Aggregations

CoreProject (org.eclipse.persistence.core.sessions.CoreProject)5 JaxbClassLoader (org.eclipse.persistence.internal.jaxb.JaxbClassLoader)3 Generator (org.eclipse.persistence.jaxb.compiler.Generator)3 JavaModelImpl (org.eclipse.persistence.jaxb.javamodel.reflection.JavaModelImpl)3 JavaModelInputImpl (org.eclipse.persistence.jaxb.javamodel.reflection.JavaModelInputImpl)3 JAXBException (jakarta.xml.bind.JAXBException)2 ClassDescriptor (org.eclipse.persistence.descriptors.ClassDescriptor)2 ConversionManager (org.eclipse.persistence.internal.helper.ConversionManager)2 JavaClass (org.eclipse.persistence.jaxb.javamodel.JavaClass)2 XMLContext (org.eclipse.persistence.oxm.XMLContext)2 Project (org.eclipse.persistence.sessions.Project)2 JAXBContext (jakarta.xml.bind.JAXBContext)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 Entry (java.util.Map.Entry)1 DescriptorCustomizer (org.eclipse.persistence.config.DescriptorCustomizer)1 Property (org.eclipse.persistence.jaxb.compiler.Property)1 TypeInfo (org.eclipse.persistence.jaxb.compiler.TypeInfo)1