1 package com.daffodilwoods.daffodildb.utils.parser; 2 3 import java.util.*; 4 import com.daffodilwoods.database.resource.*; 5 6 public class Parser { 7 8 static ProductionRules productionRules; 9 static ProductionRules bveRule1; 10 static ProductionRules defaultOption; 11 static ProductionRules triggeredSQL; 12 13 public Parser() { 14 } 15 16 public static ProductionRules findProductionRule(String ruleToFind) throws DException{ 17 initialisePR(); 18 HashMap arr = new HashMap(); 19 ProductionRules pre = findProductionRule(ruleToFind,productionRules,arr); 20 ProductionRules ttt = (ProductionRules) arr.get("999"); 21 ttt.tokenRule = productionRules.tokenRule; 22 ttt.hashMap = productionRules.hashMap; 23 return ttt; 24 } 25 26 private static ProductionRules findProductionRule(String ruleToFind,ProductionRules pr, HashMap arr) { 27 String name1 = pr.nameOfRule; 28 ProductionRules tttt = (ProductionRules)arr.get(name1); 29 if (tttt != null) { 30 return tttt; 31 } 32 if (name1.equalsIgnoreCase(ruleToFind)) { 33 arr.put("999", pr); 34 return pr; 35 } 36 arr.put(name1,pr); 37 ProductionRules ttt = (ProductionRules) arr.get("999"); 38 if (ttt != null) { 39 return ttt; 40 } 41 Object array[] = pr.rules; 42 array = array == null ? new ProductionRules[0] : array; 43 for (int i = 0 ; i < array.length ; i++) { 44 if (array[i] instanceof ProductionRules) { 45 ProductionRules tt = ( (ProductionRules) array[i]); 46 findProductionRule(ruleToFind,tt,arr); 47 } 48 } 49 return null; 50 } 51 52 public static void initialisePR() throws DException { 53 if (productionRules == null) 54 productionRules = getRules("SQL 99"); 55 } 56 57 public static Object parseBatch(String query) throws DException { 58 if (productionRules == null) 59 productionRules = getRules("SQL 99"); return productionRules.parseBatchUsingTokens(query); 61 } 62 63 public static Object parseBVE(String query) throws DException { 64 if (bveRule1 == null) 65 bveRule1 = findProductionRule("boolean value expression"); return bveRule1.parseUsingTokens(query); 67 } 68 69 70 public static Object parseQuery(String query) throws DException { 71 if (productionRules == null) 72 productionRules = getRules("SQL 99"); return productionRules.parseUsingTokens(query); 74 } 75 76 77 78 private static ProductionRules getRules(String ruleName) throws DException { 79 ProductionRuleTokenParser tokenParser = new ProductionRuleTokenParser(DaffodilClassLoader.getInstance()); 80 ProductionRules productionRule = tokenParser.getProductionRule1(ruleName); 81 return productionRule; 82 } 83 84 118 119 public static Object parseDefaultOption(String query) throws DException { 120 if (defaultOption == null) 121 defaultOption = findProductionRule("default option"); return defaultOption.parseUsingTokens(query); 123 } 124 125 public static Object parseTriggeredSQL(String query) throws DException { 126 if (triggeredSQL == null) 127 triggeredSQL = findProductionRule("triggered SQL statement"); return triggeredSQL.parseUsingTokens(query); 129 } 130 } 131 | Popular Tags |