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());
}
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;
}
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;
}
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;
}
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;
}
Aggregations