Good day, everyone. I was searching answer to my question in web, but I failed.. I have workaround, but just wondering, is it possible to do something like this: I have an *.xml:
<fileconfiguration>
<attr name="example1" type="sql" value="select value from A where id=?" priority="1"/>
<attr name="example2" type="text" value="val2" priority="2"/>
</fileconfiguration>
I want to unmarshall that xml, but instead of having sql query in a “value” field of the object, I what to evaluate the value with parameter which is known before unmarshalling and it is unique for all objects in that xml.
@XmlRootElement(name = "fileconfiguration")
@XmlAccessorType(XmlAccessType.FIELD)
public class UNIFileConfiguration {
@XmlElement(name = "attr", type = Attr.class)
public Set<Attr> attrs = new TreeSet<Attr>();
public FileConfiguration() {
}
public FileConfiguration(Set<Attr> attrs) {
this.attrs = attrs;
}
public void setAttrs(Set<Attr> attrs) {
this.attrs = attrs;
}
public Set getAttrs() {
return this.etlAttributes;
}
}
And the POJO class for Attr section:
@XmlRootElement(name = "attr")
public class Attr implements Comparable<Attr>{
private String name;
private String type;
private String value;
private int priority;
private static BigInteger id;
public Attr() {}
public Attr(BigInteger id){this.id=id;}
public String getName() { return name;}
@XmlAttribute
public void setName(String name) {this.name = name;}
public String getType() {return type;}
@XmlAttribute
public void setType(String type) {this.type = type; }
public String getValue() { return value;}
@XmlAttribute
public void setValue(String value) {
String str = StringUtils.EMPTY;
if("text".equals(this.type)){str=value}
if("sql".equals(this.type)){str=evaluateSQL(value, this.parameter)}
this.value=str;
}
public int getPriority() {return priority;}
@XmlAttribute
public void setPriority(int priority) {this.priority = priority;}
public String toString() {return "name: " + this.name;}
public int compareTo(Attr o) {return this.priority - o.getPriority();}
}
is it possible to pass an external parameter so JAXB knows it at unmarshalling step?
No comments:
Post a Comment