Jeff Sonstein wrote:

On 27 Jan 2005, at 5:32 PM, Keith wrote:

> so what puzzles me is why Castor generates classes
> which seem as though there can only be one of each choice-possibility...
> or am I missing something?


Castor should generate a GroupingAndChildrenNodes class, that contains a
collection of GroupingAndChildrenNodesChoiceType, of which each
GroupingAndChildrenNodesChoiceType can contain on of the possible choices.


there is where I get confused
[ the javadocs for the generated classes are at http://www.xvrml.net/javadocs/ ]


OK, I took a quick look at the javadocs. The collection is the array of GroupingAndChildrenNodesItem. So basically the GroupingAndChildrenNodes class contains a collection of GroupingAndChildrenNodesItem. Each GroupingAndChildrenNodesItem contains the choice component.

So the collection is there, Castor is basically giving you one extra level of abstraction which you probably don't really need in your case, but none-the-less your collection is there.



Castor generates a Class GroupingAndChildrenNodes class but I do not see the collection of GroupingAndChildrenNodesType which I expected to find


there is a getGroupingAndChildrenNodesItem() method which returns a GroupingAndChidrenNodesItem[ ] and a getGroupingAndChildrenNodesItem( int index ) method which returns one GroupingAndChidrenNodesItemItem and a GroupingAndChidrenNodesItemCount which returns an int

Right, each GroupingAndChildrenNodesItem wraps the GroupingAndChildrenNodesChoice, so there is your collection.



Question 1:

so what do I do if I take this DOM-like approach?
get the count and the array
and iterate through each asking for the [what?]

Yes, you iterate through each item, getting the GroupingAndChildrenNodesChoice contained within each. From there is where it gets slightly ugly...you need to have an if-then-else statement to check which value of the choice has been set:


eg:

if (choice.getBillboard() != null) {
}
else if (choice.getCollision() != null) {
}
..

Castor could/should provide a more simple way of retrieving the value, such as public Object getChoiceValue(); or something like that. But eventually you'll end up needing to cast that value accordingly anyway at some point. Sometimes it may be necessary to move the casting or instanceof checking off to a later point though, so I feel that we should have a way to get whatever value has been set, without needing to loop through all the possibile getters.

Anyway, that's how to do it currently.

and finding out what it is [how?]

answered above.


Question 2:

how do I get Castor to generate classes which expose
the SAX loading which is happening happening "under the hood"
so my app can notice when each element is being loaded
and do what it needs to do with it?

Have you taken a look at the UnmarshalListener to see if that would work for you? If not you can always get the stick a ContentHandler in-between the parser and Castor's UnmarshalHandler (which implements both SAX 2.0 ContentHandler and SAX 1.0 DocumentHandler) to intercept all SAX events and then forward them on to Castor's UnmarshalHandler for unmarshalling.


Hope that helps,

--Keith



----------------------------------------------------------- If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
unsubscribe castor-user

Reply via email to