Package commonj.sdo.helper

Examples of commonj.sdo.helper.DataFactory


        Property property = xsdHelper.getGlobalProperty(elementQName.getNamespaceURI(), elementQName.getLocalPart(), true);
        if (null == property) {
            throw new InvocationRuntimeException("Type '" + elementQName.toString() + "' not found in registered SDO types.");
        }
        if (isWrapped) {
            DataFactory dataFactory = SDOUtil.createDataFactory(typeHelper);
            DataObject dataObject = dataFactory.create(property.getType());
            List ips = dataObject.getInstanceProperties();
            for (int i = 0; i < ips.size(); i++) {
                dataObject.set(i, os[i]);
            }
            return dataObject;
View Full Code Here


        "The DataFactory associated with the scope that the types were created within\n"
            + "can be used to create an instance of the Person Type\n\n"
            + "DataFactory dataFactory = scope.getDataFactory();\n"
            + "DataObject person1 = dataFactory.create(\"www.example.org/people\", \"Person\");");

    DataFactory dataFactory = scope.getDataFactory();
    DataObject person1 = dataFactory.create("www.example.org/people", "Person");

    commentary("The setString() of dataObject method is used to set the properties of the\n"
        + "new Person DataObject, including a unique identifier reference value\n"
        + "for the Person instance.\n\n"
        + "person1.setString(\"id\", \"1\");\n"
        + "person1.setString(\"name\", \"Joe Johnson Snr.\");\n"
        + "person1.setString(\"gender\", \"male\"););");

    person1.setString("id", "1");
    person1.setString("name", "Joe Johnson Snr.");
    person1.setString("gender", "male");

    commentary("An alternative approach to using the DataFactory directly to create\n"
        + "all DataObjects is to use a top-down approach,  where we create the\n"
        + "root object for a data graph,  and then use the createDataObject(String propertyName)\n"
        + "method to create the contained DataObjects.  Here we create the overall\n"
        + "medical test DataObject,  and then create the contained \"referrals\" DataObject\n\n"
        + "DataObject test = dataFactory.create(\"www.example.org/MedicalTest\", \"Test\");\n"
        + "DataObject referrals = test.createDataObject(\"referrals\");");

    DataObject test = dataFactory.create("www.example.org/MedicalTest", "Test");

    DataObject referrals = test.createDataObject("referrals");

    commentary("The default state for monitoring changes for da DataObject when created in this\n" +
        "way is thay monitoring is switched off, so we switch it on. (Note that if you\n" +
        "get your data graphs from a data Access Service then this service may turn on\n" +
        "change monitoring be default\n\n" +
        "test.getChangeSummary().beginLogging();");
    test.getChangeSummary().beginLogging();
   
    commentary("We'll repeat the whole of the MedicalScenario sample,  but then at the \n" +
        "last minute we'll decide it was all wrong and roll back the changes......");
   
    commentary("Now we can add the person we created earlier into the set of people who have\n"
        + "been referred for this medical test.\n\n"
        + "test.set(\"referrals\", referrals);\n"
        + "referrals.getList(\"person\").add(person1);");

    test.set("referrals", referrals);
    referrals.getList("person").add(person1);

    commentary("Let's take a look at how the current state of the data"
        + "graph is rendered in XML ...");

    System.out.println(scope.getXMLHelper().save(test,
        "www.example.org/MedicalTest", "test"));

    commentary("The scenario unfolds and the Joe Johnson Snr. becomes a patient\n\n"
        + "DataObject patients = test.createDataObject(\"patients\");\n"
        + "patients.getList(\"person\").add(person1);");

    DataObject patients = test.createDataObject("patients");

    patients.getList("person").add(person1);

    commentary("Having added Joe Johnson Snr. to the set of patients we can see\n"
        + "the way that SDO preserves a single containment hierarchy within a\n"
        + "datagraph.  If we look at the XML rendering of the graph again, we will\n"
        + "see that by adding him to the set of patients he has been removed from the\n"
        + "containment property associated with the referrals set ...");

    System.out.println(scope.getXMLHelper().save(test,
        "www.example.org/MedicalTest", "test"));

    commentary("The 'Person' Type we are making use of here has been designed to be\n"
        + "multi-purpose,  in that the type has been declared to be 'Open'.\n"
        + "That means that we can make use of 'Open Content' Properties\n"
        + "(If the type system has been defined using an XML schema\n"
        + "then these properties will derive from global elements)\n"
        + "We can look up open content Properties using the TypeHelper\n\n"
        + "Property conditionProperty = scope.getTypeHelper().getOpenContentProperty(\n"
        + "    \"www.example.org/MedicalTest\", \"condition\");");

    Property conditionProperty = scope.getTypeHelper().getOpenContentProperty(
        "www.example.org/MedicalTest", "condition");

    commentary("We can create a value of the appropriate Type for this open\n"
        + "content Property\n\n"
        + "DataObject condition = dataFactory.create(conditionProperty.getType());\n"
        + "condition.setString(\"name\", \"Panar Syndrome\");");

    DataObject condition = dataFactory.create(conditionProperty.getType());
    condition.setString("name", "Panar Syndrome");

    commentary("If you ask a DataObject that has an 'Open' Type for its list of\n"
        + "values associated with an open content Property, and the DataObject\n"
        + "doesn't currently have any values for the Property,  it will return\n"
View Full Code Here

            }           
        }
    }

    private void processRoot(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException {
        DataFactory dataFactory = aHelperContext.getDataFactory();
        SDOTypeHelper typeHelper = (SDOTypeHelper)aHelperContext.getTypeHelper();

        getXmlDocument().setRootElementName(localName);
        getXmlDocument().setRootElementURI(namespaceURI);
        Property rootElementProperty = aHelperContext.getXSDHelper().getGlobalProperty(namespaceURI, localName, true);
        Type rootObjectType = null;

        if (rootElementProperty != null) {
            rootObjectType = rootElementProperty.getType();
        } else {
            QName typeQName = getTypeAttributeQName(atts);
            if (typeQName != null) {
                String typeName = typeQName.getLocalPart();
                String typeUri = null;
                String prefix = typeQName.getPrefix();
                if (prefix == null) {
                    typeUri = null;
                } else {
                    Stack uriStack = (Stack)getNamespaceMap().get(prefix);
                    if(uriStack != null && uriStack.size() > 0) {
                        typeUri = (String)uriStack.peek();
                    }
                }
            rootObjectType = typeHelper.getType(typeUri, typeName);
            }           
        }

        DataObject rootObject = null;
        if (rootObjectType != null) {
            giveToOXToProcess(namespaceURI, localName, qName, atts, ((SDOType)rootObjectType).getXmlDescriptor());
            return;
        } else {
            Type rootType = aHelperContext.getTypeHelper().getType(SDOConstants.ORACLE_SDO_URL, "OpenSequencedType");
            rootObject = dataFactory.create(rootType);
        }
        currentDataObjects.push(rootObject);
        depth++;
        processAttributes(atts, rootObject, true);
View Full Code Here

 
  public void testDefineOpenType() throws Exception
  {
    TypeHelperImpl types = (TypeHelperImpl)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 open content property - company
    DataObject symbolProperty = factory.create("commonj.sdo", "Property");
    symbolProperty.set("name", "symbol");
    symbolProperty.set("type", stringType);
    types.defineOpenContentProperty("http://www.example.com/open", symbolProperty);

    // Define open content property - company
    DataObject companyProperty = factory.create("commonj.sdo", "Property");
    companyProperty.set("name", "company");
    companyProperty.set("type", companyType);
    companyProperty.set("containment", Boolean.TRUE);
    types.defineOpenContentProperty("http://www.example.com/open", companyProperty);
   
    // Define open content property - price
    DataObject priceProperty = factory.create("commonj.sdo", "Property");
    priceProperty.set("name", "price");
    priceProperty.set("type", decimalType);
    types.defineOpenContentProperty("http://www.example.com/open", priceProperty);
   
    // Create DataObject instances
    DataObject openQuote = factory.create("http://www.example.com/open", "OpenQuote");
    assertTrue(openQuote.getType().isOpen());
   
    Property definedSymbolProperty = types.getOpenContentProperty("http://www.example.com/open", "symbol");
    openQuote.set(definedSymbolProperty, "s1");
   
View Full Code Here

public class SerializeTypesTestCase extends TestCase {

    public void testSerializeTypesRoundTrip() throws Exception {
        TypeHelper types = SDOUtil.createTypeHelper();
        DataFactory factory = SDOUtil.createDataFactory(types);

        Type intType = types.getType("commonj.sdo", "Int");
        Type stringType = types.getType("commonj.sdo", "String");

        // create a new Type for Addresses
        DataObject addressType = factory.create("commonj.sdo", "Type");
        addressType.set("uri", "http://example.com/address");
        addressType.set("name", "Address");

        // create a address street property
        DataObject addrStProperty = addressType.createDataObject("property");
        addrStProperty.set("name", "addrSt");
        addrStProperty.set("type", stringType);

        // 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");
View Full Code Here

  private static final String MIXED_XML = "/mixed2.xml";
  private static final String MIXEDOPEN_XML = "/mixedopen.xml";
 
  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");
   
View Full Code Here

  }
 
  public void testDefineType() 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);

    // 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");
View Full Code Here

  }
 
  public void testDefineDataType() throws Exception
  {
    TypeHelper types = SDOUtil.createTypeHelper();
    DataFactory factory = SDOUtil.createDataFactory(types);
    XSDHelper xsdHelper = SDOUtil.createXSDHelper(types);
    XMLHelper xmlHelper = SDOUtil.createXMLHelper(types);

    Property javaClassProperty = xsdHelper.getGlobalProperty("commonj.sdo/java", "javaClass", false);
   
    // create a data types
    DataObject intType = factory.create("commonj.sdo", "Type");
    intType.set("uri", "http://example.com/customer");
    intType.set("name", "MyIntType");
    intType.setBoolean("dataType", true);
    intType.set(javaClassProperty, "int");
   
    DataObject stringType = factory.create("commonj.sdo", "Type");
    stringType.set("uri", "http://example.com/customer");
    stringType.set("name", "MyStringType");
    stringType.setBoolean("dataType", true);
    stringType.set(javaClassProperty, "java.lang.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);

    // 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");
   
View Full Code Here

  }
 
  public void testFastDefineType() 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
    Type customerType = SDOUtil.createType(types, "http://example.com/customer", "Customer", false);

    // create a customer number property
    SDOUtil.createProperty(customerType, "custNum", intType);

    // create a first name property
    SDOUtil.createProperty(customerType, "firstName", stringType);

    // create a last name property
    SDOUtil.createProperty(customerType, "lastName", stringType);

    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");
   
View Full Code Here

 
  public void testDefineSequencedType() throws Exception
  {
   
    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 mixed type - MixedQuote
    DataObject mixedQuoteType = factory.create("commonj.sdo", "Type");
    mixedQuoteType.set("uri", "http://www.example.com/mixed");
    mixedQuoteType.set("name", "MixedQuote");
    mixedQuoteType.set("sequenced", Boolean.TRUE);
   
    DataObject symbolProperty = mixedQuoteType.createDataObject("property");
    symbolProperty.set("name", "symbol");
    symbolProperty.set("type", stringType);
   
    DataObject companyNameProperty = mixedQuoteType.createDataObject("property");
    companyNameProperty.set("name", "companyName");
    companyNameProperty.set("type", stringType);
   
    DataObject priceProperty = mixedQuoteType.createDataObject("property");
    priceProperty.set("name", "price");
    priceProperty.set("type", decimalType);
   
    DataObject quotesProperty = mixedQuoteType.createDataObject("property");
    quotesProperty.set("name", "quotes");
    quotesProperty.set("type", mixedQuoteType);
    quotesProperty.set("many", Boolean.TRUE);
    quotesProperty.set("containment", Boolean.TRUE);
   
    types.define(mixedQuoteType);
   
    DataObject quote = factory.create("http://www.example.com/mixed", "MixedQuote");

    assertTrue(quote.getType().isSequenced());
   
    Sequence sequence = quote.getSequence();
View Full Code Here

TOP

Related Classes of commonj.sdo.helper.DataFactory

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.