tuscany-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "天涯′" <151835...@qq.com>
Subject How to define a sub DataObject type?
Date Wed, 30 Jan 2013 16:22:51 GMT
hi,all,the save method throw exception,anybody knows how to resolve the problem?
The object 'org.apache.tuscany.sdo.impl.DynamicDataObjectImpl@812517 (eClass: org.apache.tuscany.sdo.impl.ClassImpl@aa3e9a
(name: Customer2) (instanceClassName: null) (abstract: false, interface: false))' is not contained
in a resource.
 
public static void main(String[] args) {
  HelperContext scope = SDOUtil.createHelperContext();
  scope.getTypeHelper().define(getCustomerType());
  DataObject customer2 = scope.getDataFactory().create("http://example.com/customer", "Customer2");
  customer2.setInt("custNum", 333);
  DataObject customer = scope.getDataFactory().create("http://example.com/customer", "Customer");
  customer.setInt("custNum", 123);
  customer.setDataObject("firstName",customer2 );
  
  // --DataObject
  try {
   scope.getXMLHelper().save(customer, "http://example.com/customer","customer", System.out);
  } catch (Exception e) {
   e.printStackTrace();
  }
 }
 private static DataObject specifyProperty(DataObject containingTypeDO, String nameString,
Object type) {
  DataObject subordinateProperty = containingTypeDO.createDataObject("property");
  subordinateProperty.set("name", nameString);
  subordinateProperty.set("type", type);
  return subordinateProperty;
 }
 protected static DataObject getCustomerType() {
  HelperContext scope = SDOUtil.createHelperContext();
  TypeHelper typeHelper = scope.getTypeHelper();
  Type intType = typeHelper.getType("commonj.sdo", "Int");
  DataObject customerType = scope.getDataFactory().create("commonj.sdo","Type");
  customerType.set("uri", "http://example.com/customer");
  customerType.set("name", "Customer");
  specifyProperty(customerType,"custNum",intType);
  specifyProperty(customerType,"firstName",getCustomerType2(scope));
  return customerType;
 }
 
 protected static DataObject getCustomerType2(HelperContext scope) {
  TypeHelper typeHelper = scope.getTypeHelper();
  Type intType = typeHelper.getType("commonj.sdo", "Int");
  DataObject customerType = scope.getDataFactory().create("commonj.sdo","Type");
  customerType.set("uri", "http://example.com/customer");
  customerType.set("name", "Customer2");
  specifyProperty(customerType,"custNum",intType);
  return customerType;
 }
Mime
View raw message