4 * Copyright 2004-2007 MTBJ, Inc.
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
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.
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
;
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.
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
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
;
53 * Allows the insertion of the REntityEntry into an Entity after the
55 * @param newIndex The index into the values array where the value of this attribute can be found.
57 void updateIndex(int newIndex
){
65 IRObject _defaultvalue
,
71 attribute
= _attribute
;
72 defaulttxt
= _defaulttxt
;
73 defaultvalue
= _defaultvalue
;
82 public String
toString() {
85 thetype
= "("+RSession
.typeInt2Str(type
)+")";
87 return thetype
+" default: "+defaulttxt
;
91 * @return the attribute
93 public RName
getAttribute() {
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() {
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() {
126 * @param defaultvalue the defaultvalue to set
128 public void setDefaultvalue(IRObject defaultvalue
) {
129 this.defaultvalue
= defaultvalue
;
135 public int getType() {
140 * @param type the type to set
142 public void setType(int type
) throws RulesException
{
144 setTypeValue(RSession
.typeInt2Str(type
));
148 * @return the writable
150 public boolean isWritable() {
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
);
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() {
183 public final void setIndex(int index
) {
188 * @return the subtype
190 public String
getSubtype() {