use of org.eclipse.persistence.config.DescriptorCustomizer in project eclipselink by eclipse-ee4j.
the class EntityManagerSetupImpl method processDescriptorsFromCachedProject.
/**
* INTERNAL:
* This method is used to resolve Descriptor Customizers that might have been stored in the project
* for JPA project caching.
*/
private void processDescriptorsFromCachedProject(ClassLoader realClassLoader) throws ClassNotFoundException, PrivilegedActionException, IllegalAccessException, InstantiationException {
for (ClassDescriptor descriptor : session.getProject().getDescriptors().values()) {
// process customizers:
if (descriptor.getDescriptorCustomizerClassName() != null) {
Class<?> listenerClass = findClass(descriptor.getDescriptorCustomizerClassName(), realClassLoader);
DescriptorCustomizer customizer = (DescriptorCustomizer) buildObjectForClass(listenerClass, DescriptorCustomizer.class);
try {
customizer.customize(descriptor);
} catch (Exception e) {
session.getSessionLog().logThrowable(SessionLog.FINER, SessionLog.METADATA, e);
}
}
}
}
use of org.eclipse.persistence.config.DescriptorCustomizer 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.config.DescriptorCustomizer in project eclipselink by eclipse-ee4j.
the class EntityManagerSetupImpl method processDescriptorCustomizers.
protected void processDescriptorCustomizers(Map m, ClassLoader loader) {
Map customizerMap = PropertiesHandler.getPrefixValuesLogDebug(PersistenceUnitProperties.DESCRIPTOR_CUSTOMIZER_, m, session);
if (customizerMap.isEmpty()) {
return;
}
Iterator it = customizerMap.entrySet().iterator();
while (it.hasNext()) {
Map.Entry entry = (Map.Entry) it.next();
String name = (String) entry.getKey();
String customizerClassName = (String) entry.getValue();
ClassDescriptor descriptor = session.getDescriptorForAlias(name);
if (descriptor == null) {
try {
Class<?> javaClass = findClass(name, loader);
descriptor = session.getDescriptor(javaClass);
} catch (Exception ex) {
throw EntityManagerSetupException.failedWhileProcessingProperty(PersistenceUnitProperties.DESCRIPTOR_CUSTOMIZER_ + name, customizerClassName, ex);
}
}
if (descriptor != null) {
try {
Class<? extends DescriptorCustomizer> customizerClass = findClassForProperty(customizerClassName, PersistenceUnitProperties.DESCRIPTOR_CUSTOMIZER_ + name, loader);
DescriptorCustomizer customizer = customizerClass.getConstructor().newInstance();
customizer.customize(descriptor);
} catch (Exception ex) {
throw EntityManagerSetupException.failedWhileProcessingProperty(PersistenceUnitProperties.DESCRIPTOR_CUSTOMIZER_ + name, customizerClassName, ex);
}
} else {
// TODO throw a better error, missing descriptor for property.
throw EntityManagerSetupException.failedWhileProcessingProperty(PersistenceUnitProperties.DESCRIPTOR_CUSTOMIZER_ + name, customizerClassName, null);
}
}
}
Aggregations