use of org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContext in project eclipselink by eclipse-ee4j.
the class DynamicJAXBContextCreationTestCases method testCreateContextFromXSDNode.
/*
public void testCreateContextInputStreamInvalidSchema() throws Exception {
// 'createContextFromXSD' can catch some schema errors (e.g. undeclared namespace), but
// other more basic syntax problems (e.g. a "weak correctness check") will end up getting thrown
// as a SAXParseException and is uncatchable.
InputStream inputStream = ClassLoader.getSystemResourceAsStream(INVALID_XSD);
JAXBException caughtException = null;
try {
DynamicJAXBContextFactory.createContextFromXSD(inputStream, null, null, null);
} catch (JAXBException e) {
caughtException = e;
}
assertNotNull("Did not catch exception as expected.", caughtException);
assertEquals("Incorrect exception thrown.", 50046, ((org.eclipse.persistence.exceptions.JAXBException) caughtException.getLinkedException()).getErrorCode());
}
*/
public void testCreateContextFromXSDNode() throws Exception {
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();
DynamicJAXBContext jaxbContext = DynamicJAXBContextFactory.createContextFromXSD(xsdElement, null, null, null);
DynamicEntity emp = jaxbContext.newDynamicEntity(EMPLOYEE_CLASS_NAME);
assertNotNull(emp);
}
use of org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContext in project eclipselink by eclipse-ee4j.
the class DynamicJAXBContextCreationTestCases method testCreateContextFromXSDSource.
public void testCreateContextFromXSDSource() throws Exception {
InputStream inputStream = ClassLoader.getSystemResourceAsStream(EXAMPLE_XSD);
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
docFactory.setNamespaceAware(true);
Document xsdDocument = docFactory.newDocumentBuilder().parse(inputStream);
Source domSource = new DOMSource(xsdDocument);
DynamicJAXBContext jaxbContext = DynamicJAXBContextFactory.createContextFromXSD(domSource, null, null, null);
DynamicEntity emp = jaxbContext.newDynamicEntity(EMPLOYEE_CLASS_NAME);
assertNotNull(emp);
}
use of org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContext in project eclipselink by eclipse-ee4j.
the class DynamicJAXBContextCreationTestCases method testCreateContextFromXSDInputStream.
// ========================================================================
public void testCreateContextFromXSDInputStream() throws JAXBException {
InputStream inputStream = ClassLoader.getSystemResourceAsStream(EXAMPLE_XSD);
DynamicJAXBContext jaxbContext = DynamicJAXBContextFactory.createContextFromXSD(inputStream, null, null, null);
DynamicEntity emp = jaxbContext.newDynamicEntity(EMPLOYEE_CLASS_NAME);
assertNotNull(emp);
}
use of org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContext in project eclipselink by eclipse-ee4j.
the class DynamicWithStaticAddressNoPropsTestCases 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;
}
use of org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContext in project eclipselink by eclipse-ee4j.
the class DynamicWithStaticOverrideTestCases 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