Hello, given the recent set of people announcing themselves as working on Tuscany, I guess I should say hello properly. I'm Kelvin Goodson, and I'm working on Java SDO.
To that end I've recently been doing some digging with SDO Java open content programs, and I'm not sure what the behaviour should be at times. I've been jotting my musings at http://wiki.apache.org/ws/Tuscany/Java/SDO/ThinkingAloud/OpenContent. I'd like to clarify the behaviour of the Java code with respect to the maxOccurs values associated with global elements and wildcards (I've opened Jira http://issues.apache.org/jira/browse/TUSCANY-396 for this, but the discussion here goes beyond that issue.) Here's my starting 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"> <xsd:element name="openStockQuote" type="simple:OpenQuote"/> <xsd:element name="note" type="xsd:string"/> <xsd:complexType name="OpenQuote"> <xsd:sequence> <xsd:element name="symbol" type="xsd:string"/> <xsd:any maxOccurs="1" namespace="##any"/> </xsd:sequence> </xsd:complexType> </xsd:schema> 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 p = XSDHelper.INSTANCE.getGlobalProperty("http://www.example.com/simpleGlobalElem", "simple", true); so then you should I think be 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"); but there's a problem with the code at the moment I think (see above referenced Jira) so at the moment you have to do something like this ... OpenQuote oq = OpenFactory.INSTANCE.createOpenQuote(); oq.setSymbol("ww"); DataObject doq = (DataObject)oq; boolean isElement = true; Property pc = XSDHelper.INSTANCE.getGlobalProperty("http://www.example.com/open", "note", isElement); // value must be added as a list List lnote = new ArrayList(); lnote.add(new String("TBA")); doq.set(pc, lnote); ByteArrayOutputStream baos = new ByteArrayOutputStream(); XMLHelper.INSTANCE.save(doq, "http://www.example.com/open", "openStockQuote", baos); System.out.println(baos.toString()); which gives ... <?xml version="1.0" encoding="ASCII"?> <open:openStockQuote xmlns:open="http://www.example.com/open"> <symbol>ww</symbol> <open:note>TBA</open:note> </open:openStockQuote> Open content with max occurs > 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 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"> <xsd:element name="openStockQuote2" type="simple:OpenQuote2"/> <xsd:element name="note" type="xsd:string"/> <xsd:element name="count" type="xsd:int"/> <xsd:complexType name="OpenQuote2"> <xsd:sequence> <xsd:element name="symbol" type="xsd:string"/> <xsd:any maxOccurs="unbounded" namespace="##any"/> </xsd:sequence> </xsd:complexType> </xsd:schema> 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> <open:note>TBA</open:note> <open:count>1</open:count> </open:openStockQuote2> is created by the following code ... OpenQuote2 oq = OpenFactory.INSTANCE.createOpenQuote2(); oq.setSymbol("ww"); DataObject doq = (DataObject)oq; boolean isElement = true; Property pc = XSDHelper.INSTANCE.getGlobalProperty("http://www.example.com/open", "note", isElement); List lnote = new ArrayList(); lnote.add(new String("TBA")); doq.set(pc, lnote); Property pc2 = XSDHelper.INSTANCE.getGlobalProperty("http://www.example.com/open", "count", isElement); List lcount = new ArrayList(); lcount.add(new Integer(1)); doq.set(pc2, lcount); ByteArrayOutputStream baos = new ByteArrayOutputStream(); XMLHelper.INSTANCE.save(doq, "http://www.example.com/open", "openStockQuote2", baos); 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. OK, so if my theory is correct, that the cardinality of the global elements (unspecified) causes this requirement for adding a value wrapped in a List, then 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!"); on a DataObject of Type OpenQuote 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.
