I should add that WTKXSerializer *does* actually know about maps (or, more specifically, dictionaries). If your class exposes a read-only dictionary property (e.g. Component#getUserData()), WTKXSerializer will properly populate the dictionary based on markup. For example:
<Window> <userData foo="abc" bar="$def"/> </Window> The serializer will effectively call getUserData().put("foo", "abc") and getUserData().put("bar", def), where def is the value of the page-scoped variable referred to by "def". This is what allows styles to be set using an element vs. a JSON string, for example: <Label> <styles color="#ff0000"/> </Label> vs. <Label styles="{color:'#ff0000'}"> WTKXSerializer caters to sequences and dictionaries because those are the structures employed by XML. An XML element is effectively both a sequence (containing sub-elements and text nodes) and a dictionary (mapping string attribute names to attribute values). Since sets aren't really used by XML, there's no need for WTKXSerializer to try to support them. To some extent, sets are something of an artificial construct. As I mentioned in my previous email, they can be implemented via the Sequence interface. They can also be implemented via the Dictionary interface, if they keys are used as the set's values. In fact, this is how HashSet is implemented internally. The two primary data structures in most applications and frameworks are sequences (indexed access) and dictionaries (keyed access). Hope this helps. G On Jun 11, 2010, at 8:57 AM, Greg Brown wrote: > You can ensure that a Sequence implementation does not allow duplicate > entries. However, your collection class would also need to implement Set or > Group if you want to expose that API to a caller. WTKXSerializer does not > know anything about Sets (nor does it need to, since that is not a primary > use case for WTKX serialization). > > On Jun 11, 2010, at 8:49 AM, aappddeevv wrote: > >> Meant list and set not map. >> >> -----Original Message----- >> From: aappddeevv [mailto:aappdde...@verizon.net] >> Sent: Friday, June 11, 2010 7:58 AM >> To: dev@pivot.apache.org >> Subject: RE: [jira] Updated: (PIVOT-514) create an annotation to specify the >> default "child" property of a component used by the serializer to attach >> children objects >> >> My thinking was that if a client defined a list or a map using standard java >> collection classes. If the recommendation is to always use pivot collection >> classes in pivot code and sequence supports both map and list, that sounds >> fine. >> >> -----Original Message----- >> From: Greg Brown (JIRA) [mailto:j...@apache.org] >> Sent: Thursday, June 10, 2010 11:10 AM >> To: dev@pivot.apache.org >> Subject: [jira] Updated: (PIVOT-514) create an annotation to specify the >> default "child" property of a component used by the serializer to attach >> children objects >> >> >> [ >> https://issues.apache.org/jira/browse/PIVOT-514?page=com.atlassian.jira.plug >> in.system.issuetabpanels:all-tabpanel ] >> >> Greg Brown updated PIVOT-514: >> ----------------------------- >> >> Attachment: PIVOT-514.patch >> DefaultProperty.java >> >> OK, thanks for the updated patch. I think this can be done without the need >> for the utils class - see attached patch. >> >> There was also an issue with the setOrAddDefaultPropertyContent() method in >> SerializerUtils - that method checked for instances of java.util.Collection, >> where it should have been looking for org.apache.pivot.collections.Sequence >> (nothing in Pivot implements java.util.Collection). >> >> Overall, I like the change. It can significantly reduce the size/nesting >> depth of a WTKX file. See the changes to tab_panes.wtkx in the patch for an >> example. >> >> >>> create an annotation to specify the default "child" property of a >> component used by the serializer to attach children objects >>> >> ---------------------------------------------------------------------------- >> ------------------------------------------------- >>> >>> Key: PIVOT-514 >>> URL: https://issues.apache.org/jira/browse/PIVOT-514 >>> Project: Pivot >>> Issue Type: Improvement >>> Components: wtk >>> Reporter: Appddevvv >>> Priority: Minor >>> Fix For: 1.6 >>> >>> Attachments: DefaultProperty.java, defaultpropertypatch.zip, >> defaultpropertypatch.zip, PIVOT-514.patch >>> >>> >>> Add an annotation called @ContentProperty that specifies the default >> property to attach children to in the serializer. I found that I was making >> mistakes when creating WTKX that this annotation and a default "child >> attachment" approach could help. Benefits include: >>> a) The client does not need to know which property to attach the children >> to. >>> b) To add objects to a collection the parent object does not need to >> extend from sequence. The sequence can be contained in the object instead of >> implementing the interface. Containment can be another approach to getting >> content into the parent objects versus inheritance. >>> c) You can change some of the properties in the class where attachment >> occurs and your WTKX files do not have to change. >>> The default mechanism would be similar to what exists today. It's a simple >> extension of it. The "attach child" search would be: >>> a) If the content property is specified, use that property to add the >> child to. If the content property is a collection, add it to the collection. >>> b) If the content property is not specified, >>> b.1) If the parent object is a collection (this is how it is handled >> today) then add it to the collection using the List.add(Object) method. >>> b.2) Add it to the property specified in the XML. This is also how it is >> handled today. >>> I wrote this for a small modeled framework similar to pivot and could work >> up a couple of patches for this. This is very similar to how wpf handles >> child content specifications in XML. Thoughts? >> >> -- >> This message is automatically generated by JIRA. >> - >> You can reply to this email to add a comment to the issue online. >> >