generate java bean from an xml file?

E

Elhanan

hi..

first don't say xsl, it has some drawbacks (like being too complex) i'
was wondering if there is some infrastucture like an object model or
something like it that can generate javabean code (i have a custom xml
file which i need to use for the source creation).
 
D

Daniel Dyer

hi..

first don't say xsl, it has some drawbacks (like being too complex) i'
was wondering if there is some infrastucture like an object model or
something like it that can generate javabean code (i have a custom xml
file which i need to use for the source creation).


There are dozens of such tools. http://bindmark.dev.java.net/ provides
benchmarks and links for many. JiBX (http://www.jibx.org) is my current
favourite.

Dan.
 
E

Elhanan

you are talking about xml data binding, that's exactly what i want to
avoid,i don't have an xsd, and creating one from the custom, is rather
complex,
the beans i'm want to generate

on top of that, not many xml data-binding tools support what i'm
looking for (i thought about at first), in fact jaxb was the only one
came close (it supports id, idref, by actually getting objectt
references, as well substition groups) all others either don't support
all of it, or have known bug suppurting it.
however jaxb , it too much java like, it forces you to use factories,
to create the beans, as welll other probems (like inheritence).
 
O

ozgwei

Elhanan said:
you are talking about xml data binding, that's exactly what i want to
avoid,i don't have an xsd, and creating one from the custom, is rather
complex,
the beans i'm want to generate

You may want to try xstream from codehaus.org.

However, it doesn't generate code, it just does binding according to
your rules specified in your code.

Another choice may be Jakarta Commons Bitwixt, similarly, no code
generation.

Personally, I don't like generated code because it's a maintenance
nightmare...
 
R

RiCaRdO

Oh. now that I've re-read that, yes I have missed the point...

sorry for the noise.

Is it arbitrary XML you are trying to generate class files for? or has
it been outputted from a particular tool?
 
E

Elhanan

the xml is generated from a closed product, i'm designing how the
output is going to be generated (and no , it won't be xsd), based on
that xml, i'm going to create an spring beans file, as well as classes
and interaces.


you see the closed tool is actually a java questionair generator which
can build html screens for online questionairs, but also can recive
data using xml. the end user can design the questionair, so i have to
adap with minmim change.

the fields are usually grouped in inside same subject elements, for
example you can have several fields called name, age, and weight, the
fact the these fields belong to an element called person, cannot be
change by the end user
however what can be changed is how these fields appear, validated and
displayed. such defintions, are located in something called source (not
source code)

so field called name would can have different defintions in two
seperate sources, when you start answering a questionair you select
which sources you want be used, based on that infomation the the
selected sources are in union thus creating a questionair.

so let's say you have
class Person {
private String name
public getName
public setName;

private int age
public getAge
public setAge;

private int weight
public getweight
public setweight;

}

but you selected that only name and age would be in a source. number 1

so you get
interface PersonSource1{

private String name
public getName
public setName;

private int age
public getAge
public setAge;
}

and have the person class implement that interface.

so if have like 20 sources, i'll have 20 interfaces generated for that
class

so xml i'm building is going to reflect that structure by saying (more
simplifed)

<Element Name="Person">
<Attribute Name="Name>
<Sources>
</Source Id="1"/>
</Source Id="2"/>
</Sources>
</Attribute
<Attribute Name="Age>
<Sources>
</Source Id="1"/>
</Sources>
</Attribute
</Element>

the relationship between these elemetns is fixed so i won't have to
regenerate it each time.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,071
Latest member
MetabolicSolutionsKeto

Latest Threads

Top