use of org.eclipse.persistence.oxm.XMLContext in project eclipselink by eclipse-ee4j.
the class XMLChoiceCollectionWithGroupingElementTestCases method testReadDeploymentXML.
public void testReadDeploymentXML() {
try {
// Read the deploymentXML-file.xml back in with XMLProjectReader
Project newProject = XMLProjectReader.read(DEPLOYMENT_XML_RESOURCE, Thread.currentThread().getContextClassLoader());
XMLContext ctx = new XMLContext(newProject);
XMLUnmarshaller unmarshaller = ctx.createUnmarshaller();
InputStream instream = ClassLoader.getSystemResourceAsStream(XML_RESOURCE);
Employee emp = (Employee) unmarshaller.unmarshal(instream);
instream.close();
Object[] choices = emp.choice.toArray();
assertTrue("Choice collection did not unmarshal properly", (choices != null && choices.length > 0));
} catch (Exception x) {
x.printStackTrace();
fail("Deployment XML read test failed");
}
}
use of org.eclipse.persistence.oxm.XMLContext in project eclipselink by eclipse-ee4j.
the class XMLProjectReader method readObjectPersistenceRuntimeFormat.
/**
* Read a project in the format of an ObjectPersistenceRuntimeXMLProject.
* This could include a TopLink 11.1.1 project or a TopLink 10.1.3 project
*/
public static Project readObjectPersistenceRuntimeFormat(Document document, ClassLoader classLoader, Project opmProject) {
XMLLogin xmlLogin = new XMLLogin();
xmlLogin.setDatasourcePlatform(new org.eclipse.persistence.oxm.platform.DOMPlatform());
opmProject.setDatasourceLogin(xmlLogin);
// Create the OPM project.
if (classLoader != null) {
xmlLogin.getDatasourcePlatform().getConversionManager().setLoader(classLoader);
}
// Marshal OPM format.
XMLContext context = new XMLContext(opmProject);
context.getSession(Project.class).getEventManager().addListener(new MissingDescriptorListener());
XMLUnmarshaller unmarshaller = context.createUnmarshaller();
Project project = (Project) unmarshaller.unmarshal(document);
// Set the project's class loader.
if ((classLoader != null) && (project.getDatasourceLogin() != null)) {
project.getDatasourceLogin().getDatasourcePlatform().getConversionManager().setLoader(classLoader);
}
return project;
}
use of org.eclipse.persistence.oxm.XMLContext in project eclipselink by eclipse-ee4j.
the class XMLSessionConfigLoader method buildSessionConfigs.
private boolean buildSessionConfigs(SessionManager sessionManager, ClassLoader loader, Document document, Project project) {
// No errors occurred, unmasrshal the document which will return a
// SessionConfigs containing 0 or more SessionConfigs and send
// them through the factory to create actual Sessions
XMLContext context = new XMLContext(project);
XMLUnmarshaller unmarshaller = context.createUnmarshaller();
SessionConfigs configs = (SessionConfigs) unmarshaller.unmarshal(document);
SessionsFactory factory = new SessionsFactory();
Map<String, Session> sessions = factory.buildSessionConfigs(configs, loader);
for (Map.Entry<String, Session> entry : sessions.entrySet()) {
// Only add the session if missing.
if (!sessionManager.getSessions().containsKey(entry.getKey())) {
sessionManager.addSession(entry.getKey(), entry.getValue());
}
}
return true;
}
use of org.eclipse.persistence.oxm.XMLContext in project eclipselink by eclipse-ee4j.
the class XMLSessionConfigLoader method loadConfigsForMappingWorkbench.
/**
* INTERNAL:
* This method is to be used to load config objects for the Mapping Workbench
* only. Do not call this method.
*/
public SessionConfigs loadConfigsForMappingWorkbench(ClassLoader loader, boolean validate) {
Document document = loadDocument(loader, validate);
if (getExceptionStore().isEmpty()) {
if (document.getDocumentElement().getTagName().equals("sessions")) {
// No errors occurred, unmarshal the document which will return a
// SessionConfigs containing 0 or more SessionConfigs
XMLContext context = new XMLContext(getProject());
XMLUnmarshaller unmarshaller = context.createUnmarshaller();
return (SessionConfigs) unmarshaller.unmarshal(document);
} else {
// 9.0.4 session.xml or invalid xml format.
throw SessionLoaderException.InvalidSessionXML();
}
} else {
if (document.getDocumentElement().getTagName().equals("toplink-sessions")) {
// No errors occurred, unmarshal the document which will return a
// SessionConfigs containing 0 or more SessionConfigs
XMLContext context = new XMLContext(new XMLSessionConfigToplinkProject());
XMLUnmarshaller unmarshaller = context.createUnmarshaller();
return (SessionConfigs) unmarshaller.unmarshal(document);
} else {
// Throw the exceptions we encountered
throw SessionLoaderException.finalException(getExceptionStore());
}
}
}
use of org.eclipse.persistence.oxm.XMLContext in project eclipselink by eclipse-ee4j.
the class XMLMarshallerCreateTestCases method testInvalidMappingTypeRelational.
public void testInvalidMappingTypeRelational() {
Project project = new Project();
XMLDescriptor descriptor = new XMLDescriptor();
descriptor.setJavaClass(Car.class);
descriptor.setDefaultRootElement("test");
DirectToFieldMapping mapping = new DirectToFieldMapping();
mapping.setAttributeName("license");
mapping.setFieldName("license");
descriptor.addMapping(mapping);
project.addDescriptor(descriptor);
try {
XMLContext context = new XMLContext(project);
} catch (DescriptorException exception) {
assertTrue("An invalid mapping type exception should have been caught but wasn't.", exception.getErrorCode() == DescriptorException.INVALID_MAPPING_TYPE);
return;
} catch (IntegrityException exception) {
Vector exceptions = exception.getIntegrityChecker().getCaughtExceptions();
assertTrue("Too many exceptions were found...should have been 1.", exceptions.size() == 1);
Exception e = (Exception) exceptions.elementAt(0);
assertTrue("A DescriptorException should have been caught but wasn't.", e.getClass() == DescriptorException.class);
assertTrue("An invalid mapping type exception should have been caught but wasn't.", ((DescriptorException) e).getErrorCode() == DescriptorException.INVALID_MAPPING_TYPE);
return;
}
assertTrue("An invalid mapping type exception should have been caught but wasn't.", false);
}
Aggregations