Examples of TypeHelper


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

Examples of commonj.sdo.helper.TypeHelper

    /**
     * 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

Examples of commonj.sdo.helper.TypeHelper

    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

Examples of commonj.sdo.helper.TypeHelper

        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

Examples of commonj.sdo.helper.TypeHelper

        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

Examples of commonj.sdo.helper.TypeHelper

            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

Examples of org.eclipse.persistence.jpa.jpql.TypeHelper

  private void validateUpdateItemTypes(UpdateItem expression, IType type) {

    if (expression.hasNewValue()) {

      Expression newValue = expression.getNewValue();
      TypeHelper typeHelper = getTypeHelper();
      boolean nullValue = isNullValue(newValue);

      // A NULL value is ignored, except if the type is a primitive, null cannot be
      // assigned to a mapping of primitive type
      if (nullValue) {
        if (typeHelper.isPrimitiveType(type)) {
          addProblem(expression, UpdateItem_NullNotAssignableToPrimitive);
        }
        return;
      }

      IType newValueType = getType(newValue);

      if (!newValueType.isResolvable() ||
         typeHelper.isDateType(type)    && typeHelper.isDateType(newValueType) ||
         typeHelper.isNumericType(type) && typeHelper.isNumericType(newValueType)) {

        return;
      }

      // The new value's type can't be assigned to the item's type
View Full Code Here

Examples of org.eclipse.persistence.jpa.jpql.TypeHelper

    if (types1.length != types1.length) {
      return false;
    }

    TypeHelper typeHelper = getTypeHelper();

    for (int index = types1.length; --index >= 0; ) {

      // Convert a primitive to its Object type
      IType type1 = typeHelper.convertPrimitive(types1[index].getType());
      IType type2 = typeHelper.convertPrimitive(types2[index]);

      if (!type1.isAssignableTo(type2)) {
        return false;
      }
    }
View Full Code Here

Examples of org.eclipse.persistence.jpa.jpql.TypeHelper

    // 1. The types are the same
    // 2. The type cannot be determined, pretend they are equivalent,
    //    another rule will validate it
    // 3. One is assignable to the other one
    TypeHelper typeHelper = getTypeHelper();

    return (type1 == type2) ||
           !type1.isResolvable() ||
           !type2.isResolvable() ||
            typeHelper.isNumericType(type1) && typeHelper.isNumericType(type2) ||
            typeHelper.isDateType(type1)    && typeHelper.isDateType(type2)    ||
            type1.isAssignableTo(type2) ||
            type2.isAssignableTo(type1);
  }
View Full Code Here

Examples of org.eclipse.persistence.jpa.jpql.TypeHelper

    // another rule will validate it
    if (!type1.isResolvable() || !type2.isResolvable()) {
      return true;
    }

    TypeHelper typeHelper = getTypeHelper();

    if (type1 == type2) {
      return typeHelper.isNumericType(type1) ||
      typeHelper.isStringType(type1||
      typeHelper.isDateType(type1);
    }
    else {
      return typeHelper.isNumericType(type1) && typeHelper.isNumericType(type2) ||
             typeHelper.isStringType(type1&& typeHelper.isStringType(type2||
             typeHelper.isDateType(type1)    && typeHelper.isDateType(type2);
    }
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.