KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > daffodilwoods > daffodildb > utils > parser > SimpleProductionRulesWithHashMap


1 package com.daffodilwoods.daffodildb.utils.parser;
2
3 import com.daffodilwoods.database.utility.P;
4 import java.lang.reflect.Field JavaDoc;
5 import com.daffodilwoods.daffodildb.utils.DBStack;
6 import com.daffodilwoods.database.resource.*;
7
8 public class SimpleProductionRulesWithHashMap extends ProductionRulesWithHashMap{
9
10   SimpleProductionRulesWithHashMap(ClassLoader JavaDoc classLoader0){
11     super(classLoader0);
12   }
13
14    public String JavaDoc toString(){
15       return nameOfRule;
16    }
17
18    Object JavaDoc parsePart(ParseElements pe)throws com.daffodilwoods.database.resource.DException{
19       ProductionRules object = (ProductionRules)rules[0];
20       String JavaDoc ruleName = object.getProductionRuleName();
21       if (ruleName.equalsIgnoreCase(pe.recursionState) && object.recursiveflag ){
22          if(pe.recursiveObject != null){
23             Object JavaDoc[] parsedObject = new Object JavaDoc[]{pe.recursiveObject};
24             pe.recursiveObject = null;
25             pe.recursionState = null;
26             return parsedObject;
27          }
28          else
29               return pe.parseException;
30       }
31       else if(pe.recursiveObject != null && !ruleName.equalsIgnoreCase(pe.recursionState))
32          return pe.parseException;
33       Object JavaDoc value = object.parse(pe);
34       if(!(value instanceof ParseException)){
35          return ruleKey.startsWith("Rep")? value : getObjectOfClass(value);
36       }
37       return pe.parseException;
38    }
39
40    public Object JavaDoc getComparableObject(){
41       if ( rules == null )
42          return null;
43       ProductionRules object = (ProductionRules)rules[0];
44       result = object.result;
45       return object.getComparableObject();
46    }
47
48    public Object JavaDoc getComparableObjectArray(){
49       if ( rules == null )
50          return null;
51       ProductionRules object = (ProductionRules)rules[0];
52       Object JavaDoc o[] = (Object JavaDoc [])object.getComparableObjectArray();
53       if ( o != null )
54         result = object.result;
55       return o;
56    }
57
58    public Object JavaDoc getRecursiveObject(String JavaDoc nameOfRule,DBStack occuredRules){
59       if ( rules == null )
60          return null;
61       ProductionRules rule = (ProductionRules)rules[0];
62       if ( rule.nameOfRule.equalsIgnoreCase(nameOfRule) )
63          return new Object JavaDoc[]{this};
64       return null;
65   }
66
67   public Object JavaDoc getNonRecursiveObject(String JavaDoc nameOfRule,DBStack occuredRules){
68       if ( rules == null )
69          return null;
70        ProductionRules rule = (ProductionRules)rules[0];
71        if ( !(rule.nameOfRule.equalsIgnoreCase(nameOfRule)) )
72          return new Object JavaDoc[]{this};
73        return null;
74  }
75
76    Object JavaDoc getObjectOfClass(Object JavaDoc parsedObject) throws DException{
77       Object JavaDoc tempObject = null;
78       int i = 0;
79       try{
80          if ( classMaker == null ){
81            try{ /* here using cls variable for comments refer to getObjectOfClass method of SimpleProductionRules */
82              Class JavaDoc cls = classLoader.loadClass(className);
83              loadFields(i,cls);
84              classMaker = cls;
85
86             }catch(NoClassDefFoundError JavaDoc ne){
87                throw ne;
88             }
89          }
90          /* Done by Kaushik on 09/09/2004 as part of Parser Optimization */
91          tempObject = classMaker.newInstance();
92          ((Field JavaDoc)fields[0]).set(tempObject,parsedObject);
93       }catch(Exception JavaDoc E){
94             throw new DException("DSE0",new Object JavaDoc[]{E.getMessage() });
95
96       }
97       return tempObject;
98    }
99 }
100
101
Popular Tags