今天在使用castor需要用多态映射(我不知是不是这个叫法:)),网上找了很多资料,然后终于找到一篇差不多的资料,下面是一个例子
public class PageControl {
/**
* 控件类型
*/
protected String type;
/**
* 控件标签
*/
protected String label;
/**
* 控件名
*/
protected String name;
/**
* 控件值
*/
protected String value;
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getLabel() {
return label;
}
public void setLabel(String label) {
this.label = label;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
}
public class Radio extends PageControl {
public Radio(){
this.type="radio";
}
private String viewLabel;
public String getViewLabel() {
return viewLabel;
}
public void setViewLabel(String viewLabel) {
this.viewLabel = viewLabel;
}
}
public class Text extends PageControl {
public Text(){
this.type="text";
}
}
xml的配置如下:
<bind-xml auto-naming="deriveByClass" node="element" location="fieldControlTypeMap"></bind-xml>
</field>
<field name="type" type="string" >
<bind-xml name="type" node="attribute"/>
</field>
<field name="label" type="string" >
<bind-xml name="label" node="attribute"/>
</field>
<field name="name" type="string" >
<bind-xml name="name" node="attribute"/>
</field>
<field name="value" type="string" >
<bind-xml name="value" node="attribute"/>
</field>
</class>
<class name="com.ssgm.jaoe.generator.control.Text" extends="com.ssgm.jaoe.generator.control.PageControl">
<map-to xml="text"/>
</class>
<class name="com.ssgm.jaoe.generator.control.Radio" extends="com.ssgm.jaoe.generator.control.PageControl">
<map-to xml="radio"/>
</class>