public void testDefineTypeRoundTrip() throws Exception {
TypeHelper types = SDOUtil.createTypeHelper();
DataFactory factory = SDOUtil.createDataFactory(types);
XMLHelper xmlHelper = SDOUtil.createXMLHelper(types);
Type intType = types.getType("commonj.sdo", "Int");
Type stringType = types.getType("commonj.sdo", "String");
// create a new Type for Customers
DataObject customerType = factory.create("commonj.sdo",
"Type");
customerType.set("uri", "http://example.com/customer");
customerType.set("name", "Customer");
// create a customer number property
DataObject custNumProperty = customerType.createDataObject("property");
custNumProperty.set("name", "custNum");
custNumProperty.set("type", intType);
// create a first name property
DataObject firstNameProperty =
customerType.createDataObject("property");
firstNameProperty.set("name", "firstName");
firstNameProperty.set("type", stringType);
// create a last name property
DataObject lastNameProperty = customerType.createDataObject("property");
lastNameProperty.set("name", "lastName");
lastNameProperty.set("type", stringType);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
xmlHelper.save(customerType, "commonj.sdo", "type", baos);
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
XMLDocument xdoc = xmlHelper.load(bais);
customerType = xdoc.getRootObject();
// now define the Customer type so that customers can be made
types.define(customerType);
DataObject customer1 = factory.create("http://example.com/customer",
"Customer");
customer1.setInt("custNum", 1);
customer1.set("firstName", "John");
customer1.set("lastName", "Adams");
DataObject customer2 = factory.create("http://example.com/customer",
"Customer");
customer2.setInt("custNum", 2);
customer2.set("firstName", "Jeremy");
customer2.set("lastName", "Pavick");
assertNotNull(customer1);
Type type = customer1.getType();
assertNotNull(type.getProperty("custNum"));
assertNotNull(type.getProperty("firstName"));
assertNotNull(type.getProperty("lastName"));
assertEquals(type.getProperty("custNum").getType(), intType);
assertEquals(type.getProperty("firstName").getType(), stringType);
assertEquals(type.getProperty("lastName").getType(), stringType);
assertNotNull(customer2);
type = customer2.getType();
assertNotNull(type.getProperty("custNum"));
assertNotNull(type.getProperty("firstName"));
assertNotNull(type.getProperty("lastName"));
assertEquals(type.getProperty("custNum").getType(), intType);
assertEquals(type.getProperty("firstName").getType(), stringType);
assertEquals(type.getProperty("lastName").getType(), stringType);
baos = new ByteArrayOutputStream();
xmlHelper.save(
customer1,
"http://example.com/customer",