Nicolas, First of all, you don't need both the sequence and the any to have maxOccurs="unbounded". If either one is repeating then it the elements repeat.
<xsd:complexType name="content" mixed="false">
<xsd:sequence minOccurs="0" maxOccurs="unbounded">
<xsd:any namespace="##any"/>
</xsd:sequence>
</xsd:complexType>
For what you're trying to do, it sounds like you need to add a global
element userref, something like this:
<xsd:complexType name="userref">
<xsd:complexContent>
<xsd:extension base="um:umref">
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
<xsd:element name="userref" type="um:userref"/>
And then istead of adding the userref like this:
DataObject contentDO = do_audit.createDataObject("content");
contentDO.getList("userref").add(dobj);
you need to add it as an open content property like this:
DataObject contentDO = do_audit.createDataObject("content");
Property userrrefProp = typeHelper.getOpenContentProperty(";
http://example.com/usermodel/1.0", "userref");
contentDO.setList(userrefProp, Collections.singletonList(dobj));
Note that changing the last line to this:
contentDO.getList(userrefProp).add(obj));
might also work in Tuscany (I believe Tuscany will demand create an empty
open content list), but it's not guaranteed by the spec. That's why I'd
recommend going with setList approach.
Frank.
Nicolas Nobelis
<n...@blue-elepha
nt-systems.com> To
[email protected]
08/24/2009 08:39 cc
AM
Subject
Re: XMLHelper.save() write down
Please respond to object address
[email protected]
he.org
Sorry, copy paste error.
For the schema that lead to an exception, it was :
<xsd:complexType name="content" mixed="false">
<xsd:sequence minOccurs="0" maxOccurs="unbounded">
<xsd:any namespace="##any" minOccurs="0" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
Nicolas
Frank Budinsky wrote:
> Nicolas,
>
> One more thing I noticed. Your schema has an error:
>
> This part:
>
> <xsd:element ref="um:userref" minOccurs="0"/>
>
> should be:
>
> <xsd:element type="um:userref" minOccurs="0"/>
>
> since userref is a type, not a global element.
>
> Frank.
>
>
> Frank Budinsky/Toronto/i...@ibmca wrote on 08/21/2009 01:08:01 PM:
>
> > This part seems quite wrong:
> >
> > Property contentProp = do_audit.getType().getProperty("content");
> > DataObject contentDO = dobj.createDataObject(contentProp,
> > contentProp.getType());
> > contentDO.getList("userref").add(dobj);
> > do_audit.setDataObject(contentProp, contentDO);
> >
> > I think it should be something like this:
> >
> > DataObject contentDO = do_audit.createDataObject("content");
> > contentDO.getList("userref").add(dobj);
> >
> > Frank.
> >
> >
> > Nicolas Nobelis <[email protected]> wrote on 08/21/2009
> > 12:20:49 PM:
> >
> > > Greetings !
> > >
> > > Sorry for this huge post but I'm completely stuck with SDO ...
> > >
> > > I am using Tuscany tuscany-sdo-impl-1.1.1.jar with JDK 6.
> > >
> > > I have a XML schema audit.xsd :
> > > <xsd:schema targetNamespace="http://example.com/request/1.0"
> > > xmlns:xsd="http://www.w3.org/2001/XMLSchema"
> > > xmlns:req="http://example.com/request/1.0"
> > > xmlns:um="http://example.com/usermodel/1.0"
> > > xmlns="http://example.com/request/1.0."
> > > elementFormDefault="qualified">
> > >
> > > <xsd:include schemaLocation="usermodel.xsd"/>
> > >
> > > <xsd:complexType name="auditlog">
> > > <xsd:all>
> > > [...]
> > > <xsd:element name="content" type="content" minOccurs="0"
> > > maxOccurs="1"/>
> > > </xsd:all>
> > > </xsd:complexType>
> > >
> > > <xsd:complexType name="content" mixed="false">
> > > <xsd:sequence minOccurs="0" maxOccurs="unbounded">
> > > <xsd:element ref="um:userref" minOccurs="0"/>
> > > </xsd:sequence>
> > > </xsd:complexType>
> > > </xsd:schema>
> > >
> > > This schema references usermodel.xsd which contains :
> > > <xsd:complexType name="umref">
> > > <xsd:all>
> > > <xsd:element name="name" type="xsd:string" minOccurs="1"
> > > maxOccurs="1"/>
> > > </xsd:all>
> > > </xsd:complexType>
> > > <xsd:complexType name="userref">
> > > <xsd:complexContent>
> > > <xsd:extension base="um:umref">
> > > </xsd:extension>
> > > </xsd:complexContent>
> > > </xsd:complexType>
> > >
> > > So I give these two schemas to the XSDHelper through the "define"
> > > method. From the same HelperContext, I create a userref DO :
> > > dobj = getDataFactory().create("http://example.com/usermodel/1.0",
> > > "userref");
> > > I set its property :
> > > dobj.setString("name", "blabla");
> > >
> > > Then, I take an AuditLog DataObject do_audit and I add dobj as the
> > > attribute "content" :
> > >
> > > Property contentProp = do_audit.getType().getProperty("content");
> > > DataObject contentDO = dobj.createDataObject(contentProp,
> > > contentProp.getType());
> > > contentDO.getList("userref").add(dobj);
> > > do_audit.setDataObject(contentProp, contentDO);
> > >
> > > Finally, from the same HelperContext, I save the do_audit object :
> > >
> > > getXMLHelper().save(content, "http://example.com/request/1.0",
> "auditlog");
> > >
> > > and I get :
> > >
> > > <?xml version="1.0" encoding="UTF-8"?>
> > > <req:auditlog xmlns:req="http://example.com/request/1.0"
> > > xmlns:um="http://example.com/usermodel/1.0">
> > > [...]
> > > <req:content>
> > >
> > > <um:userref>org.apache.tuscany.sdo.impl.dynamicdataobjecti...@2c47d7
> > > (eClass: org.apache.tuscany.sdo.impl.classi...@1e2a543 (name:
userref)
> > > (instanceClassName: null) (abstract: false, interface: false))
> > > </um:userref>
> > > </req:content>
> > > </req:auditlog>
> > >
> > > Could anybody tell me why the address of the object is written and
not
> > > its contents ?
> > >
> > > Thanks a lot for any tips or advice :)
> > > Best regards and a nice w.e. to all !
> > >
> > > Nicolas Nobelis
> > >
> > >
> > >
> > >
>
<<inline: graycol.gif>>
<<inline: pic10656.gif>>
<<inline: ecblank.gif>>
