101 lines
2.3 KiB
Java
101 lines
2.3 KiB
Java
package org.hwo.servicelink.register;
|
|
|
|
import javax.xml.xpath.XPath;
|
|
import javax.xml.xpath.XPathConstants;
|
|
import javax.xml.xpath.XPathFactory;
|
|
|
|
import org.w3c.dom.Element;
|
|
import org.w3c.dom.Node;
|
|
|
|
public class RegisterType implements Cloneable{
|
|
|
|
XPath xpath;
|
|
|
|
String name;
|
|
String baseName;
|
|
|
|
boolean wantsFloat;
|
|
|
|
protected RegisterType(String name){
|
|
this.name = name;
|
|
this.baseName = "";
|
|
this.wantsFloat = false;
|
|
xpath = XPathFactory.newInstance().newXPath();
|
|
}
|
|
|
|
protected XPath getXPath(){
|
|
return xpath;
|
|
}
|
|
|
|
public String getBaseName() {
|
|
return baseName;
|
|
}
|
|
protected void setBaseName(String baseName) {
|
|
this.baseName = baseName;
|
|
}
|
|
public String getName() {
|
|
return name;
|
|
}
|
|
protected void setName(String name) {
|
|
this.name = name;
|
|
}
|
|
public boolean getWantsFloat() {
|
|
return wantsFloat;
|
|
}
|
|
protected void setWantsFloat(boolean wantsFloat) {
|
|
this.wantsFloat = wantsFloat;
|
|
}
|
|
|
|
public void createFromTypeNode(Node typeNode){
|
|
};
|
|
|
|
public RegisterType inherit(String newName){
|
|
try {
|
|
RegisterType inherited = (RegisterType)this.clone();
|
|
|
|
inherited.setBaseName(getName());
|
|
inherited.setName(newName);
|
|
|
|
return inherited;
|
|
} catch (CloneNotSupportedException e) {
|
|
e.printStackTrace();
|
|
return null;
|
|
}
|
|
}
|
|
|
|
public RegisterType createRegisterTypeInstance(ServiceRegisterList serviceRegisterList,Node registerNode){
|
|
try {
|
|
Node aNode = (Node)getXPath().evaluate("Address", registerNode, XPathConstants.NODE);
|
|
RegisterType rt = inherit(String.format("%s/%s/%s",serviceRegisterList.id,getName(),aNode.getFirstChild().getNodeValue()));
|
|
return rt;
|
|
} catch (Exception e){
|
|
e.printStackTrace();
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public String getDisplayValue(Object regValue){
|
|
return "-- REGISTER TYPE NOT IMPLEMENTED --";
|
|
}
|
|
|
|
|
|
protected java.lang.Integer valueAsInteger(Object regValue){
|
|
if (java.lang.Integer.class.isInstance(regValue)){
|
|
return (java.lang.Integer)regValue;
|
|
} else if (java.lang.Float.class.isInstance(regValue)){
|
|
return ((java.lang.Float)regValue).intValue();
|
|
};
|
|
return null;
|
|
}
|
|
|
|
protected java.lang.Float valueAsFloat(Object regValue){
|
|
if (java.lang.Float.class.isInstance(regValue)){
|
|
return (java.lang.Float)regValue;
|
|
} else if (java.lang.Integer.class.isInstance(regValue)){
|
|
return ((java.lang.Integer)regValue).floatValue();
|
|
};
|
|
return null;
|
|
}
|
|
|
|
}
|