1 package com.daffodilwoods.daffodildb.utils.parser; 2 3 import java.lang.reflect.Field ; 4 import com.daffodilwoods.database.utility.P; 5 import com.daffodilwoods.database.resource.*; 6 7 10 11 public class KeyWordProductionRules 12 extends StringProductionRules { 13 14 private static char[] reserveWord = new char[] { 15 '+', '-', '*', '/', '=', '<', '>', '!', 13}; 16 17 public KeyWordProductionRules(ClassLoader classLoader0) { 18 super(classLoader0); 19 } 20 21 25 26 Object parsePart(ParseElements pe) throws DException { 27 if (pe.position >= pe.query.length() || pe.recursiveObject != null) { 28 pe.parseException.setPosition(pe.getIndexPosition(pe.position)); 29 return pe.parseException; 30 } 31 while (Character.isWhitespace(pe.queryArray[pe.position])) { 32 pe.position++; 33 } 34 Object ob = parseComments(pe); 35 if(ob instanceof ParseException ) 36 return ob; 37 int prevPosition = pe.position = ((Integer )ob).intValue() ; 38 39 41 int cmp1[] = checkString(pe.queryArray, string, pe.position); 42 int cmp = cmp1[0]; 43 boolean delimeter = false; 44 if (cmp == 0) { 45 pe.position += ((String )result).length(); 46 if (pe.position <= pe.queryArray.length - 1) 47 delimeter = checkForDelimeters(pe); 48 49 if (delimeter) { 50 return getObjectOfClass(new String (pe.queryArray, prevPosition,pe.position- prevPosition)); 51 } 52 if (pe.position == pe.queryArray.length) { 53 String saq = new String (pe.queryArray, prevPosition, 54 pe.position - prevPosition); 55 return getObjectOfClass(saq); 56 } 57 } 58 cmp = cmp > 0 ? 1 : cmp < 0 ? -1 : 0; 59 if (!delimeter && (cmp == 0)) { 60 pe.position -= ( ( (String ) result).length() + cmp1[1]); 61 cmp = 2; 62 } 63 pe.parseException.setReturnType(cmp); 64 pe.parseException.setPosition(pe.getIndexPosition(pe.position)); 65 return pe.parseException; 66 } 67 68 69 74 private int[] checkString(char[] source, char[] target, int position) { int compare = 0, i = position; 76 for (int j = 0; i < source.length && j < target.length && compare == 0; ++j, 77 ++i) { 78 79 85 86 if (source[i] >= 97 && source[i] < 123) 87 compare = (source[i] - 32) - target[j]; 88 else 89 compare = source[i] - target[j]; 90 } 91 92 93 return new int[] { 94 compare,0}; 95 } 96 97 100 private boolean checkForDelimeters(ParseElements pe) { 101 for (int i = 0; i < delimitedTokens.length; ++i) { 102 if (pe.queryArray[pe.position] == delimitedTokens[i]) 103 return true; 104 } 105 for (int i = 0; i < reserveWord.length; ++i) { 106 if (pe.queryArray[pe.position] == reserveWord[i]) 107 return true; 108 } 109 return false; 110 } 111 112 public String toString() { 113 return nameOfRule; 114 } 115 116 public int hashCode() { 117 return keyWord.hashCode(); 118 } 119 120 Object getObjectOfClass(Object parsedObject) throws DException { 121 Object tempObject = null; 122 int i = 0; 123 try { 124 if (classMaker == null) { 125 try { 126 Class cls = classLoader.loadClass(className); 127 loadFields(i,cls); 128 classMaker = cls; 129 } 130 catch (NoClassDefFoundError ne) { 131 throw ne; 132 } 133 } 134 135 tempObject = classMaker.newInstance(); 136 ( (Field ) fields[0]).set(tempObject, parsedObject); 137 } 138 catch (Exception E) { 139 throw new DException("DSE0",new Object []{E.getMessage() }); 140 141 } 142 return tempObject; 143 } 144 145 154 } 155 | Popular Tags |