[jdom-interest] Class generator
Brad Cox
bcox at virtualschool.edu
Thu Dec 22 04:09:00 PST 2011
Regarding "a "tool" that would create those classes automatically from a
xsd file"
If I understand your question correctly, that's what JAXB does.
http://jaxb.java.net/
On Thu, Dec 22, 2011 at 5:21 AM, Alexandre Santos <santosam72 at gmail.com>wrote:
> Hello Rolf,
>
> I'll do my best to the JDOM community :-)
>
> This example was compiled with JDOM 1.1.1 and jdk 1.3.1 on a j2se 1.2
> eclipse environment, because my Ubuntu 11.10 won't execute the java 1.2.1
> binaries (only my virtual CentOS 2...).
>
> About your observations: my first post was about asking if there was a
> "tool" that would create those classes automatically from a xsd file (or a
> xml file like EditiX). In my approach, the only "hard" work is to copy the
> toXML() method to each class. But in the end, you're right :-)
>
> Maybe a ToDo tool for JDOM :-)
>
> Alexandre
>
>
> On Thu, Dec 22, 2011 at 2:26 AM, Rolf <jdom at tuis.net> wrote:
>
>> Hi Alexandre.
>>
>> Thank you for your feedback. It's nice when people respond the way you
>> have.
>>
>> I have some observations, and a question....
>>
>> First the questions, in an earlier mail you indicated that you are using
>> Java 1.2.1. Do you have this running under Java 1.2.1? Are you using JDOM
>> 1.1.2?
>>
>> Then the observations....
>>
>> Just out of interest (and I know that the 'cars2java' example may be a
>> massive simplification), but have you considered simply extending the JDOM
>> classes to get what you want? You may be able to eliminate a complex
>> 'model'. It may create other issues, but, you may come up with a simpler
>> (and perhaps better) solution.
>>
>> For example, you could declare the class 'Car' to be:
>>
>> public class Car extends org.jdom.Element {
>>
>> public Car(String brandname) {
>> super("Car");
>> setBrand(brandname);
>> }
>>
>> public void setBrand(String brandname) {
>> Element brand = getChild("Brand");
>> if (brand == null) {
>> brand = new Element("Brand");
>> // add brand at the beginning of our content....
>> addContent(0, brand);
>> }
>> brand.setText(brandname);
>> }
>>
>> public String getBrand() {
>> Element brand = getChild("Brand");
>> if (brand == null) {
>> return "";
>> }
>> return brand.getText();
>> }
>>
>> ......
>>
>> }
>>
>> Once you have defined 'Car' to extend the JDOM Element, you can create
>> Car instances, and add them directly to a root element:
>>
>> Element cars = new Element("Cars");
>> Car renault = new Car("renault");
>> renault.setColorRGB("red", "FF0000");
>> cars.addContent(renault);
>>
>> xmlout.output(System.out, cars);
>>
>>
>> Just some thoughts.
>>
>> Rolf
>>
>>
>>
>> On 21/12/2011 6:05 PM, Alexandre Santos wrote:
>>
>>> Hello Rolf,
>>> I've been doing some experiments with a software called EditiX that can
>>> creates Java classes from a XML file. I've used JDOM on those classes to
>>> accomplish what I've been trying.
>>> The description of the solution I've figured out is here:
>>> www.alexandre-santos.com/**Cars2Java.html<http://www.alexandre-santos.com/Cars2Java.html>
>>> <http://www.alexandre-santos.**com/Cars2Java.html<http://www.alexandre-santos.com/Cars2Java.html>
>>> >
>>>
>>> Alexandre
>>>
>>>
>>>
>
> _______________________________________________
> To control your jdom-interest membership:
> http://www.jdom.org/mailman/options/jdom-interest/youraddr@yourhost.com
>
--
Cell: 703-594-1883
Blog: http://bradjcox.blogspot.com
Web: http://virtualschool.edu
Manassas VA 20111
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.jdom.org/pipermail/jdom-interest/attachments/20111222/3501c7e7/attachment.html>
More information about the jdom-interest
mailing list