Exemplo n.º 1
0
 protected SDOType(SDOTypeHelper sdoTypeHelper, XMLDescriptor xmlDescriptor) {
   this.xmlDescriptor = xmlDescriptor;
   if (null != sdoTypeHelper) {
     aHelperContext = sdoTypeHelper.getHelperContext();
     if (null != xmlDescriptor) {
       this.xmlDescriptor.setNamespaceResolver(sdoTypeHelper.getNamespaceResolver());
     }
   }
 }
  public SDOType getRootSDOType() {
    SDOType type = new SDOType("http://testing", "myRoot");
    type.setOpen(true);
    type.setAbstract(false);
    SDOProperty prop = new SDOProperty(aHelperContext);
    prop.setName("name");
    prop.setType(SDOConstants.SDO_STRING);
    prop.setContainingType(type);
    type.addDeclaredProperty(prop);

    SDOProperty prop2 = new SDOProperty(aHelperContext);
    prop2.setName("child");
    prop2.setType(typeHelper.getType("http://testing", "firstChildType"));
    prop2.setContainment(true);
    prop2.setContainingType(type);
    type.addDeclaredProperty(prop2);

    SDOProperty prop3 = new SDOProperty(aHelperContext);
    prop3.setName("child2");
    prop3.setType(typeHelper.getType("http://testing", "firstChildType"));
    prop3.setContainment(true);
    prop3.setContainingType(type);
    type.addDeclaredProperty(prop3);

    SDOProperty prop4 = new SDOProperty(aHelperContext);
    prop4.setName("nullTypeProp");
    // we were omitting setting the Type on purpose here - we don't need it - just add anything
    prop4.setType(SDOConstants.SDO_BOOLEAN);

    prop4.setContainingType(type);
    type.addDeclaredProperty(prop4);

    ((SDOTypeHelper) typeHelper).addType(type);
    return type;
  }
  public DataObject create(Type type) {
    if (type == null) {
      throw new IllegalArgumentException(
          SDOException.cannotPerformOperationWithNullInputParameter("create", "type"));
    }
    SDOType sdoType = (SDOType) type;

    if (sdoType.isAbstract()) {
      // throw illegal arg exception
      // spec page 40
      throw new IllegalArgumentException(
          SDOException.errorCreatingDataObjectForType(sdoType.getURI(), sdoType.getName()));
    }

    if (sdoType.isDataType()) {
      SDOTypeHelper sth = (SDOTypeHelper) getHelperContext().getTypeHelper();
      sdoType = (SDOType) sth.getWrappersHashMap().get(sdoType.getQName());
    }

    Class implClass;
    try {
      implClass = sdoType.getImplClass();
      if (implClass != null) {
        // initialization of the properties Map Implementation will be done in the default
        // constructor call below
        // testcase is in org.apache.tuscany.sdo.test
        SDODataObject theDataObject = (SDODataObject) implClass.newInstance();
        theDataObject._setType(sdoType);
        theDataObject._setHelperContext(getHelperContext());
        return theDataObject;
      }
    } catch (InstantiationException e) {
      throw new IllegalArgumentException(
          SDOException.errorCreatingDataObjectForClass(
              e, (sdoType).getInstanceClassName(), sdoType.getURI(), sdoType.getName()));
    } catch (IllegalAccessException e) {
      throw new IllegalArgumentException(
          SDOException.errorCreatingDataObjectForClass(
              e, (sdoType).getInstanceClassName(), sdoType.getURI(), sdoType.getName()));
    }
    SDODataObject dataObject = new SDODataObject();
    dataObject._setType(sdoType);
    dataObject._setHelperContext(getHelperContext());
    return dataObject;
  }
  public Project getTopLinkProject() {
    if (topLinkProject == null) {
      topLinkProject = new Project();
      XMLLogin xmlLogin = new XMLLogin();
      xmlLogin.setEqualNamespaceResolvers(false);
      topLinkProject.setDatasourceLogin(xmlLogin);
      // 200606_changeSummary
      NamespaceResolver nr = new NamespaceResolver();
      SDOTypeHelper sdoTypeHelper = (SDOTypeHelper) aHelperContext.getTypeHelper();
      String sdoPrefix = sdoTypeHelper.getPrefix(SDOConstants.SDO_URL);
      nr.put(sdoPrefix, SDOConstants.SDO_URL);
      SDOType changeSummaryType =
          (SDOType) sdoTypeHelper.getType(SDOConstants.SDO_URL, SDOConstants.CHANGESUMMARY);
      changeSummaryType.getXmlDescriptor().setNamespaceResolver(nr);
      topLinkProject.addDescriptor(changeSummaryType.getXmlDescriptor());
      SDOType openSequencedType =
          (SDOType)
              aHelperContext
                  .getTypeHelper()
                  .getType(SDOConstants.ORACLE_SDO_URL, "OpenSequencedType");
      topLinkProject.addDescriptor(openSequencedType.getXmlDescriptor());
      SDOTypeType typeType =
          (SDOTypeType)
              aHelperContext.getTypeHelper().getType(SDOConstants.SDO_URL, SDOConstants.TYPE);
      typeType.getXmlDescriptor().setNamespaceResolver(nr);
      if (!typeType.isInitialized()) {
        typeType.initializeMappings();
      }
      topLinkProject.addDescriptor(typeType.getXmlDescriptor());
      SDOPropertyType propertyType =
          (SDOPropertyType)
              aHelperContext.getTypeHelper().getType(SDOConstants.SDO_URL, SDOConstants.PROPERTY);
      if (!propertyType.isInitialized()) {
        propertyType.initializeMappings();
      }
      topLinkProject.addDescriptor(propertyType.getXmlDescriptor());

      ((SDOTypeHelper) aHelperContext.getTypeHelper()).addWrappersToProject(topLinkProject);
    }
    return topLinkProject;
  }
  public SDOType getFirstChildType() {
    SDOType type = new SDOType("http://testing", "firstChildType");
    type.setOpen(true);
    type.setAbstract(false);

    SDOProperty prop = new SDOProperty(aHelperContext);
    prop.setName("name");
    prop.setType(SDOConstants.SDO_STRING);
    prop.setContainingType(type);
    type.addDeclaredProperty(prop);

    SDOProperty prop2 = new SDOProperty(aHelperContext);
    prop2.setName("child");
    prop2.setType(typeHelper.getType("http://testing", "secondChildType"));
    prop2.setContainment(true);
    prop2.setContainingType(type);
    type.addDeclaredProperty(prop2);

    ((SDOTypeHelper) typeHelper).addType(type);
    return type;
  }
  public List<Type> getControlTypes() {
    List<Type> types = new ArrayList<Type>();
    ((SDOTypeHelper) typeHelper).reset();

    DataObject phoneTypeDO = dataFactory.create("commonj.sdo", "Type");
    phoneTypeDO.set("uri", "my.uri");
    phoneTypeDO.set("name", "phoneType");
    phoneTypeDO.set("sequenced", true);
    DataObject areaCodeProp = addProperty(phoneTypeDO, "areaCode", SDOConstants.SDO_STRING);
    DataObject numberProp = addProperty(phoneTypeDO, "number", SDOConstants.SDO_OBJECT);
    numberProp.set("many", true);
    Type phoneType = typeHelper.define(phoneTypeDO);
    ((SDOProperty) phoneType.getProperty("areaCode")).setXsd(true);
    ((SDOProperty) phoneType.getProperty("areaCode")).setContainment(true);
    ((SDOProperty) phoneType.getProperty("areaCode")).setXsdLocalName("areaCode");
    ((SDOProperty) phoneType.getProperty("number")).setXsd(true);
    ((SDOProperty) phoneType.getProperty("number")).setContainment(true);
    ((SDOProperty) phoneType.getProperty("number")).setXsdLocalName("number");

    DataObject personTypeDO = dataFactory.create("commonj.sdo", "Type");
    personTypeDO.set("uri", "my.uri");
    personTypeDO.set("name", "personType");
    personTypeDO.set("sequenced", true);
    addProperty(personTypeDO, "age", SDOConstants.SDO_STRING);
    DataObject nameProp = addProperty(personTypeDO, "name", SDOConstants.SDO_OBJECT);
    nameProp.set("many", true);
    Type personType = typeHelper.define(personTypeDO);
    ((SDOProperty) personType.getProperty("age")).setXsd(true);
    ((SDOProperty) personType.getProperty("age")).setContainment(true);
    ((SDOProperty) personType.getProperty("age")).setXsdLocalName("age");
    ((SDOProperty) personType.getProperty("name")).setXsd(true);
    ((SDOProperty) personType.getProperty("name")).setContainment(true);
    ((SDOProperty) personType.getProperty("name")).setXsdLocalName("name");

    DataObject jobTypeDO = dataFactory.create("commonj.sdo", "Type");
    jobTypeDO.set("uri", "my.uri");
    jobTypeDO.set("name", "jobType");
    jobTypeDO.set("sequenced", true);
    DataObject titleProp = addProperty(jobTypeDO, "title", SDOConstants.SDO_OBJECT);
    titleProp.set("many", true);
    Type jobType = typeHelper.define(jobTypeDO);
    ((SDOProperty) jobType.getProperty("title")).setXsd(true);
    ((SDOProperty) jobType.getProperty("title")).setContainment(true);
    ((SDOProperty) jobType.getProperty("title")).setXsdLocalName("title");

    DataObject contactTypeDO = dataFactory.create("commonj.sdo", "Type");
    contactTypeDO.set("uri", "my.uri");
    contactTypeDO.set("name", "contactType");
    contactTypeDO.set("sequenced", true);
    DataObject streetProp = addProperty(contactTypeDO, "street", SDOConstants.SDO_OBJECT);
    streetProp.set("many", true);
    Type contactType = typeHelper.define(contactTypeDO);
    ((SDOProperty) contactType.getProperty("street")).setXsd(true);
    ((SDOProperty) contactType.getProperty("street")).setContainment(true);
    ((SDOProperty) contactType.getProperty("street")).setXsdLocalName("street");

    DataObject addressTypeDO = dataFactory.create("commonj.sdo", "Type");
    addressTypeDO.set("uri", "my.uri");
    addressTypeDO.set("name", "addressType");
    addressTypeDO.set("sequenced", true);
    List baseTypes = new ArrayList();
    baseTypes.add(contactType);
    addressTypeDO.set("baseType", baseTypes);
    DataObject cityProp = addProperty(addressTypeDO, "city", SDOConstants.SDO_STRING);
    Type addressType = typeHelper.define(addressTypeDO);
    ((SDOProperty) addressType.getProperty("city")).setXsd(true);
    ((SDOProperty) addressType.getProperty("city")).setContainment(true);
    ((SDOProperty) addressType.getProperty("city")).setXsdLocalName("city");

    DataObject cdnAddressTypeDO = dataFactory.create("commonj.sdo", "Type");
    cdnAddressTypeDO.set("uri", "my.uri");
    cdnAddressTypeDO.set("name", "cdnAddressType");
    cdnAddressTypeDO.set("sequenced", true);
    baseTypes = new ArrayList();
    baseTypes.add(addressType);
    cdnAddressTypeDO.set("baseType", baseTypes);
    DataObject postalCodeProp =
        addProperty(cdnAddressTypeDO, "postalCode", SDOConstants.SDO_STRING);
    Type cdnAddressType = typeHelper.define(cdnAddressTypeDO);
    ((SDOProperty) cdnAddressType.getProperty("postalCode")).setXsd(true);
    ((SDOProperty) cdnAddressType.getProperty("postalCode")).setContainment(true);
    ((SDOProperty) cdnAddressType.getProperty("postalCode")).setXsdLocalName("postalCode");

    types.add(personType);
    types.add(jobType);
    types.add(addressType);
    types.add(contactType);
    types.add(cdnAddressType);
    types.add(phoneType);

    return types;
  }
  public List getControlTypes() {
    SDOType changeSummaryType =
        (SDOType)
            aHelperContext
                .getTypeHelper()
                .getType(SDOConstants.SDO_URL, SDOConstants.CHANGESUMMARY);

    List<Type> types = new ArrayList<Type>();
    ((SDOTypeHelper) typeHelper).reset();
    // String xsdSchema =
    // getSchema("org/eclipse/persistence/testing/sdo/schemas/PurchaseOrderComplexSequenced.xsd");
    // List types = xsdHelper.define(xsdSchema);
    DataObject addressTypeDO = dataFactory.create("commonj.sdo", "Type");
    addressTypeDO.set("uri", NON_DEFAULT_URI);
    addressTypeDO.set("name", "AddressType");
    addressTypeDO.set("sequenced", true);

    addProperty(addressTypeDO, "name", SDOConstants.SDO_STRING, false, false, true);
    addProperty(addressTypeDO, "street", SDOConstants.SDO_STRING, false, true, true);
    addProperty(addressTypeDO, "city", SDOConstants.SDO_STRING, false, false, true);

    Type addressType = typeHelper.define(addressTypeDO);
    ((SDOProperty) addressType.getProperty("name")).setXsd(true);
    ((SDOProperty) addressType.getProperty("name")).setXsdLocalName("name");
    ((SDOProperty) addressType.getProperty("street")).setXsd(true);
    ((SDOProperty) addressType.getProperty("street")).setXsdLocalName("street");
    ((SDOProperty) addressType.getProperty("city")).setXsd(true);
    ((SDOProperty) addressType.getProperty("city")).setXsdLocalName("city");
    // -----------------
    DataObject usAddressTypeDO = dataFactory.create("commonj.sdo", "Type");
    usAddressTypeDO.set("uri", NON_DEFAULT_URI);
    usAddressTypeDO.set("name", "usAddressType");
    usAddressTypeDO.set("sequenced", true);
    List<Type> baseTypes = new ArrayList<Type>();
    baseTypes.add(addressType);
    usAddressTypeDO.set("baseType", baseTypes);

    DataObject stateProp = addProperty(usAddressTypeDO, "state", SDOConstants.SDO_STRING);
    stateProp.set(SDOConstants.XMLELEMENT_PROPERTY, true);

    Type usAddressType = typeHelper.define(usAddressTypeDO);
    ((SDOProperty) usAddressType.getProperty("state")).setXsd(true);
    ((SDOProperty) usAddressType.getProperty("state")).setXsdLocalName("state");
    // -----------------
    DataObject cdnAddressTypeDO = dataFactory.create("commonj.sdo", "Type");
    cdnAddressTypeDO.set("uri", NON_DEFAULT_URI);
    cdnAddressTypeDO.set("name", "cdnAddressType");
    cdnAddressTypeDO.set("sequenced", true);
    baseTypes = new ArrayList<Type>(); // reset
    baseTypes.add(addressType);
    cdnAddressTypeDO.set("baseType", baseTypes);

    addProperty(cdnAddressTypeDO, "province", SDOConstants.SDO_STRING, false, false, true);
    addProperty(cdnAddressTypeDO, "postalcode", SDOConstants.SDO_STRING, false, false, true);

    Type cdnAddressType = typeHelper.define(cdnAddressTypeDO);
    ((SDOProperty) cdnAddressType.getProperty("province")).setXsd(true);
    ((SDOProperty) cdnAddressType.getProperty("province")).setXsdLocalName("province");
    ((SDOProperty) cdnAddressType.getProperty("postalcode")).setXsd(true);
    ((SDOProperty) cdnAddressType.getProperty("postalcode")).setXsdLocalName("postalcode");

    // -----------------
    DataObject cdnAddressMailingTypeDO = dataFactory.create("commonj.sdo", "Type");
    cdnAddressMailingTypeDO.set("uri", NON_DEFAULT_URI);
    cdnAddressMailingTypeDO.set("name", "cdnAddressMailingType");
    cdnAddressMailingTypeDO.set("sequenced", true);
    baseTypes = new ArrayList<Type>(); // reset
    baseTypes.add(cdnAddressType);
    cdnAddressMailingTypeDO.set("baseType", baseTypes);

    DataObject deliveryInfoProp =
        addProperty(cdnAddressMailingTypeDO, "deliveryInfo", SDOConstants.SDO_STRING);
    deliveryInfoProp.set(SDOConstants.XMLELEMENT_PROPERTY, true);

    Type cdnAddressMailingType = typeHelper.define(cdnAddressMailingTypeDO);
    ((SDOProperty) cdnAddressMailingType.getProperty("deliveryInfo")).setXsd(true);
    ((SDOProperty) cdnAddressMailingType.getProperty("deliveryInfo"))
        .setXsdLocalName("deliveryInfo");

    // -----------------
    DataObject itemTypeDO = dataFactory.create("commonj.sdo", "Type");
    itemTypeDO.set("uri", NON_DEFAULT_URI);
    itemTypeDO.set("name", "LineItemType");

    DataObject prodcutNameProp = addProperty(itemTypeDO, "productName", SDOConstants.SDO_STRING);
    prodcutNameProp.set(SDOConstants.XMLELEMENT_PROPERTY, true);
    DataObject priceProp = addProperty(itemTypeDO, "price", SDOConstants.SDO_FLOAT);
    priceProp.set(SDOConstants.XMLELEMENT_PROPERTY, true);
    DataObject shipDateProp = addProperty(itemTypeDO, "shipDate", SDOConstants.SDO_STRING);
    shipDateProp.set(SDOConstants.XMLELEMENT_PROPERTY, true);
    DataObject commentProp = addProperty(itemTypeDO, "comment", SDOConstants.SDO_STRING);
    commentProp.set(SDOConstants.XMLELEMENT_PROPERTY, true);

    Type itemType = typeHelper.define(itemTypeDO);
    ((SDOProperty) itemType.getProperty("productName")).setXsd(true);
    ((SDOProperty) itemType.getProperty("productName")).setXsdLocalName("productName");

    ((SDOProperty) itemType.getProperty("price")).setXsd(true);
    ((SDOProperty) itemType.getProperty("price")).setXsdLocalName("price");

    ((SDOProperty) itemType.getProperty("shipDate")).setXsd(true);
    ((SDOProperty) itemType.getProperty("shipDate")).setXsdLocalName("shipDate");

    ((SDOProperty) itemType.getProperty("comment")).setXsd(true);
    ((SDOProperty) itemType.getProperty("comment")).setXsdLocalName("comment");
    // -----------------
    DataObject itemsTypeDO = dataFactory.create("commonj.sdo", "Type");
    itemsTypeDO.set("uri", NON_DEFAULT_URI);
    itemsTypeDO.set("name", "Items");
    itemsTypeDO.set("sequenced", true);

    addProperty(itemsTypeDO, "item", itemType, true, true, true);

    Type itemsType = typeHelper.define(itemsTypeDO);
    ((SDOProperty) itemsType.getProperty("item")).setXsd(true);
    ((SDOProperty) itemsType.getProperty("item")).setXsdLocalName("item");
    // -----------------
    DataObject poTypeDO = dataFactory.create("commonj.sdo", "Type");
    poTypeDO.set("uri", NON_DEFAULT_URI);
    poTypeDO.set("name", "PurchaseOrderType");

    addProperty(poTypeDO, "address", addressType, true, true, true);
    addProperty(poTypeDO, "comment", SDOConstants.SDO_STRING, false, false, true);
    addProperty(poTypeDO, "items", itemsType, true, false, true);

    Type poType = typeHelper.define(poTypeDO);
    ((SDOProperty) poType.getProperty("address")).setXsd(true);
    ((SDOProperty) poType.getProperty("address")).setXsdLocalName("address");
    ((SDOProperty) poType.getProperty("comment")).setXsd(true);
    ((SDOProperty) poType.getProperty("comment")).setXsdLocalName("comment");
    ((SDOProperty) poType.getProperty("items")).setXsd(true);
    ((SDOProperty) poType.getProperty("items")).setXsdLocalName("items");
    //  ((SDOProperty)poType.getProperty("myCS")).setXsd(true);
    //        ((SDOProperty)poType.getProperty("myCS")).setXsdLocalName("myCS");

    // -----------------
    DataObject companyTypeDO = dataFactory.create("commonj.sdo", "Type");
    companyTypeDO.set("uri", NON_DEFAULT_URI);
    companyTypeDO.set("name", "CompanyType");

    DataObject csProp = addProperty(companyTypeDO, "myCS", changeSummaryType, true, false, true);
    csProp.set("readOnly", true);
    addProperty(companyTypeDO, "order", poType, true, false, true);

    Type companyType = typeHelper.define(companyTypeDO);
    ((SDOProperty) companyType.getProperty("myCS")).setXsd(true);
    ((SDOProperty) companyType.getProperty("myCS")).setXsdLocalName("myCS");

    ((SDOProperty) companyType.getProperty("order")).setXsd(true);
    ((SDOProperty) companyType.getProperty("order")).setXsdLocalName("order");

    // ------------------

    types.add(companyType);
    types.add(cdnAddressType);
    types.add(usAddressType);
    types.add(itemsType);
    types.add(poType);
    types.add(cdnAddressMailingType);
    types.add(itemType);
    types.add(addressType);

    return types;
  }