1 package com.daffodilwoods.daffodildb.utils.parser; 2 3 import java.util.ArrayList ; 4 import com.daffodilwoods.database.utility.P; 5 import java.lang.reflect.Field ; 6 import com.daffodilwoods.daffodildb.utils.DBStack; 7 import com.daffodilwoods.database.resource.*; 8 9 public class StringProductionRules extends ProductionRules{ 10 11 public String XYZ = "XYZ"; 13 char[] string; 14 String keyWord; 15 16 StringProductionRules(ClassLoader classLoader0){ 17 super(classLoader0); 18 } 19 20 public void setString(String result1,String keyWord0){ 21 this.result = result1.equalsIgnoreCase("'\\u0020'") ? " " : result1; 22 XYZ = (String )this.result; 23 this.keyWord = keyWord0; 24 ArrayList rules = new ArrayList (); 25 String xyz = nameOfRule == null ? (String )this.result : nameOfRule; 26 if ( keyWord == null ){ 27 rules.add(xyz); 28 this.keyWord = nameOfRule; 29 } 30 else 31 rules.add(keyWord); 32 super.setProductionRules(rules); 33 string = ((String )result).toCharArray(); 34 } 35 36 Object parsePart(ParseElements pe) throws DException{ 37 if(pe.position >= pe.query.length() || pe.recursiveObject != null){ 38 pe.parseException.setPosition(pe.getIndexPosition(pe.position)); 39 return pe.parseException; 40 } 41 42 Object ob = parseComments(pe); 43 if(ob instanceof ParseException ) 44 return ob; 45 pe.position = ((Integer )ob).intValue() ; 46 48 49 50 int cmp = checkString(pe.queryArray,string,pe.position); 51 if ( cmp == 0 ) { 52 pe.position += ((String )result).length(); 53 if ( pe.position <= pe.queryArray.length){ 54 return getObjectOfClass(result); 55 } 56 } 57 cmp = cmp > 0 ? 1 : cmp < 0 ? -1 : 0; 58 pe.parseException.setReturnType(cmp); 59 pe.parseException.setPosition(pe.getIndexPosition(pe.position)); 60 return pe.parseException; 61 } 62 63 public void setProductionRuleName(String nameOfRule1){ 64 String name = nameOfRule1.trim(); 65 StringBuffer name1 = new StringBuffer ("S"); 66 name1.append(name).append(name.hashCode()); 67 super.setProductionRuleName(name1.toString()); 68 } 69 70 private int checkString(char []source, char[] target,int position){ 71 int compare = 0; 72 int i = position; 73 for(int j = 0; i < source.length && j < target.length && compare == 0; ++j,++i) 74 compare = source[i] - target[j]; 75 return compare; 76 } 77 78 public Object getComparableObject(){ 79 String result1 = (String )this.result; 80 if ( result1.equalsIgnoreCase(">=") || result1.equalsIgnoreCase("<=") || 81 result1.equalsIgnoreCase("<>") || result1.equalsIgnoreCase("!=") || 82 result1.equalsIgnoreCase("==") || result1.equalsIgnoreCase("&&") || 83 result1.equalsIgnoreCase("||") ) 84 return null; 85 return result1; 86 } 87 88 public Object getComparableObjectArray(){ 89 return new String []{nameOfRule}; 90 } 91 92 93 public String toString(){ 94 return new StringBuffer ("[").append(nameOfRule).append("] SPR [").append(result).append("]").toString(); 95 } 96 97 public Object getRecursiveObject(String nameOfRule,DBStack occuredRules){ 98 if ( this.nameOfRule.equalsIgnoreCase(nameOfRule) ) 99 return new Object []{this}; 100 return null; 101 } 102 103 public Object getNonRecursiveObject(String nameOfRule,DBStack occuredRules){ 104 if ( !(this.nameOfRule.equalsIgnoreCase(nameOfRule)) ) 105 return new Object []{this}; 106 return null; 107 } 108 109 public int hashCode(){ 110 return result.hashCode(); 111 } 112 113 Object getObjectOfClass(Object parsedObject) throws DException{ 114 Object tempObject = null; 115 int i = 0; 116 try{ 117 if ( classMaker == null ){ 118 try{ 119 Class cls = classLoader.loadClass(className); 120 121 loadFields(i,cls); 122 classMaker = cls; 123 }catch(NoClassDefFoundError ne){ 124 throw ne; 125 } 126 } 127 128 tempObject = classMaker.newInstance(); 129 130 ((Field )fields[0]).set(tempObject,parsedObject); 131 }catch(Exception E){ 132 throw new DException("DSE0",new Object []{E.getMessage() }); 133 134 } 135 return tempObject; 136 } 137 } 138 | Popular Tags |