Dear Wiki user, You have subscribed to a wiki page or wiki category on "Ws Wiki" for change notification.
The following page has been changed by KelvinGoodson: http://wiki.apache.org/ws/Tuscany/Java/SDO/ThinkingAloud/OpenContent ------------------------------------------------------------------------------ A suitable schema for playing with open content ... - {{{ + {{{ <?xml version="1.0" encoding="UTF-8"?> <xsd:schema xmlns:simple="http://www.example.com/open" xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.com/open"> @@ -21, +21 @@ <xsd:element name="company"> <xsd:complexType> <xsd:sequence> - <xsd:element name="name" type="xsd:string"/> + <xsd:element name="name" type="xsd:string"/> </xsd:sequence> </xsd:complexType> </xsd:element> @@ -40, +40 @@ To be able to set a value into a wildcard (<xsd:any>), you have to be able to get hold of a Property that is associated with a global element, the schema above demonstrates one way to create such a beast. In the code you can find the Property that is generated from the element "simple" with ... - {{{ + {{{ Property pc = XSDHelper.INSTANCE.getGlobalProperty("http://www.example.com/open", "note", true); }}} - so then you should I think be able to do ... + so then you might think you should able to do ... - {{{ + {{{ OpenQuote oq = OpenFactory.INSTANCE.createOpenQuote(); Property pc = XSDHelper.INSTANCE.getGlobalProperty("http://www.example.com/open", "note", true); ((DataObject)oq).set(pc, "TBA"); }}} - '''Note:''' in the future it will be possible to do '''dob.set("<property>", value);''' to set into a wildcard (not sure how the namespace is selected in the property argument.) + ('''Note:''' in the future it will be possible to do '''dob.set("<property>", value);''' to set into a wildcard (although I'm not sure at the moment how the namespace is selected in the property argument.)) - but there's a problem with the code at the moment I think (I've submitted http://issues.apache.org/jira/browse/TUSCANY-396) + But the thing is that the cardinality of association between the OpenQuote instance and the instance of the Property that's being attached by virtue of the xsd:any wildcard is defined by the ''global element'' (not the xsd:any), i.e. in this case the "note" element, and there's no way in schema to constrain the maxOccurs attribute of a global element. The upshot of that is that if you want to add a single Property value as open content, where the Property is derived from an XML Schema global element, you must wrap the value in a Collection... - so at the moment you have to do something like this ... - - {{{ + {{{ OpenQuote oq = OpenFactory.INSTANCE.createOpenQuote(); oq.setSymbol("ww"); @@ -80, +78 @@ which gives ... - {{{ + {{{ <?xml version="1.0" encoding="ASCII"?> <open:openStockQuote xmlns:open="http://www.example.com/open"> <symbol>ww</symbol> @@ -88, +86 @@ </open:openStockQuote> }}} + There is a way programmatically to create Property instances with maxOccurs=1 ... + {{{ + OpenQuote oq = OpenFactory.INSTANCE.createOpenQuote(); + Type globalType = SDOUtil.createType(TypeHelper.INSTANCE, "some-namespace", null, false); + Property p = SDOUtil.createProperty(globalType, "newProp", TypeHelper.INSTANCE.getType("commonj.sdo", "String")); + ((DataObject)oq).set(p, "newValue"); + }}} + + but if your environment constrains you to creating you metadata from XSD then currently there's no way to achieve this coding style. It has been mooted that a new SDO annotation could be added so that the generated code for the Property could ascribe the 0..1 cardinality behaviour. + + So now I need to understand what semantics are placed on the maxOccurs=1 of the xsd:any -- any suggestions most welcome [EMAIL PROTECTED] [[Anchor(multiprop)]] - == Open content with max occurs > 1 == + == Open content with maxOccurs > 1 == - The behaviour of the code here may throw some light on why the single valued case is as it is, and perhaps that I have misunderstood that case. Here's where my experiments have led so far + + This section being reworked in the light of my newly gained understanding above Considering the schema ... - {{{ + {{{ <?xml version="1.0" encoding="UTF-8"?> <xsd:schema xmlns:simple="http://www.example.com/open" xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.com/open"> @@ -117, +127 @@ The following document .... - {{{ + {{{ <?xml version="1.0" encoding="ASCII"?> <open:openStockQuote2 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:open="http://www.example.com/open" xsi:type="open:OpenQuote2"> <symbol>ww</symbol> @@ -127, +137 @@ }}} is created by the following code ... - {{{ + {{{ OpenQuote2 oq = OpenFactory.INSTANCE.createOpenQuote2(); oq.setSymbol("ww"); @@ -156, +166 @@ System.out.println(baos.toString()); }}} - Which kind of surprised me a bit, since I had expected the second set() call to overwrite the first, but now it kind of makes sense. So that makes me reconsider the semantics I had placed upon the single cardinality case above, and begs the question whether the above referenced JIRA I raised was in error. Watch this space! - - OK, so if my theory is correct, adding - {{{ - <xsd:element name="oneNote" type="xsd:string" maxOccurs="1" /> - }}} - - to the schema should allow me to do ... - {{{ - Property pOneNote = XSDHelper.INSTANCE.getGlobalProperty("http://www.example.com/open", "oneNote", true); - doq.set(pOneNote, "this is it!"); - }}} - - but it doesn't! it still fails as described above, when expecting the supplied argument to be a List, even though both the xsd:any and the global element have maxOccurs = 1 on them! So either I still misunderstand, or there's something wrong here. - --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
