Java/JAXB: Accessing property of object in a list
- by Mark Lewis
Hello
Using JAXB I've created a series of classes which represent my XML schema. Validating against the schema an XML file has thus become a 'tree' of java objects representing the XML. Now I'd like to access, delete and add an object of one the created types in my tree.
If I've got classes' methods arranged like this:
RootType class has:
public List<FQType> getFq() { // and setter
return fq;
}
FQType class has:
public RemapType getRemap() { // and setter
return remap;
}
RemapType class has:
public String getSource() { // and setter
return source;
}
What's the most concise way to code reading and writing of the 'source' member of a RemapType instance in an FQType instance with, say, fqtypeID=1, in an array of type RootType (in which RootType instances also each have rootID)?
Currently I'm using a for loop Iterator in which is an if rootID = mySelectedRootID. In the if I nest a second for loop Iterator over the contained FQType instances and in that a second if fqTypeID = mySelectedFQTypeID.
IE for loop iterator/if statement pairs to recognise the object of desire. With all the bells and whistles this way is nearly 15 lines of code to access a data type - can I do this in one line?
Thanks