Hallo,
ich hab mir mit JAXB und dem xjc einen Klassenhierarchie erzeugen lassen und möchte dafür nun eine Fassade bauen damit meine ganzen Programme sie genauso benutzen können wie meine alte JDOM Lösung.
Mein Problem ist nun das ich um die ganze Sache performanter zu machen auf die in den erzeugen Class Files Listen der Unterelemente verzichten will um dort Hashmaps einzusetzten. Die Liste werde aber weiterhin genutzt, sonst würde ja beim schreiben der Unmarshaller meckern.
Wenn ich jedoch in einer dieser Class Files nachträglich eine Hashmap sowie die zur Nutzung notwendigen Methoden implementiere, werde wenn ich die Datei schreiben will, die Hashmap mit in die XML Datei geschrieben.
Man muß ja diese Hashmap in dem Objekt unter porpOrder einfügen damit der JAXBContext net meckert.
Also wie kann ich nachträglich eine HashMap einfügen, ohne das mir das hinterher im XML Dokument landet?
merci
Christian
ich hab mir mit JAXB und dem xjc einen Klassenhierarchie erzeugen lassen und möchte dafür nun eine Fassade bauen damit meine ganzen Programme sie genauso benutzen können wie meine alte JDOM Lösung.
Mein Problem ist nun das ich um die ganze Sache performanter zu machen auf die in den erzeugen Class Files Listen der Unterelemente verzichten will um dort Hashmaps einzusetzten. Die Liste werde aber weiterhin genutzt, sonst würde ja beim schreiben der Unmarshaller meckern.
Wenn ich jedoch in einer dieser Class Files nachträglich eine Hashmap sowie die zur Nutzung notwendigen Methoden implementiere, werde wenn ich die Datei schreiben will, die Hashmap mit in die XML Datei geschrieben.
Man muß ja diese Hashmap in dem Objekt unter porpOrder einfügen damit der JAXBContext net meckert.
Also wie kann ich nachträglich eine HashMap einfügen, ohne das mir das hinterher im XML Dokument landet?
merci
Christian
Code:
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;
import javax.xml.datatype.XMLGregorianCalendar;
/**
* All Intervals
*
*
Java class for IntervalType complex type.
*
*
The following schema fragment specifies the expected content contained within this class.
*
* <pre>
* &complexType name="IntervalType">
* &complexContent>
* &restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* &sequence>
* &element name="location" type="{http://www.iset.de/wpms}LocationType" maxOccurs="unbounded"/>
* &/sequence>
* &attribute name="start_time" type="{http://www.w3.org/2001/XMLSchema}dateTime" />
* &/restriction>
* &/complexContent>
* &/complexType>
* </pre>
*
*
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "IntervalType", propOrder = {
"location",
"locationMap"
})
public class IntervalType implements Comparable <IntervalType> {
@XmlElement(required = true)
protected List<LocationType> location;
@XmlAttribute(name = "start_time")
protected XMLGregorianCalendar startTime;
@XmlElement(required = false)
protected HashMap<String, LocationType> locationMap = new HashMap<String, LocationType>();
/**
* Gets the value of the location property.
*
*
* This accessor method returns a reference to the live list,
* not a snapshot. Therefore any modification you make to the
* returned list will be present inside the JAXB object.
* This is why there is not a <CODE>set</CODE> method for the location property.
*
*
* For example, to add a new item, do as follows:
* <pre>
* getLocation().add(newItem);
* </pre>
*
*
*
* Objects of the following type(s) are allowed in the list
* {@link LocationType }
*
*
*/
public List<LocationType> getLocation() {
if (location == null) {
location = new ArrayList<LocationType>();
}
return this.location;
}
public void addLocation(LocationType loc){
if(!locationMap.containsKey (loc)){
this.locationMap.put (loc.getId ( ), loc);
if (location == null) {
location = new ArrayList<LocationType>();
}
this.location.add(loc);
}
}
public LocationType getLocationFromMap(String LocationId){
return locationMap.get (LocationId);
}
/**
* Gets the value of the startTime property.
*
* @return
* possible object is
* {@link XMLGregorianCalendar }
*
*/
public XMLGregorianCalendar getStartTime() {
return startTime;
}
/**
* Sets the value of the startTime property.
*
* @param value
* allowed object is
* {@link XMLGregorianCalendar }
*
*/
public void setStartTime(XMLGregorianCalendar value) {
this.startTime = value;
}
@Override
public int compareTo (IntervalType o)
{
// TODO Auto-generated method stub
return startTime.compare (o.getStartTime ( ));
}