Updated error messages when an error occurs within an executable array
[DTRules.git] / DTRules / src / main / java / com / dtrules / interpreter / RXmlValue.java
blob6004ca8abe5bfd8207b10409df043f24c0666198
1 /**
2 *
3 */
4 package com.dtrules.interpreter;
6 import java.util.ArrayList;
7 import java.util.Date;
8 import com.dtrules.infrastructure.RulesException;
9 import com.dtrules.mapping.XMLTag;
10 import com.dtrules.session.DTState;
12 /**
13 * @author paul snow
15 * An XmlValue object represents a node in the XML input stream that
16 * supplied data to the Rules Engine. It provides a way to update
17 * and modify that XML based on rules defined in Decision Tables.
20 public class RXmlValue extends ARObject {
21 XMLTag tag;
22 DTState state;
23 int id;
25 public RXmlValue(DTState state, XMLTag tag){
26 this.tag = tag;
27 id = state.getSession().getUniqueID();
30 /**
31 * Sets the value of an Attribute on the tag for this RXmlValue.
33 * @param attribute
34 * @param value
36 public void setAttribute(String attribute, String value){
37 tag.getAttribs().put(attribute, value);
40 /**
41 * Gets the value of an Attribute on the tag for this RXmlValue.
42 * Returns a null if the Attribute isn't defined on this tag.
43 * @param attribute
44 * @param value
46 public String getAttribute(String attribute){
47 if(!tag.getAttribs().containsKey(attribute)){
48 return null;
50 return tag.getAttribs().get(attribute).toString();
53 /**
54 * The following are all the accessors that are suppored
55 * for working with RXmlValue objects
58 /**
59 * The string value of an XMLTag is its body value
61 public String stringValue() {
62 return tag.getBody().toString();
64 public int type() {
65 return iXmlValue;
68 public ArrayList<IRObject> arrayValue() throws RulesException {
69 ArrayList<IRObject> a = new ArrayList<IRObject>();
70 if(tag.getTags().size()>0){
71 for(XMLTag t : tag.getTags()){
72 a.add(new RXmlValue(state,t));
75 return a;
78 @Override
79 public boolean booleanValue() throws RulesException {
80 return RBoolean.booleanValue(tag.getBody().toString());
83 @Override
84 public double doubleValue() throws RulesException {
85 return RDouble.getDoubleValue(tag.getBody().toString());
88 @Override
89 public boolean equals(IRObject o) throws RulesException {
90 return rStringValue().equals(o);
93 @Override
94 public int intValue() throws RulesException {
95 return (int)RInteger.getIntegerValue(tag.getBody().toString());
99 @Override
100 public long longValue() throws RulesException {
101 return RInteger.getIntegerValue(tag.getBody().toString());
104 @Override
105 public RBoolean rBooleanValue() throws RulesException {
106 return RBoolean.getRBoolean(booleanValue());
109 @Override
110 public RDouble rDoubleValue() throws RulesException {
111 return RDouble.getRDoubleValue(doubleValue());
114 @Override
115 public RInteger rIntegerValue() throws RulesException {
116 return RInteger.getRIntegerValue(longValue());
119 @Override
120 public RName rNameValue() throws RulesException {
121 return RName.getRName(stringValue(),false);
124 public RString rStringValue() {
125 return RString.newRString(stringValue());
128 public RTime rTimeValue() throws RulesException {
129 return RTime.getRTime(timeValue());
132 public Date timeValue() throws RulesException {
133 return RTime.getDate(tag.getBody().toString());
136 /* (non-Javadoc)
137 * @see com.dtrules.interpreter.ARObject#rXmlValue()
139 @Override
140 public RXmlValue rXmlValue() throws RulesException {
141 return this;
144 /* (non-Javadoc)
145 * @see com.dtrules.interpreter.ARObject#xmlTagValue()
147 @Override
148 public XMLTag xmlTagValue() throws RulesException {
149 return tag;