use of org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContext in project eclipselink by eclipse-ee4j.
the class DynamicJAXBContextCreationTestCases method testCreateContextFromSessionsXMLString.
public void testCreateContextFromSessionsXMLString() throws JAXBException {
DynamicJAXBContext jaxbContext = DynamicJAXBContextFactory.createContext(SESSION_NAMES, null, null);
DynamicEntity docWrapper = jaxbContext.newDynamicEntity(DOCWRAPPER_CLASS_NAME);
assertNotNull(docWrapper);
}
use of org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContext in project eclipselink by eclipse-ee4j.
the class DynamicJAXBContextCreationTestCases method testNewInstanceOXM.
public void testNewInstanceOXM() throws JAXBException {
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
InputStream iStream = classLoader.getResourceAsStream(EXAMPLE_OXM);
if (iStream == null) {
fail("Couldn't load metadata file [" + EXAMPLE_OXM + "]");
}
HashMap<String, Source> metadataSourceMap = new HashMap<String, Source>();
metadataSourceMap.put("org.eclipse.persistence.testing.jaxb.dynamic", new StreamSource(iStream));
Map<String, Map<String, Source>> properties = new HashMap<String, Map<String, Source>>();
properties.put(JAXBContextProperties.OXM_METADATA_SOURCE, metadataSourceMap);
// Have to include a path to a jaxb.properties, so just reusing a context path that does contain one.
DynamicJAXBContext jaxbContext = (DynamicJAXBContext) JAXBContext.newInstance("org.eclipse.persistence.testing.jaxb.dynamic", classLoader, properties);
DynamicEntity person = jaxbContext.newDynamicEntity(PERSON_CLASS_NAME);
assertNotNull(person);
}
use of org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContext in project eclipselink by eclipse-ee4j.
the class DynamicJAXBContextCreationTestCases method testNewInstanceXSDImportError.
public void testNewInstanceXSDImportError() throws Exception {
// To use schema imports, schemas must be given as Sources
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
InputStream inputStream = ClassLoader.getSystemResourceAsStream(EXAMPLE_XSD);
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
docFactory.setNamespaceAware(true);
DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
Document xsdDocument = docBuilder.parse(inputStream);
Element xsdElement = xsdDocument.getDocumentElement();
Map<String, Object> properties = new HashMap<String, Object>();
properties.put(DynamicJAXBContextFactory.XML_SCHEMA_KEY, xsdElement);
CustomEntityResolver re = new CustomEntityResolver(false);
properties.put(DynamicJAXBContextFactory.ENTITY_RESOLVER_KEY, re);
JAXBException caughtEx = null;
try {
DynamicJAXBContext jaxbContext = (DynamicJAXBContext) JAXBContext.newInstance("org.eclipse.persistence.testing.jaxb.dynamic", classLoader, properties);
DynamicEntity person = jaxbContext.newDynamicEntity("mynamespace.Person");
assertNotNull("Could not create Dynamic Entity.", person);
DynamicEntity salary = jaxbContext.newDynamicEntity("banknamespace.CdnCurrency");
assertNotNull("Could not create Dynamic Entity.", salary);
} catch (JAXBException e) {
caughtEx = e;
} catch (Exception e) {
fail("Unexpected exception thrown. " + e);
}
org.eclipse.persistence.exceptions.JAXBException jEx = null;
Exception currentException = caughtEx;
// Walk the exception looking for an EclipseLink JAXBException
while (true) {
if (currentException instanceof JAXBException) {
Exception linkedEx = (Exception) ((JAXBException) currentException).getLinkedException();
if (linkedEx instanceof org.eclipse.persistence.exceptions.JAXBException) {
jEx = (org.eclipse.persistence.exceptions.JAXBException) linkedEx;
break;
} else {
currentException = linkedEx;
}
} else {
break;
}
}
if (jEx == null) {
fail("Unexpected exception thrown. " + caughtEx);
}
assertEquals("Unexpected EclipseLink exception thrown.", org.eclipse.persistence.exceptions.JAXBException.XSD_IMPORT_NOT_SOURCE, jEx.getErrorCode());
}
use of org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContext in project eclipselink by eclipse-ee4j.
the class DynamicWithStaticTestCases method getControlObject.
@Override
protected Object getControlObject() {
DynamicEntity employee = ((DynamicJAXBContext) jaxbContext).newDynamicEntity(PACKAGE + "." + "Customer");
DynamicEntity phone1 = ((DynamicJAXBContext) jaxbContext).newDynamicEntity(PACKAGE + "." + "PhoneNumber");
DynamicEntity phone2 = ((DynamicJAXBContext) jaxbContext).newDynamicEntity(PACKAGE + "." + "PhoneNumber");
phone1.set("value", "555-WORK");
phone1.set("type", "work");
phone2.set("value", "555-HOME");
phone2.set("type", "home");
ArrayList phones = new ArrayList();
phones.add(phone1);
phones.add(phone2);
employee.set("phoneNumber", phones);
Address address = new Address();
address.city = "Any Town";
address.street = "123 Some Street";
employee.set("address", address);
employee.set("name", "Jane Doe");
return employee;
}
Aggregations