1 package com.daffodilwoods.daffodildb.utils.parser; 2 3 import com.daffodilwoods.database.utility.P; 4 import java.lang.reflect.Field ; 5 import com.daffodilwoods.daffodildb.utils.DBStack; 6 import com.daffodilwoods.database.resource.*; 7 8 public class SimpleProductionRules extends ProductionRules{ 9 10 SimpleProductionRules(ClassLoader classLoader0){ 11 super(classLoader0); 12 } 13 14 public String toString(){ 15 return nameOfRule; 16 } 17 18 Object 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 [] parsedObject = new Object []{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 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 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 getComparableObjectArray(){ 47 if ( rules == null ) 48 return null; 49 ProductionRules object = (ProductionRules)rules[0]; 50 Object o[] = (Object [])object.getComparableObjectArray(); 51 if ( o != null ) 52 result = object.result; 53 return o; 54 } 55 56 public Object getRecursiveObject(String 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 []{this}; 62 return null; 63 } 64 65 public Object getNonRecursiveObject(String 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 []{this}; 71 return null; 72 } 73 74 Object getObjectOfClass(Object parsedObject) throws DException{ 75 Object tempObject = null; 76 int i = 0; 77 try{ 78 if ( classMaker == null ){ 79 try{ 80 91 Class cls = classLoader.loadClass(className); 92 loadFields(i,cls); 93 classMaker = cls; 94 95 }catch(NoClassDefFoundError ne){ 96 throw ne; 97 } 98 } 99 100 tempObject = classMaker.newInstance(); 101 ((Field )fields[0]).set(tempObject,parsedObject); 102 }catch(Exception E){ 103 throw new DException("DSE0",new Object []{E.getMessage() }); 104 } 105 return tempObject; 106 } 107 } 108 109 110 | Popular Tags |