{
TypeHelper types = SDOUtil.createTypeHelper();
DataFactory factory = SDOUtil.createDataFactory(types);
XMLHelper xmlHelper = SDOUtil.createXMLHelper(types);
Type stringType = types.getType("commonj.sdo", "String");
Type decimalType = types.getType("commonj.sdo", "Decimal");
// Define a new open type - OpenQuote
DataObject openQuoteType = factory.create("commonj.sdo", "Type");
openQuoteType.set("uri", "http://www.example.com/open");
openQuoteType.set("name", "OpenQuote");
openQuoteType.set("open", Boolean.TRUE);
openQuoteType.setBoolean("open", true);
types.define(openQuoteType);
// Define new type - CompanyType
DataObject companyType = factory.create("commonj.sdo", "Type");
companyType.set("uri", "http://www.example.com/open");
companyType.set("name", "CompanyType");
// Create CompanyType property - "name"
DataObject nameProperty = companyType.createDataObject("property");
nameProperty.set("name", "name");
nameProperty.set("type", stringType);
nameProperty.set("containment", Boolean.TRUE);
types.define(companyType);
// Define a global type
DataObject globalType = factory.create("commonj.sdo", "Type");
globalType.set("uri", "http://www.example.com/open");
// Don't set the type's name - null is used for types containing global properties.
DataObject symbolProperty = globalType.createDataObject("property");
symbolProperty.set("name", "symbol");
symbolProperty.set("type", stringType);
symbolProperty.set("containment", Boolean.TRUE);
// Define a global property - company
DataObject companyProperty = globalType.createDataObject("property");
companyProperty.set("name", "company");
companyProperty.set("type", companyType);
companyProperty.set("containment", Boolean.TRUE);
// Define a global property - price
DataObject priceProperty = globalType.createDataObject("property");
priceProperty.set("name", "price");
priceProperty.set("type", decimalType);
types.define(globalType);
// Create DataObject instances
DataObject openQuote = factory.create("http://www.example.com/open", "OpenQuote");
assertTrue(openQuote.getType().isOpen());
// Get global type
Type definedGlobalType = types.getType("http://www.example.com/open", null);
Property definedSymbolProperty = definedGlobalType.getProperty("symbol");
openQuote.set(definedSymbolProperty, "s1");
Property definedCompanyProperty = definedGlobalType.getProperty("company");
DataObject company = openQuote.createDataObject(definedCompanyProperty);
company.setString("name", "FlyByNightTechnology");
Property definedPriceProperty = definedGlobalType.getProperty("price");
openQuote.setBigDecimal(definedPriceProperty, new BigDecimal("1000.0"));
assertEquals(definedPriceProperty.getType(), decimalType);
ByteArrayOutputStream baos = new ByteArrayOutputStream();