Package commonj.sdo.helper

Examples of commonj.sdo.helper.TypeHelper


     * createDynamicallyWithStaticResources. The same XSD is used for the static
     * generation of SDO Types using XSD2JavaGenerator.
     */
    public static void createDynamically(HelperContext hc) {

        TypeHelper types = hc.getTypeHelper();
        Type stringType = types.getType("commonj.sdo", "String");
        Type intType = types.getType("commonj.sdo", "Int");
        Type booleanType = types.getType("commonj.sdo", "Boolean");
        Type byteType = types.getType("commonj.sdo", "Byte");
        Type decimalType = types.getType("commonj.sdo", "Decimal");
        Type floatType = types.getType("commonj.sdo", "Float");
        Type doubleType = types.getType("commonj.sdo", "Double");
        Type dateType = types.getType("commonj.sdo", "Date");
        Type shortType = types.getType("commonj.sdo", "Short");
        Type longType = types.getType("commonj.sdo", "Long");
        Type bytesType = types.getType("commonj.sdo", "Bytes");
        Type integerType = types.getType("commonj.sdo", "Integer");
        Type charType = types.getType("commonj.sdo", "Character");

        DataObject testType = hc.getDataFactory().create("commonj.sdo", "Type");
        testType.set("uri", TEST_URI);
        testType.set("name", TEST_TYPE_NAME);

        DataObject stringProperty = testType.createDataObject("property");
        stringProperty.set("name", "stringVal");
        stringProperty.set("type", stringType);

        DataObject booleanProperty = testType.createDataObject("property");
        booleanProperty.set("name", "booleanVal");
        booleanProperty.set("type", booleanType);

        DataObject byteProperty = testType.createDataObject("property");
        byteProperty.set("name", "byteVal");
        byteProperty.set("type", byteType);

        DataObject decimalProperty = testType.createDataObject("property");
        decimalProperty.set("name", "decimalVal");
        decimalProperty.set("type", decimalType);

        DataObject intProperty = testType.createDataObject("property");
        intProperty.set("name", "intVal");
        intProperty.set("type", intType);

        DataObject floatProperty = testType.createDataObject("property");
        floatProperty.set("name", "floatVal");
        floatProperty.set("type", floatType);

        DataObject doubleProperty = testType.createDataObject("property");
        doubleProperty.set("name", "doubleVal");
        doubleProperty.set("type", doubleType);

        DataObject dateProperty = testType.createDataObject("property");
        dateProperty.set("name", "dateVal");
        dateProperty.set("type", dateType);

        DataObject shortProperty = testType.createDataObject("property");
        shortProperty.set("name", "shortVal");
        shortProperty.set("type", shortType);

        DataObject longProperty = testType.createDataObject("property");
        longProperty.set("name", "longVal");
        longProperty.set("type", longType);

        DataObject childrenProperty = testType.createDataObject("property");
        childrenProperty.set("name", "listVal");
        childrenProperty.setBoolean("many", true);
        childrenProperty.set("type", stringType);

        DataObject bytesProperty = testType.createDataObject("property");
        bytesProperty.set("name", "bytesVal");
        bytesProperty.set("type", bytesType);

        DataObject integerProperty = testType.createDataObject("property");
        integerProperty.set("name", "integerVal");
        integerProperty.set("type", integerType);

        DataObject charProperty = testType.createDataObject("property");
        charProperty.set("name", "charVal");
        charProperty.set("type", charType);

        DataObject readOnlyProperty = testType.createDataObject("property");
        readOnlyProperty.set("name", "readOnlyVal");
        readOnlyProperty.set("type", stringType);
        readOnlyProperty.setBoolean("readOnly", true);

        DataObject readOnlyListProperty = testType.createDataObject("property");
        readOnlyListProperty.set("name", "readOnlyListVal");
        readOnlyListProperty.set("type", stringType);
        readOnlyListProperty.setBoolean("readOnly", true);
        readOnlyListProperty.setBoolean("many", true);

        types.define(testType);

        DataObject seqType = hc.getDataFactory().create("commonj.sdo", "Type");
        seqType.set("uri", TEST_URI);
        seqType.set("name", SEQ_TYPE_NAME);
        seqType.setBoolean("sequenced", true);

        DataObject seqROProperty = seqType.createDataObject("property");
        seqROProperty.set("name", "readOnlyVal");
        seqROProperty.set("type", stringType);
        seqROProperty.setBoolean("readOnly", true);

        DataObject seqROListProperty = seqType.createDataObject("property");
        seqROListProperty.set("name", "readOnlyListVal");
        seqROListProperty.set("type", stringType);
        seqROListProperty.setBoolean("readOnly", true);
        seqROListProperty.setBoolean("many", true);

        DataObject uniqueNameProperty = seqType.createDataObject("property");
        uniqueNameProperty.set("name", "uniqueName");
        uniqueNameProperty.set("type", stringType);

        types.define(seqType);
    }
