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
.session
;
21 import java
.io
.IOException
;
22 import java
.util
.HashMap
;
24 import com
.dtrules
.entity
.REntity
;
25 import com
.dtrules
.infrastructure
.RulesException
;
26 import com
.dtrules
.interpreter
.IRObject
;
27 import com
.dtrules
.interpreter
.RName
;
28 import com
.dtrules
.xmlparser
.IGenericXMLParser
;
30 @SuppressWarnings({"unchecked"})
31 public class EDDLoader
implements IGenericXMLParser
{
33 final EntityFactory ef
;
34 final String filename
;
35 boolean succeeded
= true;
36 String errorMsgs
= "";
38 EDDLoader(String _filename
, EntityFactory _ef
){
44 * If this string has a non-zero length, the EDD did not load
45 * properly. The caller is responsible for checking this. Otherwise
46 * the loader can only report a single error.
52 public String
getErrorMsgs() {
59 public void beginTag(String
[] tagstk
, int tagstkptr
, String tag
,
60 HashMap attribs
) throws IOException
, Exception
{
63 public void endTag(String
[] tagstk
,
67 HashMap attribs
) throws Exception
, IOException
{
69 if(tag
.equals("entity")){
70 String entityname
= (String
) attribs
.get("entityname");
71 String attribute
= (String
) attribs
.get("attribute");
72 String type
= (String
) attribs
.get("type");
73 String subtype
= (String
) attribs
.get("subtype");
74 String access
= (String
) attribs
.get("access");
75 String defaultv
= (String
) attribs
.get("default");
77 boolean writeable
= true; // We need to convert access to a boolean
78 boolean readable
= true; // Make an assumption of r/w
79 int itype
= -1; // We need to convert the type to an int.
80 IRObject defaultO
= null; // We need to convert the default into a Rules Engine Object.
82 //First deal with the access thing... Compute the boolean we need.
83 if(access
==null){ // Check to see if we need to handle TIERS EDD files.
84 access
= (String
) attribs
.get("cdd_i_c_flag");
86 writeable
= access
.toLowerCase().indexOf("i")<0;
88 }else{ // Nope? Then handle the more rational DTRules EDD files
89 writeable
= access
.toLowerCase().indexOf("w")>=0;
90 readable
= access
.toLowerCase().indexOf("r")>=0;
91 if(!writeable
&& !readable
){
92 errorMsgs
+="\nThe attribute "+attribute
+" has to be either readable or writable\r\n";
97 // Now the type. An easy thing.
99 itype
= RSession
.typeStr2Int(type
,entityname
,attribute
);
100 } catch (RulesException e1
) {
101 errorMsgs
+= e1
.getMessage()+"\n";
105 // Now deal with the default specified.
106 if (defaultv
==null){ // Do we need to handle TIERS EDD files?
107 defaultv
= (String
) attribs
.get("cdd_default_value");
110 defaultO
= EntityFactory
.computeDefaultValue(ef
, ef
.ruleset
, defaultv
, itype
) ;
112 RName entityRName
= RName
.getRName(entityname
.trim(),false);
113 RName attributeRName
= RName
.getRName(attribute
.trim(),false);
114 REntity entity
= ef
.findcreateRefEntity(false,entityRName
);
117 intType
= RSession
.typeStr2Int(type
,entityname
,attribute
);
118 } catch (RulesException e
) {
119 errorMsgs
+= "Bad Type: '"+type
+"' encountered on entity: '"+entityname
+"' attribute: '"+attribute
+"' \n";
122 String errstr
= entity
.addAttribute(attributeRName
,
134 //else if(tag.equals("obj")){
135 // String javaclass = (String)attribs.get("class");
136 // Class javaobj = getClass().getClassLoader().loadClass(javaclass);
137 //new REntityWrapper(ef,javaobj,false,RName.getRName(body));
142 public boolean error(String v
) throws Exception
{