"DataObject customerType = scope.getDataFactory().create(\"commonj.sdo\", \"Type\");\n"+
"customerType.set(\"uri\", \"http://example.com/customer\");\n"+
"customerType.set(\"name\", \"Customer\");");
DataObject customerType = scope.getDataFactory().create("commonj.sdo", "Type");
customerType.set("uri", "http://example.com/customer");
customerType.set("name", "Customer");
commentary("Now we can create a model for the Properties for the Type\n"+
"and set the name and Types of those Properties\n\n"+
"DataObject custNumProperty = customerType.createDataObject(\"property\");\n"+
"custNumProperty.set(\"name\", \"custNum\");\n"+
"custNumProperty.set(\"type\", intType);"
);
DataObject custNumProperty = customerType.createDataObject("property");
custNumProperty.set("name", "custNum");
custNumProperty.set("type", intType);
commentary("We continue in this manner until all the Types and their Properties are modelled");
DataObject lastNameProperty = customerType.createDataObject("property");
lastNameProperty.set("name", "lastName");
lastNameProperty.set("type", stringType);
DataObject firstNameProperty = customerType.createDataObject("property");
firstNameProperty.set("name", "firstName");
firstNameProperty.set("type", stringType);
commentary("Now that our type is fully modelled we submit the model to the TypeHelper\n"+
"The new Type instance is retuend to us, but is also available for lookup within\n"+
"the scope associated with the TypeHelper\n\n"+
"Type t = typeHelper.define(customerType);");
Type t = typeHelper.define(customerType);
commentary("Here we see the newly created Type being accessed via the TypeHelper\n"+
"along with a printout of the Type's Properties\n\n"+
"Type testType = scope.getTypeHelper().getType(\"http://example.com/customer\", \"Customer\");");
Type testType = scope.getTypeHelper().getType("http://example.com/customer", "Customer");
List props = testType.getProperties();
for (int i = 0; i < props.size(); i++) {
System.out.println(props.get(i));
}
commentary("Now we can create an instance of the type using the DataFactory associated with the type scope\n\n"+
"DataFactory factory = scope.getDataFactory();\n"+
"DataObject customer1 = factory.create(\"http://example.com/customer\", \"Customer\");");
DataFactory factory = scope.getDataFactory();
DataObject customer1 = factory.create("http://example.com/customer", "Customer");
customer1.setInt("custNum", 1);
customer1.set("firstName", "John");
customer1.set("lastName", "Adams");
commentary("Here's an XML String representing a DataObject we have created with the new type");
String xmlDocString = scope.getXMLHelper().save(customer1, CUSTOMER_NAMESPACE, "customer");
System.out.println(xmlDocString);