View Full Code Here


    }
   
    public void testBytesEquality() {
        // Dynamically create a type
        HelperContext scope = HelperProvider.getDefaultContext();
        TypeHelper types = scope.getTypeHelper();
        Type BytesType = types.getType("commonj.sdo", "Bytes");
        DataObject customerType = DataFactory.INSTANCE.create("commonj.sdo", "Type");
        customerType.set("uri", "http://example.com/simple");
        customerType.set("name", "Simple");
        DataObject BytesProperty = customerType.createDataObject("property");
        BytesProperty.set("name", "BytesVal");
        BytesProperty.set("type", BytesType);
        types.define(customerType);
       
        // Create two instances
        DataObject obj1 = DataFactory.INSTANCE.create("http://example.com/simple", "Simple");
        DataObject obj2 = DataFactory.INSTANCE.create("http://example.com/simple", "Simple");
View Full Code Here

     * the static generation of SDO Types using XSD2JavaGenerator.
     */
    public Object createDynamically(HelperContext hc, boolean createDataObject)
    {
       
        TypeHelper types = hc.getTypeHelper();
        DataFactory dataFactory = hc.getDataFactory();
   
      Type stringType = types.getType("commonj.sdo", "String");
       
      DataObject testType = dataFactory.create("commonj.sdo", "Type");
      testType.set("uri", "http://www.example.com/api_test");
      testType.set("name", "APITest");
     
        DataObject stringProperty = testType.createDataObject("property");
        stringProperty.set("name", "stringVal");
        stringProperty.set("type", stringType);
       
          
        List types2Define = new ArrayList();
        types2Define.add(testType);
        List apiXSD = types.define(types2Define);
        Type apiXSDType = (Type) apiXSD.get(0);
       
        if(createDataObject)
            return dataFactory.create(apiXSDType);;
       
View Full Code Here

     * createDynamically() creates the SDO Types using the TypeHelper.  This method should be kept in
     * synch with the XSD used for createDynamicallyWithStaticResources.  The same XSD is used for
     * the static generation of SDO Types using XSD2JavaGenerator.
     */
    public static void createDynamically(HelperContext hc) {
        TypeHelper types = hc.getTypeHelper();
        Type stringType = types.getType("commonj.sdo", "String");

        DataObject testType = hc.getDataFactory().create("commonj.sdo", "Type");
        testType.set("uri", "http://www.example.com/ContainmentTest");
        testType.set("name", "ContainmentTest");
        testType.setBoolean("sequenced", true);

        DataObject nameProperty = testType.createDataObject("property");
        nameProperty.set("name", "Name");
        nameProperty.set("type", stringType);

        DataObject containProperty = testType.createDataObject("property");
        containProperty.set("name", "Contain");
        containProperty.setBoolean("containment", true);
        containProperty.set("type", testType);

        DataObject containManyProperty = testType.createDataObject("property");
        containManyProperty.set("name", "ContainMany");
        containManyProperty.setBoolean("many", true);
        containManyProperty.setBoolean("containment", true);
        containManyProperty.set("type", testType);

        types.define(testType);
    }
View Full Code Here

        super.setUp();
        hc = SDOUtil.createHelperContext();
    }
   
    public void testSerializeTypesRoundTrip() throws Exception {
        TypeHelper types = hc.getTypeHelper();
        DataFactory factory = hc.getDataFactory();

        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");
        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);

        // create an address property
        DataObject addressProperty = customerType.createDataObject("property");
        addressProperty.set("name", "address");
        addressProperty.set("type", addressType);
        addressProperty.setBoolean("containment", true);

        // now define the Address and Customer type so that addresses and customers can be made
        List types2define = new ArrayList();
        types2define.add(addressType);
        types2define.add(customerType);
        List typesDefined = types.define(types2define);

        // Create an empty data graph and add a root object, an instance of customerType
        //

        DataGraph dataGraph = SDOUtil.createDataGraph();
View Full Code Here

    }
  }
 
  public void testTypeRoundTrips() throws Exception {
    String URI = "commonj.sdo";
    TypeHelper types = TypeHelper.INSTANCE;
   
    List list = new ArrayList();
    list.add("foo");
    list.add("bar");
    list.add("test");
    Test[] tests = {
      new Test(types.getType(URI, "Boolean"),      "true", new Boolean(true)),
      new Test(types.getType(URI, "Byte"),         "49", new Byte((byte)49)),
      new Test(types.getType(URI, "Bytes"),        "666F6F", "foo", new BytesComparator()),
      new Test(types.getType(URI, "Character"),    "a", new Character('a')),
      new Test(types.getType(URI, "Date"),         "2005-12-12T12:12:12.012Z", DataHelper.INSTANCE.toDate("2005-12-12T12:12:12.012Z")),
      new Test(types.getType(URI, "DateTime"),     "2005-12-12T12:12:12zz", "2005-12-12T12:12:12zz"),
      new Test(types.getType(URI, "Day"),          "---12", "---12"),
      new Test(types.getType(URI, "Decimal"),      "12.12", new BigDecimal("12.12")),
      new Test(types.getType(URI, "Double"),       "12.12", new Double(12.12)),
      new Test(types.getType(URI, "Duration"),     "P5Y2M10D", "P5Y2M10D"),
      new Test(types.getType(URI, "Float"),        "12.12", new Float(12.12f)),
      new Test(types.getType(URI, "Int"),          "12", new Integer(12)),
      new Test(types.getType(URI, "Integer"),      "12", new BigInteger("12")),
      new Test(types.getType(URI, "Long"),         "12", new Long(12l)),
      new Test(types.getType(URI, "Month"),        "--12", "--12"),
      new Test(types.getType(URI, "MonthDay"),     "--12-12", "--12-12"),
      new Test(types.getType(URI, "Object"),       "test", "test"),
      new Test(types.getType(URI, "Short"),        "12", new Short((short)12)),
      new Test(types.getType(URI, "String"),       "test", "test"),
      new Test(types.getType(URI, "Strings"),      "foo bar test", list, new ListComparator()),
      new Test(types.getType(URI, "Time"),         "12:12:12.12", "12:12:12.12"),
      new Test(types.getType(URI, "URI"),          "http://example.org", "http://example.org"),
      new Test(types.getType(URI, "Year"),         "2005", "2005"),
      new Test(types.getType(URI, "YearMonth"),    "2005-12", "2005-12"),
      new Test(types.getType(URI, "YearMonthDay"), "2005-12-12", "2005-12-12")
    };
   
    for (int n = 0; n < tests.length; n++) {
      assertEquals(
        SDOUtil.convertToString(tests[n].type, SDOUtil.createFromString(tests[n].type, tests[n].value)),
View Full Code Here

    public DataGraph loadDataGraph(InputStream inputStream, Map options, HelperContext scope) throws IOException {
        if (scope == null) {
            scope = HelperProvider.getDefaultContext();
        }
        TypeHelper th = scope.getTypeHelper();
        DataGraph result = null;
    if (th == null || th == TypeHelper.INSTANCE) {
        result = loadDataGraph(inputStream, options);
    } else if (options == null) {
        options = new HashMap();
View Full Code Here

      }
  }
 
  public void testEncoding() throws IOException
  {
      TypeHelper types = hc.getTypeHelper();
      Type stringType = types.getType("commonj.sdo", "String");
      DataObject customerType = hc.getDataFactory().create("commonj.sdo", "Type");
      customerType.set("uri", "http://example.com/simple");
      customerType.set("name", "Simple");
      DataObject multiProperty = customerType.createDataObject("property");
      multiProperty.set("name", "name");
      multiProperty.set("type", stringType);
      types.define(customerType);
      DataObject obj = hc.getDataFactory().create("http://example.com/simple",
      "Simple");
      obj.set("name", "John Smith");
     
      ByteArrayOutputStream baos = new ByteArrayOutputStream();
View Full Code Here

    super.setUp();
    hc = SDOUtil.createHelperContext();
  }

  public void testDefineTypeRoundTrip() throws Exception {
    TypeHelper types = hc.getTypeHelper();
    DataFactory factory = hc.getDataFactory();
    XMLHelper xmlHelper = hc.getXMLHelper();

    Type intType = types.getType("commonj.sdo", "Int");
    Type stringType = types.getType("commonj.sdo", "String");
   
    Property xmlElementProp = hc.getXSDHelper().getGlobalProperty("commonj.sdo/xml", "xmlElement", false);
   
    // 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 as an XSD attribute
    DataObject custNumProperty = customerType.createDataObject("property");
    custNumProperty.set("name", "custNum");
    custNumProperty.set("type", intType);
    custNumProperty.setBoolean(xmlElementProp, false);
    
    // create a first name property as an XSD attribute
    DataObject firstNameProperty =
    customerType.createDataObject("property");
    firstNameProperty.set("name", "firstName");
    firstNameProperty.set("type", stringType);
    firstNameProperty.setBoolean(xmlElementProp, false);

    // create a last name property as an XSD attribute
    DataObject lastNameProperty = customerType.createDataObject("property");
    lastNameProperty.set("name", "lastName");
    lastNameProperty.set("type", stringType);
    lastNameProperty.setBoolean(xmlElementProp, false);

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

          getClass().getResource(CUSTOMER2_XML)));
  }
 
  public void testDefineType() throws Exception
  {
    TypeHelper types = hc.getTypeHelper();
    DataFactory factory = hc.getDataFactory();
    XMLHelper xmlHelper = hc.getXMLHelper();

    Type intType = types.getType("commonj.sdo", "Int");
    Type stringType = types.getType("commonj.sdo", "String");
   
    Property xmlElementProp = hc.getXSDHelper().getGlobalProperty("commonj.sdo/xml", "xmlElement", false);
   
    // 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);
    custNumProperty.setBoolean(xmlElementProp, false);

    // create a first name property
    DataObject firstNameProperty =
    customerType.createDataObject("property");
    firstNameProperty.set("name", "firstName");
    firstNameProperty.set("type", stringType);
    firstNameProperty.setBoolean(xmlElementProp, false);

    // create a last name property
    DataObject lastNameProperty = customerType.createDataObject("property");
    lastNameProperty.set("name", "lastName");
    lastNameProperty.set("type", stringType);
    lastNameProperty.setBoolean(xmlElementProp, false);

    // 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", 0);
    assertTrue(customer1.isSet("custNum"));

    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);
    assertNotNull(types.getOpenContentProperty("http://example.com/customer", "customer"));

    type = customer2.getType();
    assertNotNull(type.getProperty("custNum"));
    assertNotNull(type.getProperty("firstName"));
    assertNotNull(type.getProperty("lastName"));
View Full Code Here

TOP

Related Classes of commonj.sdo.helper.TypeHelper

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.