You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@tuscany.apache.org by Peter Klotz <pe...@blue-elephant-systems.com> on 2008/03/17 19:49:03 UTC

List of anyType elements

Hi,

I would like to define a attribute that is a list of other DataObjects of any
type (non-primitive). I've tried to use a anonymous element without name as any
attribute of any type could go in here:

  <xsd:complexType name="content">
    <xsd:sequence>
      <xsd:element type="xsd:anyType" minOccurs="0" maxOccurs="unbound"/>
    </xsd:sequence>
  </xsd:complexType>

used somewhere as an element:

 <xsd:element name="content" type="content" minOccurs="0" maxOccurs="1"/>


Result:

Caused by: java.lang.IllegalArgumentException
        at
org.apache.tuscany.sdo.helper.XSDHelperImpl.define(XSDHelperImpl.java:263)
        at
org.apache.tuscany.sdo.helper.XSDHelperImpl.define(XSDHelperImpl.java:224)


Other options like setting the type of an element to xsd:anyType instead of this
"x:content"

 <xsd:element name="content" type="xsd:anyType" minOccurs="0" maxOccurs="unbound"/>

or things like this


  <xsd:complexType name="content">
    <xsd:complexContent>
      <xsd:restriction base="xsd:anyType">
        <xsd:sequence/>
      </xsd:restriction>
    </xsd:complexContent>
  </xsd:complexType>

 <xsd:element name="content" type="content" minOccurs="0" maxOccurs="1"/>

yield an ClassCastException on java.util.ArrayList on the statement

List<DataObject> mylist = ...
dobj.setList("content", mylist);

where I try to set a attribute with a list of DataObjects.


How to do this correctly in Tuscany?

