throw new javax.xml.bind.JAXBException(ex.getMessage(), ex);
}
}
private JAXBContextState createContextState(Generator generator, JaxbClassLoader loader, TypeMappingInfo[] typesToBeBound, Map properties) throws Exception {
CoreProject proj = generator.generateProject();
ConversionManager conversionManager = null;
if (classLoader != null) {
conversionManager = new ConversionManager();
conversionManager.setLoader(loader);
} else {
conversionManager = ConversionManager.getDefaultManager();
}
proj.convertClassNamesToClasses(conversionManager.getLoader());
// need to make sure that the java class is set properly on each
// descriptor when using java classname - req'd for JOT api implementation
for (Iterator<ClassDescriptor> descriptorIt = proj.getOrderedDescriptors().iterator(); descriptorIt.hasNext();) {
ClassDescriptor descriptor = descriptorIt.next();
if (descriptor.getJavaClass() == null) {
descriptor.setJavaClass(conversionManager.convertClassNameToClass(descriptor.getJavaClassName()));
}
}
XMLPlatform platform = new SAXPlatform();
platform.getConversionManager().setLoader(loader);
XMLContext xmlContext = new XMLContext((Project) proj, loader, sessionEventListeners());
((XMLLogin) xmlContext.getSession().getDatasourceLogin()).setEqualNamespaceResolvers(true);
JAXBContextState contextState = new JAXBContextState(xmlContext, generator, typesToBeBound, properties);
for (TypeMappingInfo typeMappingInfo : typesToBeBound) {
Type classToLookup = typeMappingInfo.getType();
if (contextState.getTypeMappingInfoToGeneratedType() != null && contextState.getTypeMappingInfoToGeneratedType().size() > 0) {
Class generatedClass = contextState.getTypeMappingInfoToGeneratedType().get(typeMappingInfo);
if (generatedClass != null) {
classToLookup = generatedClass;
}
}
if (classToLookup != null && classToLookup.getClass() == Class.class) {
Descriptor xmlDescriptor = (Descriptor) proj.getDescriptor((Class) classToLookup);
typeMappingInfo.setXmlDescriptor(xmlDescriptor);
}
}
return contextState;