I have an XML which has tags corresponding to three types of Java objects which would be created from the XML. The objects are of the form:
A
- static Map<String, A>
- String name
- String aInfo1
- String aInfo2
B
- static Map<String, B>
- String name
- String bInfo1
- String bInfo2
C
- A aObject
- B bObject
Now, in my XML, I define a list of tags for A objects and B objects and then I define tags for C objects which refer to A and B objects using there name field. I have two requirements:
I have read about some Java frameworks like JAXB but I am unable to come up with a way to create such type of objects from my XML. Is there a framework in Java which can do this out-of-the box or with minimum logic?
Edit:
There is another requirement: I need to define D and E objects of the form
D
- Map<A, E>
I would define E objects similar to how servlets are defined in web.xml i.e. first define the name and class for the E class and then use the name for E at some other place. Additionally, pass parameters to instantiate E objects. The tag would look like:
<E>
<name>queryProcessor</name>
<class>com.mydomain.QueryProcessor</class>
</E>
Now this would be used while defining content of Map in D
<D>
<map>
<A>name_of_some_A_object</A>
<E name="queryProcessor">
<param1>name_of_some_B_object</param1>
<param2>name_of_some_B_object</param2>
</E>
<A>name_of_some_A_object</A>
<E name="queryProcessor">
<param1>name_of_some_B_object</param1>
<param2>name_of_some_B_object</param2>
</E>
</map>
</D>
Essentially the map in D will be populated by instantiating a class of base type E with the parameters passed to it and an object of A, referred by its name.
(You could do it also the other way around, if you are familiar with JAXB annotations and want to control the interface with Java rather than with an XSD).
Note: static Maps is most likely not what you want to use. If you explain more about what problem you want to solve we might be able to point you out some alternative ways
Edit:
Are you talking about the format of the XML? Or why I need XML at all? I need XML for the ability to make my applications configurable outside of Java.
It looks like you're re-inventing the wheel. Have a look at Spring and see if it fits your needs. If it doesn't, explain why.