I've debugged a bit but I'm getting lost in the EMF stuff :-(
Note, that I can't set an attribute name for the element as there could be many
so in the end I need an any type anonymous element. Just want to specify that it
should be complex content.


Thanks, Peter


Re: List of anyType elements

Posted by kelvin goodson <ke...@thegoodsons.org.uk>.
Peter,
  I don't think it's something I can put on my radar at the moment, sorry.
You may like to raise this as an issue on the tuscany-dev mailing list,  and
perhaps open a JIRA for it.  I guess from your request that it's not
something you might consider contributing yourself is it?  If you could that
would be really helpful.

Regards, Kelvin.



On 19/03/2008, Peter Klotz <pe...@blue-elephant-systems.com> wrote:
>
> Hi Kevin,
>
> thanks that was very very helpfull indeed! It's working, thanks.
>
> One more question in
>
> XMLHelperImpl.save()
>
> public void save(XMLDocument xmlDocument, Result outputResult, Object
> options)
> throws IOException {
>         options = checkSetOptions(options);
>         if (outputResult instanceof DOMResult) {
>
> ((XMLDocumentImpl)xmlDocument).save(((DOMResult)outputResult).getNode(),
> options);
>         } else if (outputResult instanceof SAXResult) {
>
>
>             throw new UnsupportedOperationException();
> ---
>
> when will this be "supported", because I need to read the result of the
> save
> into a JDOMResult, which is a sub-class of SAXResult :-( ?
> I can certainly workaround this but that is not efficient to use DOM!
>
> ---
>         } else if (outputResult instanceof StreamResult) {
>             save(xmlDocument,
> ((StreamResult)outputResult).getOutputStream(),
> options);
>         } else {
>             throw new UnsupportedOperationException();
>         }
>     }
>
>
> Thanks, Peter
>
>
> kelvin goodson wrote:
> > 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.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tuscany-user-unsubscribe@ws.apache.org
> For additional commands, e-mail: tuscany-user-help@ws.apache.org
>

Re: List of anyType elements

Posted by Peter Klotz <pe...@blue-elephant-systems.com>.
Hi Kevin,

thanks that was very very helpfull indeed! It's working, thanks.

One more question in

XMLHelperImpl.save()

public void save(XMLDocument xmlDocument, Result outputResult, Object options)
throws IOException {
        options = checkSetOptions(options);
        if (outputResult instanceof DOMResult) {

((XMLDocumentImpl)xmlDocument).save(((DOMResult)outputResult).getNode(), options);
        } else if (outputResult instanceof SAXResult) {


            throw new UnsupportedOperationException();
---

when will this be "supported", because I need to read the result of the save
into a JDOMResult, which is a sub-class of SAXResult :-( ?
I can certainly workaround this but that is not efficient to use DOM!

---
        } else if (outputResult instanceof StreamResult) {
            save(xmlDocument, ((StreamResult)outputResult).getOutputStream(),
options);
        } else {
            throw new UnsupportedOperationException();
        }
    }


Thanks, Peter

kelvin goodson wrote:
> 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.


Re: List of anyType elements

Posted by kelvin goodson <ke...@thegoodsons.org.uk>.
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 <pe...@blue-elephant-systems.com> 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
> 'org.apache.tuscany.sdo.impl.DynamicDataObjectImpl@15a6029 (eClass:
> org.apache.tuscany.sdo.impl.ClassImpl@1fc6e42 (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: tuscany-user-unsubscribe@ws.apache.org
> For additional commands, e-mail: tuscany-user-help@ws.apache.org
>

Re: List of anyType elements

Posted by Peter Klotz <pe...@blue-elephant-systems.com>.
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
'org.apache.tuscany.sdo.impl.DynamicDataObjectImpl@15a6029 (eClass:
org.apache.tuscany.sdo.impl.ClassImpl@1fc6e42 (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


Re: List of anyType elements

Posted by Frank Budinsky <fr...@ca.ibm.com>.
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"

Frank.


Peter Klotz <pe...@blue-elephant-systems.com> wrote on 03/17/2008 
02:49:03 PM:

> Hi,
> 
> I would like to define a attribute that is a list of other DataObjects 
of any
> type (non-primitive). I've tried to use a anonymous element without 
> name as any
> attribute of any type could go in here:
> 
>   <xsd:complexType name="content">
>     <xsd:sequence>
>       <xsd:element type="xsd:anyType" minOccurs="0" 
maxOccurs="unbound"/>
>     </xsd:sequence>
>   </xsd:complexType>
> 
> used somewhere as an element:
> 
>  <xsd:element name="content" type="content" minOccurs="0" 
maxOccurs="1"/>
> 
> 
> Result:
> 
> Caused by: java.lang.IllegalArgumentException
>         at
> 
org.apache.tuscany.sdo.helper.XSDHelperImpl.define(XSDHelperImpl.java:263)
>         at
> 
org.apache.tuscany.sdo.helper.XSDHelperImpl.define(XSDHelperImpl.java:224)
> 
> 
> Other options like setting the type of an element to xsd:anyType 
> instead of this
> "x:content"
> 
>  <xsd:element name="content" type="xsd:anyType" minOccurs="0" 
> maxOccurs="unbound"/>
> 
> or things like this
> 
> 
>   <xsd:complexType name="content">
>     <xsd:complexContent>
>       <xsd:restriction base="xsd:anyType">
>         <xsd:sequence/>
>       </xsd:restriction>
>     </xsd:complexContent>
>   </xsd:complexType>
> 
>  <xsd:element name="content" type="content" minOccurs="0" 
maxOccurs="1"/>
> 
> yield an ClassCastException on java.util.ArrayList on the statement
> 
> List<DataObject> mylist = ...
> dobj.setList("content", mylist);
> 
> where I try to set a attribute with a list of DataObjects.
> 
> 
> How to do this correctly in Tuscany?
> 
> I've debugged a bit but I'm getting lost in the EMF stuff :-(
> Note, that I can't set an attribute name for the element as there 
> could be many
> so in the end I need an any type anonymous element. Just want to 
> specify that it
> should be complex content.
> 
> 
> Thanks, Peter
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tuscany-user-unsubscribe@ws.apache.org
> For additional commands, e-mail: tuscany-user-help@ws.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-user-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-user-help@ws.apache.org