You may be able to create an object from one of the JAXB generated
classes by calling clazz.newInstance() after clazz = Class.forName(
"..." ), but what then? I cannot imagine that you'll be able to
provide meaningful data for these objects, just using reflection. And,
even you could do so, what could you do with this object?
Why do you think that you have to do this "dynamic element creation"?
There is, of course, the possibility of inspecting (by reading the
JAXB generated annotations) the generated Java classes. This will tell
you which class(es) is (are) XML root elements, and the sub-elements
and attributes of these elements as well. Then, you could inspect the
sub-elements, etc. This is very similar to what JAXB itself does to
learn about the bound XML structure, but this is quite complex. (And,
once more, where would the data for the XML elements come from?)
-W
On Tue, Sep 30, 2008 at 7:48 AM, maliheh shariat <malsh20_at_yahoo.com> wrote:
> Yes I mean the regular way is instantiate from jaxb objects and call setter methods but I want to instantiate and call setter methods in dynamically (I mean without I know the name of object I loop in jaxb objects , instantiate it and setting their methods), I know that I must use class.forname but I have to know the root element for setting another elements in it .
> do you have any suggestion or better way for doing this for me ?
>
> Thanks for your attention.
>
> Shariat
>
> --- On Mon, 9/29/08, Wolfgang Laun <wolfgang.laun_at_gmail.com> wrote:
>
>> From: Wolfgang Laun <wolfgang.laun_at_gmail.com>
>> Subject: Re: How to fill dynamically JAXB java objects
>> To: users_at_jaxb.dev.java.net
>> Date: Monday, September 29, 2008, 3:31 AM
>> What do you mean by "fixed way" and what by
>> "fill dynamically"? Perhaps you
>> post a Java code snippet of what you call "fixed
>> way".
>>
>> Generally speaking, you create an object by a call to one
>> of the methods in
>> some JAXB generated ObjectFactory class
>> ("createSomeElement") and then you
>> call the methods setThisSubElement( ... ) and
>> setTahtAttribute( ... ) of the
>> newly generated object. Except for the root element, all of
>> these created
>> objects have to be entered with setter methods as
>> sub-elements of their
>> parent elements.
>>
>>
>> On Sat, Sep 27, 2008 at 9:24 AM, maliheh shariat
>> <malsh20_at_yahoo.com> wrote:
>>
>> > Hi Friends
>> >
>> > I created Jaxb java classes and now I want to fill
>> them dynamically , but I
>> > dont know how I can dynamically fill JAXB java objects
>> (I can do it in fix
>> > way) ,I must say that their data are in xml file to
>> fill java objects ,
>> > please help me.
>> >
>> > Thanks alot
>> >
>> > Shariat
>> >
>> >
>> >
>> >
>> >
>> ---------------------------------------------------------------------
>> > To unsubscribe, e-mail:
>> users-unsubscribe_at_jaxb.dev.java.net
>> > For additional commands, e-mail:
>> users-help_at_jaxb.dev.java.net
>> >
>> >
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
> For additional commands, e-mail: users-help_at_jaxb.dev.java.net
>
>