I think what you are missing is a declaration of a global element in your
schema, so if you had something like
<xsd:element name="datasource" type="tns:datasource"/>
then you will be able to get a non-null response from
Property prop = scope.getXSDHelper().getGlobalProperty(NS_CODA,"datasource",
true);
You can then call content.setList(prop, list); // using Property based
setter, not string based
That should get you going.
Alternatively you could do
List list = content.getList(prop)
then just add DataObjects to list and they will automatically be contained
in content.
or repeated call
content.createDataObject(prop);
followed by content.getList(prop)
The problem with the way you are doing it is this -- when you are doing the
content.setList("datasource", thelist)
the namespace of the property "datasource" is not known. If the Type of the
content DataObject had a defined property called "datasource" then you could
just look up the Type of the "datasource" property, but it doesn't, we are
dealing with open content here.
There may be many "datasource" open content properties registered in
different namespaces or there may be none, but the runtime can't make
assumptions about which one to use, and, because the Type of content is
open, the runtime therefore creates an "on the fly" property "datasource"
in the no-namespace, and tries to infer it's type from the value passed
in. I think what is then happening is that the list object that you passed
in, when serialized, has a sequence of data objects that are not part of
the containment hierarchy of the data graph, which is not permissable,
hence the serialization failure.
Hope this helps, Kelvin.
On 19/03/2008, Peter Klotz <[EMAIL PROTECTED]> wrote:
>
> Hi,
>
> the setList works now fine when using xsd:any but
> I now get a exception when saving:
>
>
> <?xml version="1.0" encoding="ASCII"?>
> <listresponse xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:type="listresponse">
> <objectclass>test</objectclass>
> <content/>
>
> org.eclipse.emf.ecore.resource.Resource$IOWrappedException: The object
> '[EMAIL PROTECTED] (eClass:
> [EMAIL PROTECTED] (name: datasource)
> (instanceClassName: null) (abstract: false, interface: false))' is not
> contained
> in a resource.
> at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.endSave(
> XMLSaveImpl.java:284)
> at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.save(
> XMLSaveImpl.java:247)
> at org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl.doSave(
> XMLResourceImpl.java:203)
> at org.eclipse.emf.ecore.resource.impl.ResourceImpl.save(
> ResourceImpl.java:993)
> at org.apache.tuscany.sdo.helper.XMLDocumentImpl.save(
> XMLDocumentImpl.java:205)
> at org.apache.tuscany.sdo.helper.XMLDocumentImpl.save(
> XMLDocumentImpl.java:159)
> at org.apache.tuscany.sdo.helper.XMLHelperImpl.save(
> XMLHelperImpl.java:163)
> at org.apache.tuscany.sdo.helper.XMLHelperImpl.save(
> XMLHelperImpl.java:149)
> at com.bes.itm.sdo.test.RequestTest.testSetContent(
> RequestTest.java:74)
>
>
> although
> content.setList("datasource", list);
> adds the sub-DO into the "content" object.
> Probably has to do with the declaration of the content as xsd:any
>
> When I look into the OpenType example in the 1.0 distributio that I'm
> using,
> it uses
>
> Property prop = scope.getXSDHelper().getGlobalProperty(NS_CODA,
> "datasource", true);
>
> but this always returns null?
>
> what is wrong with the original approach as seen below?
>
>
> ---
>
>
> <xsd:complexType name="content">
> <xsd:sequence>
>
> <xsd:any minOccurs="0" maxOccurs="unbounded" namespace="##any"
> processContents="lax"/>
> </xsd:sequence>
> </xsd:complexType>
>
>
> ---
> DataObject resp = scope.getDataFactory().create(RequestUtils.NS_REQ,
> "listresponse");
> resp.setString(RequestUtils.ATTR_OBJCLASS, "test");
>
> TypeHelper th = scope.getTypeHelper();
> Type type = th.getType(NS_CODA, "datasource");
> DataFactory df = scope.getDataFactory();
>
> // construct list of datasource DOs
> List<DataObject> list = new ArrayList<DataObject>();
> DataObject dobj = df.create(type);
> dobj.setString("name", "test1");
> dobj.setString("description", "test1");
> list.add(dobj);
> dobj = df.create(type);
> dobj.setString("name", "test2");
> dobj.setString("description", "test2");
> list.add(dobj);
>
> // create content wrapper
> DataObject content = scope.getDataFactory().create(RequestUtils.NS_REQ
> ,
> "content");
> resp.setDataObject("content", content);
> // set xsd:any element
> content.setList("datasource", list);
>
> // output
> scope.getXMLHelper().save(resp, RequestUtils.NS_REQ, "listresponse",
> System.out);
> ---
>
>
>
> Frank Budinsky wrote:
> > Hi Peter,
> >
> > This should work:
> >
> > <xsd:element name="content" type="xsd:anyType" minOccurs="0"
> > maxOccurs="unbounded"/>
> >
> > I think the problem is just a typo. Your declaration says
> > maxOccurs="unbound"
>
>
> Peter
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>