Package commonj.sdo.helper

Examples of commonj.sdo.helper.TypeHelper


import commonj.sdo.helper.TypeHelper;

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");
        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();
        Type customerTypeDefined = (Type) typesDefined.get(1);
        DataObject customer1 = dataGraph.createRootObject(customerTypeDefined);

        customer1.setInt("custNum", 1);
        customer1.set("firstName", "John");
        customer1.set("lastName", "Adams");
        DataObject address = customer1.createDataObject("address");
        address.set("addrSt", "577 Airport Blvd");

        SDOUtil.registerDataGraphTypes(dataGraph, typesDefined);

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        SDOUtil.saveDataGraph(dataGraph, baos, null);
        //SDOUtil.saveDataGraph(dataGraph, System.out, null);

        TypeHelper deserializingTypeHelper = SDOUtil.createTypeHelper();
       
        // The following is a kludge to force deserialization of metadata into a different TypeHelper (scope)
        // TBD figure out a proper non-EMF way to do this.
        Map options = new HashMap();
        Object differentFromSerializing = ((TypeHelperImpl) deserializingTypeHelper).getExtendedMetaData();
View Full Code Here


    /**
     * Method dynamically defines customer types
     */
    public static void defineCustomerTypes() {
        // get an instance of the type helper
        TypeHelper types = TypeHelper.INSTANCE;
        Type intType = types.getType("commonj.sdo", "Int");
        Type stringType = types.getType("commonj.sdo", "String");

        // create a new Type for Customers
        DataObject customerType = DataFactory.INSTANCE.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 last name property
        DataObject lastNameProperty = customerType.createDataObject("property");
        lastNameProperty.set("name", "lastName");
        lastNameProperty.set("type", stringType);

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

        // now define the Customer type so that customers can be made
        types.define(customerType);

        Type testType = TypeHelper.INSTANCE.getType("http://example.com/customer", "Customer");
        List props = testType.getProperties();
        for (int i = 0; i < props.size(); i++) {
            System.out.println(props.get(i));
View Full Code Here

    return list;
  }
 
  protected static Property demandOpenProperty(Type type, String name, Object value, boolean isSequence)
  {
    TypeHelper typeHelper = TypeHelper.INSTANCE; //FB TODO: what TypeHelper to use?
   
    String uri = type.getURI() + "/" + type.getName(); // unique URI for open content properties on instances of the type
    Property property = typeHelper.getOpenContentProperty(uri, name);
    if (property != null)
      return property;

    boolean isMany = isSequence;
    boolean isContainment = false;
    Type propertyType;
   
    if (value instanceof DataObject)
    {
      DataObject dataObject = (DataObject)value;
      propertyType = dataObject.getType();
      isContainment = dataObject.getContainer() == null;
    }
    else if (value instanceof List && !((List)value).isEmpty())
    {
      Object listValue = ((List)value).get(0); //TODO: get common base class if all values are not the same type?
      if (listValue instanceof DataObject)
        propertyType = ((DataObject)listValue).getType();
      else
        propertyType = typeHelper.getType(listValue.getClass());
      isMany = true;
    }
    else
    {
      propertyType = typeHelper.getType(value.getClass());
    }
    if (propertyType == null)
    {
      propertyType = ((ModelFactoryImpl)ModelFactory.INSTANCE).getObject();
    }
View Full Code Here

        Type type = null;
        if (URI_2001_SCHEMA_XSD.equals(typeName.getNamespaceURI())) {
            type = SDOUtil.getXSDSDOType(typeName.getLocalPart());
        } else {
            HelperContext helperContext = SDOContextHelper.getHelperContext(context, false);
            TypeHelper typeHelper = helperContext.getTypeHelper();
            type = typeHelper.getType(typeName.getNamespaceURI(), typeName.getLocalPart());
        }
        return SDOUtil.createFromString(type, value);
    }
View Full Code Here

        Type type = null;
        if (URI_2001_SCHEMA_XSD.equals(typeName.getNamespaceURI())) {
            type = SDOUtil.getXSDSDOType(typeName.getLocalPart());
        } else {
            HelperContext helperContext = SDOContextHelper.getHelperContext(context, true);
            TypeHelper typeHelper = helperContext.getTypeHelper();
            type = typeHelper.getType(typeName.getNamespaceURI(), typeName.getLocalPart());
        }
        return SDOUtil.convertToString(type, obj);
    }
View Full Code Here

            return SDODataBinding.ROOT_ELEMENT;
        }
    }

    public static String generateSchema(HelperContext context, Class<?>[] classes) {
        TypeHelper typeHelper = context.getTypeHelper();
        List<Type> types = new ArrayList<Type>();
        for (Class<?> cls : classes) {
            Type type = typeHelper.getType(cls);
            if (type != null) {
                types.add(type);
            }
        }
        return generateSchema(context, types);
View Full Code Here

        URL url = getClass().getResource("/ipo.xsd");
        Assert.assertNotNull(url);
        InputStream is = url.openStream();
        XSDHelper xsdHelper = context.getXSDHelper();
        xsdHelper.define(is, url.toExternalForm());
        TypeHelper typeHelper = context.getTypeHelper();
        Type type = typeHelper.getType("http://www.example.com/IPO", "PurchaseOrderType");
        Assert.assertNotNull(type);
        /*
        SDOContextHelper.generateSchema(context, Arrays.asList(type));
        */
    }
View Full Code Here

            return SDODataBinding.ROOT_ELEMENT;
        }
    }

    public static String generateSchema(HelperContext context, Class<?>[] classes) {
        TypeHelper typeHelper = context.getTypeHelper();
        List<Type> types = new ArrayList<Type>();
        for (Class<?> cls : classes) {
            Type type = typeHelper.getType(cls);
            if (type != null) {
                types.add(type);
            }
        }
        return generateSchema(context, types);
View Full Code Here

        Type type = null;
        if (URI_2001_SCHEMA_XSD.equals(typeName.getNamespaceURI())) {
            type = SDOUtil.getXSDSDOType(typeName.getLocalPart());
        } else {
            HelperContext helperContext = SDOContextHelper.getHelperContext(context, false);
            TypeHelper typeHelper = helperContext.getTypeHelper();
            type = typeHelper.getType(typeName.getNamespaceURI(), typeName.getLocalPart());
        }
        return SDOUtil.createFromString(type, value);
    }
View Full Code Here

        Type type = null;
        if (URI_2001_SCHEMA_XSD.equals(typeName.getNamespaceURI())) {
            type = SDOUtil.getXSDSDOType(typeName.getLocalPart());
        } else {
            HelperContext helperContext = SDOContextHelper.getHelperContext(context, true);
            TypeHelper typeHelper = helperContext.getTypeHelper();
            type = typeHelper.getType(typeName.getNamespaceURI(), typeName.getLocalPart());
        }
        return SDOUtil.convertToString(type, obj);
    }
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.