KickJava   Java API By Example, From Geeks To Geeks.

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


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 SimpleProductionRules extends ProductionRules{
9
10   SimpleProductionRules(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       if (nameOfRule.equalsIgnoreCase(pe.recursionState) && object.recursiveflag ){
21          if(pe.recursiveObject != null){
22             Object JavaDoc[] parsedObject = new Object JavaDoc[]{pe.recursiveObject};
23             pe.recursiveObject = null;
24             pe.recursionState = null;
25             return parsedObject;
26          }
27          else
28               return pe.parseException;
29       }
30       else if(pe.recursiveObject != null && !nameOfRule.equalsIgnoreCase(pe.recursionState))
31          return pe.parseException;
32        Object JavaDoc value = object.parse(pe);
33        if(!(value instanceof ParseException))
34          return ruleKey.startsWith("Rep")? value : getObjectOfClass(value);
35       return pe.parseException;
36    }
37
38    public Object JavaDoc getComparableObject(){
39       if ( rules == null )
40          return null;
41       ProductionRules object = (ProductionRules)rules[0];
42       result = object.result;
43       return object.getComparableObject();
44    }
45
46    public Object JavaDoc getComparableObjectArray(){
47       if ( rules == null )
48          return null;
49       ProductionRules object = (ProductionRules)rules[0];
50       Object JavaDoc o[] = (Object JavaDoc [])object.getComparableObjectArray();
51       if ( o != null )
52         result = object.result;
53       return o;
54    }
55
56   public Object JavaDoc getRecursiveObject(String JavaDoc nameOfRule,DBStack occuredRules){
57       if ( rules == null )
58          return null;
59       ProductionRules rule = (ProductionRules)rules[0];
60       if ( rule.ruleKey.equalsIgnoreCase(nameOfRule) )
61          return new Object JavaDoc[]{this};
62       return null;
63   }
64
65   public Object JavaDoc getNonRecursiveObject(String JavaDoc nameOfRule,DBStack occuredRules){
66       if ( rules == null )
67          return null;
68        ProductionRules rule = (ProductionRules)rules[0];
69        if ( !(rule.ruleKey.equalsIgnoreCase(nameOfRule)) )
70          return new Object JavaDoc[]{this};
71        return null;
72   }
73
74   Object JavaDoc getObjectOfClass(Object JavaDoc parsedObject) throws DException{
75       Object JavaDoc tempObject = null;
76       int i = 0;
77       try{
78          if ( classMaker == null ){
79             try{
80               /**
81                 * Here we are getting class in other variable instead of classMaker
82                 * because if we take it directly than in multi threading if first thread
83                 * is loaded class and we initialize classMaker and suppose a second
84                 * thread is on check of if now classMaker is not null and first thread
85                 * is loading fields but second thread is continue after varification of
86                 * classMaker is not null now it gets fields as null.
87                 * So here we initialize classMaker after loading fields and also pass
88                 * class in loadFields method and now it throws Dexception also which
89                 * after catching any exception which is earlier dumped.
90                 */

91                Class JavaDoc cls = classLoader.loadClass(className);
92                 loadFields(i,cls);
93                 classMaker = cls;
94
95             }catch(NoClassDefFoundError JavaDoc ne){
96                throw ne;
97             }
98          }
99          /* Done by Kaushik on 09/09/2004 as part of Parser Optimization */
100          tempObject = classMaker.newInstance();
101          ((Field JavaDoc)fields[0]).set(tempObject,parsedObject);
102       }catch(Exception JavaDoc E){
103             throw new DException("DSE0",new Object JavaDoc[]{E.getMessage() });
104       }
105       return tempObject;
106    }
107 }
108
109
110
Popular Tags