initial load
[DTRules.git] / DTRules / src / main / java / com / dtrules / entity / REntityEntry.java
blob707412ab37eab4e184789eea00a84577ee95f580
1 /*
2 * $Id$
3 *
4 * Copyright 2004-2007 MTBJ, Inc.
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
19 package com.dtrules.entity;
21 import com.dtrules.infrastructure.RulesException;
22 import com.dtrules.interpreter.IRObject;
23 import com.dtrules.interpreter.RName;
24 import com.dtrules.session.RSession;
26 /**
28 * A Entry holds the attribute type and attribute value as held in an
29 * Entity. Past implementations of the Rules Engine used a separate
30 * Attribute and Value hashmaps. However, too many operations require
31 * both an inspection of the attribute as well as the value. So now
32 * I have one hashmap for the attribute, which provides an index into
33 * an ArrayList to get the value.
35 * @author Paul Snow
38 public class REntityEntry {
39 public REntity entity; // The entity involved.
40 public RName attribute; // The name of this attribute.
41 public String defaulttxt; // Text for the default value.
42 public IRObject defaultvalue; // Every Entry has default value, which may be null.
43 public boolean writable; // We allow Entries to be locked.
44 public boolean readable; // We allow some Entries to be write only.
45 public int type; // The type value, i.e. integer, float, etc. as defined
46 // by IRObject
47 public String subtype; // The Subtype (for some kinds of attributes)...
48 public int index; // Index into the values array to get the current
49 // value for this attribute.
50 public String typeValue;
52 /**
53 * Allows the insertion of the REntityEntry into an Entity after the
54 * fact.
55 * @param newIndex The index into the values array where the value of this attribute can be found.
57 void updateIndex(int newIndex){
58 index = newIndex;
61 REntityEntry(
62 REntity _entity,
63 RName _attribute,
64 String _defaulttxt,
65 IRObject _defaultvalue,
66 boolean _writable,
67 boolean _readable,
68 int _type,
69 String _subtype,
70 int _index){
71 attribute = _attribute;
72 defaulttxt = _defaulttxt;
73 defaultvalue = _defaultvalue;
74 writable = _writable;
75 readable = _readable;
76 type = _type;
77 subtype = _subtype;
78 index = _index;
81 @Override
82 public String toString() {
83 String thetype="";
84 try{
85 thetype = "("+RSession.typeInt2Str(type)+")";
86 }catch(Exception e){}
87 return thetype +" default: "+defaulttxt;
90 /**
91 * @return the attribute
93 public RName getAttribute() {
94 return attribute;
97 /**
98 * @param attribute the attribute to set
100 public void setAttribute(RName attribute) {
101 this.attribute = attribute;
105 * @return the defaulttxt
107 public String getDefaulttxt() {
108 return defaulttxt;
112 * @param defaulttxt the defaulttxt to set
114 public void setDefaulttxt(String defaulttxt) {
115 this.defaulttxt = defaulttxt;
119 * @return the defaultvalue
121 public IRObject getDefaultvalue() {
122 return defaultvalue;
126 * @param defaultvalue the defaultvalue to set
128 public void setDefaultvalue(IRObject defaultvalue) {
129 this.defaultvalue = defaultvalue;
133 * @return the type
135 public int getType() {
136 return type;
140 * @param type the type to set
142 public void setType(int type) throws RulesException {
143 this.type = type;
144 setTypeValue(RSession.typeInt2Str(type));
148 * @return the writable
150 public boolean isWritable() {
151 return writable;
155 * @param writable the writable to set
157 public void setWritable(boolean writable) {
158 this.writable = writable;
161 public String getTypeValue() throws RulesException {
162 if(typeValue==null)typeValue=RSession.typeInt2Str(type);
163 return typeValue;
166 public void setTypeValue(String typeValue) throws RulesException{
167 this.typeValue = typeValue;
168 setType(RSession.typeStr2Int(typeValue,entity.getName().stringValue(),attribute.stringValue()));
171 public String getAttributeStrValue() {
172 return attribute.stringValue();
175 public void setAttributeStrValue(String attributeStrValue) {
176 setAttribute(RName.getRName(attributeStrValue));
179 public final int getIndex() {
180 return index;
183 public final void setIndex(int index) {
184 this.index = index;
188 * @return the subtype
190 public String getSubtype() {
191 return subtype;