Hi,

For my school-project I need to persist some object to xml-files.
I saw castor and wow, I think thats the right way!

I read the documentations, but I not found any hint for my problem.
There are DeviceModels which consist of data keys (different device models
can share the same data keys).
Is it possible to marshall the objects, but without specifying the keys for
each model but once on the top of the document?

Thank you for helping
Greetings Daniel



My marshal action:
---------------------------------------------------------------------
List models = new LinkedList<DeviceModel>();
List attributes = new LinkedList<Datakey>();

attributes.add(new Datakey("rad", "Solarstrahlung"));
attributes.add(new Datakey("rad_e_day", "Solarenergie Tag"));

DeviceModel model = new DeviceModel("S 2000C");
model.setAttributes(attributes);
models.add(model);

marshaller.marshal(models);



Here is an example of the xml file that I will receive on marshaling:
---------------------------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<model-definition>

        <data-keys>
                <data-key id="rad" description="Solarstrahlung" />
                <data-key id="rad_e_day" description="Solarstrahlung Tag" />
        </data-keys>

    <models>
        <model name="S 2000C">
                <data-key-id>rad</data-key-id>
        </model>

        <model name="S 4000C">
                <data-key-id>rad_e_day</data-key-id>
        </model>

        <model name="S 5000C">
                <data-key-id>rad</data-key-id>
                <data-key-id>rad_e_day</data-key-id>
        </model>
    </models>

</model-definition>



Class DeviceModel:
---------------------------------------------------------------------
public class DeviceModel {

        private String name;
        private List<Datakey> attributes;

        public DeviceModel() {

        }

        public DeviceModel(String name) {
                this.name = name;
        }

        public String getName() {
                return name;
        }

        public void setName(String name) {
                this.name = name;
        }

        public List<Datakey> getAttributes() {
                return attributes;
        }

        public void setAttributes(List<Datakey> attributes) {
                this.attributes = attributes;
        }
}



Class Datakey:
---------------------------------------------------------------------
public class Datakey {

        private String id;
        private String description;


        public Datakey() {
        }


        public Datakey(String id, String description) {
                this.id = id;
                this.description = description;
        }

        public String getID() {
                return id;
        }
        public void setID(String id) {
                this.id = id;
        }
        public String getDescription() {
                return description;
        }
        public void setDescription(String description) {
                this.description = description;
        }
}


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply via email to