You are viewing a plain text version of this content. The canonical link for it is here.
Posted to imperius-commits@incubator.apache.org by ke...@apache.org on 2008/01/11 18:57:14 UTC
svn commit: r611261 [30/43] - in /incubator/imperius/trunk: ./
imperius-javaspl/ imperius-javaspl/src/main/java/org/apache/imperius/javaspl/
imperius-splcore/
imperius-splcore/src/main/antlr/org/apache/imperius/spl/parser/compiler/
imperius-splcore/src...
Modified: incubator/imperius/trunk/imperius-splcore/src/main/java/org/apache/imperius/spl/parser/factory/BuitInOperationExpressionFactory.java
URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/imperius-splcore/src/main/java/org/apache/imperius/spl/parser/factory/BuitInOperationExpressionFactory.java?rev=611261&r1=611260&r2=611261&view=diff
==============================================================================
--- incubator/imperius/trunk/imperius-splcore/src/main/java/org/apache/imperius/spl/parser/factory/BuitInOperationExpressionFactory.java (original)
+++ incubator/imperius/trunk/imperius-splcore/src/main/java/org/apache/imperius/spl/parser/factory/BuitInOperationExpressionFactory.java Fri Jan 11 10:56:30 2008
@@ -1,427 +1,427 @@
-/*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-//
-
-/**
- * @author Neeraj Joshi <jn...@us.ibm.com>
- *
- */
-package org.apache.imperius.spl.parser.factory;
-
-import java.lang.reflect.Constructor;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.logging.Logger;
-
-import org.apache.imperius.spl.external.Expression;
-import org.apache.imperius.spl.parser.compiler.symboltable.MacroSymbol;
-import org.apache.imperius.spl.parser.compiler.symboltable.MethodSymbol;
-import org.apache.imperius.spl.parser.compiler.symboltable.SPLSymbolTable;
-import org.apache.imperius.spl.parser.compiler.symboltable.Symbol;
-import org.apache.imperius.spl.parser.exceptions.SPLException;
-import org.apache.imperius.spl.parser.expression.primary.MacroExpression;
-import org.apache.imperius.util.SPLLogger;
-
-
-// import org.apache.imperius.spl.parser.expressions.MethodExpression;
-
-public class BuitInOperationExpressionFactory
-{
- /*
- * stringLength toUpper toLower concatenate substring matchesRegExp
- * leftSubstring rightSubstring middleSubstring replaceSubstring toShort
- * toInteger toLong toFloat toDouble toDoubleInteger toUnsignDoubleInteger
- * toLongInteger toUnsignLongInteger toInteger toUnsignInteger toShort
- * toUnsignShort toBoolean word startsWith endsWith contains
- * containsOnlyDigits containsOnlyLetters containsOnlyLettersOrDigits
- * containsOnlyLettersOrDigits("a1b2C3") like min max remainder power abs
- * toString toDouble toFloat toLong toDoubleInteger toUnsignDoubleInteger
- * toLongInteger toUnsignLongInteger toInteger toUnsignInteger toShort
- * toUnsignShort toBoolean round exp log sqrt floor ceiling getMillisecond
- * getSecond getMinute getHour12 getHour24 getDayOfWeek getDayOfWeekInMonth
- * getDayOfMonth getDayOfYear getWeekOfMonth getWeekOfYear getMonth getYear
- * isWithin toMilliseconds
- *
- */
-
- private static Logger logger = SPLLogger.getSPLLogger().getLogger();
-
- private static final String sourceClass="MethodExpressionFactory";
-
-
- public static final String stringLength = "stringLength";
-
- public static final String toUpper = "toUpper";
-
- public static final String toLower = "toLower";
-
- public static final String concatenate = "concatenate";
-
- public static final String substring = "substring";
-
- public static final String matchesRegExp = "matchesRegExp";
-
- public static final String leftSubstring = "leftSubstring";
-
- public static final String rightSubstring = "rightSubstring";
-
- public static final String middleSubstring = "middleSubstring";
-
- public static final String replaceSubstring = "replaceSubstring";
-
- public static final String word = "word";
-
- public static final String startsWith = "startsWith";
-
- public static final String endsWith = "endsWith";
-
- public static final String contains = "contains";
-
- public static final String containsOnlyDigits = "containsOnlyDigits";
-
- public static final String containsOnlyLetters = "containsOnlyLetters";
-
- public static final String containsOnlyLettersOrDigits = "containsOnlyLettersOrDigits";
-
- // public static final String like = "like";
- public static final String min = "min";
-
- public static final String max = "max";
-
- public static final String remainder = "remainder";
-
- public static final String power = "power";
-
- public static final String abs = "abs";
-
- public static final String toString = "toString";
-
- public static final String toDouble = "toDouble";
-
- public static final String toFloat = "toFloat";
-
- public static final String toLong = "toLong";
-
- public static final String toDoubleInteger = "toDoubleInteger";
-
- public static final String toUnsignDoubleInteger = "toUnsignDoubleInteger";
-
- public static final String toLongInteger = "toLongInteger";
-
- public static final String toUnsignLongInteger = "toUnsignLongInteger";
-
- public static final String toInteger = "toInteger";
-
- public static final String toUnsignInteger = "toUnsignInteger";
-
- public static final String toShort = "toShort";
-
- public static final String toUnsignShort = "toUnsignShort";
-
- public static final String toBoolean = "toBoolean";
-
- public static final String round = "round";
-
- public static final String exp = "exp";
-
- // public static final String log = "log";
- public static final String sqrt = "sqrt";
-
- public static final String floor = "floor";
-
- public static final String ceiling = "ceiling";
-
- public static final String getMillisecond = "getMillisecond";
-
- public static final String getSecond = "getSecond";
-
- public static final String getMinute = "getMinute";
-
- public static final String getHour12 = "getHour12";
-
- public static final String getHour24 = "getHour24";
-
- public static final String getDayOfWeek = "getDayOfWeek";
-
- public static final String getDayOfWeekInMonth = "getDayOfWeekInMonth";
-
- public static final String getDayOfMonth = "getDayOfMonth";
-
- public static final String getDayOfYear = "getDayOfYear";
-
- public static final String getWeekOfMonth = "getWeekOfMonth";
-
- public static final String getWeekOfYear = "getWeekOfYear";
-
- public static final String getMonth = "getMonth";
-
- public static final String getYear = "getYear";
-
- public static final String isWithin = "isWithin";
-
- public static final String toMilliseconds = "toMilliseconds";
-
- public static final String minInCollection = "minInCollection";
-
- public static final String inCollection = "inCollection";
-
- public static final String union = "union";
-
- public static final String maxInCollection = "maxInCollection";
-
- public static final String collectionSize = "collectionSize";
-
- public static final String sum = "sum";
-
- public static final String avrgInCollection = "avrgInCollection";
-
- public static final String eqCollections = "eqCollections";
-
- public static final String subCollection = "subCollection";
-
- public static final String sdInCollection = "sdInCollection";
-
- public static final String medianInCollection = "medianInCollection";
-
- public static final String allInCollection = "allInCollection";
-
- public static final String anyInCollection = "anyInCollection";
-
- public static final String applyToCollection = "applyToCollection";
-
- public static final String log10 = "log10";
-
- public static final String ln = "ln";
-
- public static final String getCurrentTime = "getCurrentTime";
-
- public static final String invokePolicy = "invokePolicy";
-
- public static final String returnValue = "ReturnValue";
-
- public static Expression createExpression(String id1, String id2,
- List pList, SPLSymbolTable symTab) throws SPLException
- {
-
- logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "createExpression");
-
-
- boolean recurse = true;
- Expression returnExpr = null;
- if (!id1.equals("") && !id2.equals(""))
- {
- /*
- * if(symTab.symbolExists(id1 + "." + id2, recurse)) { Symbol symbol =
- * symTab.getSymbol(id1 + "." + id2); if(symbol instanceof
- * MethodSymbol) { returnExpr = new
- * MethodExpression((MethodSymbol)symbol,pList,symTab); } else {
- * throw new SPLException("undefined method" + id1 + "." + id2); } }
- */
- logger.severe( "id1.id2 type of method calls not allowed");
-
- throw new SPLException(
- "id1.id2 type of method calls not allowed");
- }
- else if (!id1.equals("") && id2.equals(""))
- {
-
- if (symTab.symbolExists(id1, recurse))
- {
- Symbol symbol = symTab.getSymbol(id1);
- if (symbol instanceof MacroSymbol)
- {
- returnExpr = new MacroExpression((MacroSymbol) symbol,
- (ArrayList)pList, symTab);
-
- }
- else if (symbol instanceof MethodSymbol)
- {
- logger.severe( "id1.id2 type of method calls not allowed");
-
- throw new SPLException(
- "id1.id2 type of method calls not allowed");
- }
- }
- else
- {
- if (ACPLParserMap.isKnownOperatorExpressionType(id1))
- {
- //System.out.println("creating inbuilt function expression");
- returnExpr = createBuiltInExpression(id1, pList, symTab);
- }
- else
- {
- logger.severe(Thread.currentThread().getName()+" "+"the symbol does not exist in the symbol table and is not a known inbuilt function");
-
- throw new SPLException(
- "the symbol does not exist in the symbol table and is not a known inbuilt function");
- }
- }
- }
-
- logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "createExpression");
-
- return returnExpr;
- }
-
- public static Expression createBuiltInExpression(String expName,
- List paramList, SPLSymbolTable symTab)
- throws SPLException
- {
-
- logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "createBuiltInExpression");
-
- boolean isAction = false;
- Expression returnExpression = _createBuiltInType(expName,paramList,symTab,isAction);
- logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "createBuiltInExpression");
-
- return returnExpression;
- }
-
- public static Expression createBuiltInAction(String expName,
- List paramList, SPLSymbolTable symTab)
- throws SPLException
- {
-
- logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "createBuiltInAction");
-
- boolean isAction = true;
- Expression returnExpression = _createBuiltInType(expName,paramList,symTab,isAction);
- logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "createBuiltInAction");
-
- return returnExpression;
- }
-
-
- private static Expression _createBuiltInType(String expName,
- List paramList, SPLSymbolTable symTab, boolean isAction)
- throws SPLException
- {
-
- logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "createACPLExpression");
-
-
-// String methodName = "createExpression(String expName,ArrayList parameters, SPLSymbolTable symTab)";
- //System.out.println("createACPLExpression::MethodExpressionFactory "+ expName);
- Expression returnExpression = null;
- // logger.entry(className, methodName, new Object[] { element });
- Boolean validateExpression = Boolean.TRUE;
- if (symTab.getSymbolTableType() == SPLSymbolTable.COLLECT)
- {
- validateExpression = Boolean.FALSE;
- }
- // String elementName = element.getLocalName();
- Class handlerClass = null;
- try
- {
- if(!isAction)
- {
- //System.out.println("ACPLParserMap.getClassForKnownType(expName) "+ expName);
- handlerClass = ACPLParserMap.getClassForOperatorExpressionType(expName);
- }
- else
- {
- handlerClass = ACPLParserMap.getClassForActionExpressionType(expName);
- }
- //System.out.println("handlerClass " + handlerClass.toString());
-
- }
- catch (ClassNotFoundException e)
- {
-// Object[] args = new Object[]
-// {
-// expName.toString()
-// };
- // {ERROR_EXPRESSION_CREATION_CLASS_PATH,
- // "Autonomic Manager Library cannot create an expression for
- // element {0}
- // because the expression handler class could not be found or
- // loaded."},
- logger.severe(Thread.currentThread().getName()+" "+"No such expression" + expName);
-
- throw new SPLException("No such expression" + expName);
-
- }
-
- /*
- * There are two cases:
- *
- * 1) the "regular" case like And expression, where the element has only
- * children elements representing known functions. In the regular case,
- * the children are converted to expression and passed as a Vector to
- * the appropriate expression handler.
- *
- * 2) a "SpecialCase" where the element has attributes or supporting
- * elements that are not known functions (like PolicyTimePeriod). In
- * this case, the whole element is passed to a SpecialCaseElementParser
- * that does a special conversion to the appropriate expression handler.
- */
- {
- // Do the normal case when the element just has children elements
- // Do all children
-
- Class[] argClassArray =
- {
- List.class, boolean.class
- };
- Object[] argObjectArray =
- {
- paramList, validateExpression
- };
-
- // Try to build the expression now
- /*
- * Constructor expressionConstructor; try { expressionConstructor =
- * handlerClass.getConstructor(new Class[] { List.class,
- * Boolean.class }); return
- * (Expression)expressionConstructor.newInstance( new Object[] {
- * parameters,validateExpression }); } catch (Exception e1) {
- * Object[] elementArg = new Object[] { expName, handlerClass };
- *
- * throw new SPLException("error instantiating"); }
- */
-
- Constructor exprConstructor;
- try
- {
- Constructor[] ctors = handlerClass.getConstructors();
- for (int k = 0; k < ctors.length; k++)
- {
- //System.out.println("Constructor name: "+ ctors[k].getName());
- Class[] paramTps = ctors[k].getParameterTypes();
- for (int z = 0; z < paramTps.length; z++)
- {
- //System.out.println("param type " + paramTps[z].getName());
- }
- }
- exprConstructor = handlerClass.getConstructor(argClassArray);
- returnExpression = (Expression) exprConstructor
- .newInstance(argObjectArray);
- //System.out.println("returnExpression "+ returnExpression.toString());
-
- }
- catch (Exception e)
- {
- logger.severe(Thread.currentThread().getName()+" "+"error instantiating" + e.getMessage());
- throw new SPLException("error instantiating" + e.getMessage());
- }
- }
- logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "createACPLExpression");
-
- return returnExpression;
- }
-
-
-
-}
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+//
+
+/**
+ * @author Neeraj Joshi <jn...@us.ibm.com>
+ *
+ */
+package org.apache.imperius.spl.parser.factory;
+
+import java.lang.reflect.Constructor;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.logging.Logger;
+
+import org.apache.imperius.spl.external.Expression;
+import org.apache.imperius.spl.parser.compiler.symboltable.MacroSymbol;
+import org.apache.imperius.spl.parser.compiler.symboltable.MethodSymbol;
+import org.apache.imperius.spl.parser.compiler.symboltable.SPLSymbolTable;
+import org.apache.imperius.spl.parser.compiler.symboltable.Symbol;
+import org.apache.imperius.spl.parser.exceptions.SPLException;
+import org.apache.imperius.spl.parser.expression.primary.MacroExpression;
+import org.apache.imperius.util.SPLLogger;
+
+
+// import org.apache.imperius.spl.parser.expressions.MethodExpression;
+
+public class BuitInOperationExpressionFactory
+{
+ /*
+ * stringLength toUpper toLower concatenate substring matchesRegExp
+ * leftSubstring rightSubstring middleSubstring replaceSubstring toShort
+ * toInteger toLong toFloat toDouble toDoubleInteger toUnsignDoubleInteger
+ * toLongInteger toUnsignLongInteger toInteger toUnsignInteger toShort
+ * toUnsignShort toBoolean word startsWith endsWith contains
+ * containsOnlyDigits containsOnlyLetters containsOnlyLettersOrDigits
+ * containsOnlyLettersOrDigits("a1b2C3") like min max remainder power abs
+ * toString toDouble toFloat toLong toDoubleInteger toUnsignDoubleInteger
+ * toLongInteger toUnsignLongInteger toInteger toUnsignInteger toShort
+ * toUnsignShort toBoolean round exp log sqrt floor ceiling getMillisecond
+ * getSecond getMinute getHour12 getHour24 getDayOfWeek getDayOfWeekInMonth
+ * getDayOfMonth getDayOfYear getWeekOfMonth getWeekOfYear getMonth getYear
+ * isWithin toMilliseconds
+ *
+ */
+
+ private static Logger logger = SPLLogger.getSPLLogger().getLogger();
+
+ private static final String sourceClass="MethodExpressionFactory";
+
+
+ public static final String stringLength = "stringLength";
+
+ public static final String toUpper = "toUpper";
+
+ public static final String toLower = "toLower";
+
+ public static final String concatenate = "concatenate";
+
+ public static final String substring = "substring";
+
+ public static final String matchesRegExp = "matchesRegExp";
+
+ public static final String leftSubstring = "leftSubstring";
+
+ public static final String rightSubstring = "rightSubstring";
+
+ public static final String middleSubstring = "middleSubstring";
+
+ public static final String replaceSubstring = "replaceSubstring";
+
+ public static final String word = "word";
+
+ public static final String startsWith = "startsWith";
+
+ public static final String endsWith = "endsWith";
+
+ public static final String contains = "contains";
+
+ public static final String containsOnlyDigits = "containsOnlyDigits";
+
+ public static final String containsOnlyLetters = "containsOnlyLetters";
+
+ public static final String containsOnlyLettersOrDigits = "containsOnlyLettersOrDigits";
+
+ // public static final String like = "like";
+ public static final String min = "min";
+
+ public static final String max = "max";
+
+ public static final String remainder = "remainder";
+
+ public static final String power = "power";
+
+ public static final String abs = "abs";
+
+ public static final String toString = "toString";
+
+ public static final String toDouble = "toDouble";
+
+ public static final String toFloat = "toFloat";
+
+ public static final String toLong = "toLong";
+
+ public static final String toDoubleInteger = "toDoubleInteger";
+
+ public static final String toUnsignDoubleInteger = "toUnsignDoubleInteger";
+
+ public static final String toLongInteger = "toLongInteger";
+
+ public static final String toUnsignLongInteger = "toUnsignLongInteger";
+
+ public static final String toInteger = "toInteger";
+
+ public static final String toUnsignInteger = "toUnsignInteger";
+
+ public static final String toShort = "toShort";
+
+ public static final String toUnsignShort = "toUnsignShort";
+
+ public static final String toBoolean = "toBoolean";
+
+ public static final String round = "round";
+
+ public static final String exp = "exp";
+
+ // public static final String log = "log";
+ public static final String sqrt = "sqrt";
+
+ public static final String floor = "floor";
+
+ public static final String ceiling = "ceiling";
+
+ public static final String getMillisecond = "getMillisecond";
+
+ public static final String getSecond = "getSecond";
+
+ public static final String getMinute = "getMinute";
+
+ public static final String getHour12 = "getHour12";
+
+ public static final String getHour24 = "getHour24";
+
+ public static final String getDayOfWeek = "getDayOfWeek";
+
+ public static final String getDayOfWeekInMonth = "getDayOfWeekInMonth";
+
+ public static final String getDayOfMonth = "getDayOfMonth";
+
+ public static final String getDayOfYear = "getDayOfYear";
+
+ public static final String getWeekOfMonth = "getWeekOfMonth";
+
+ public static final String getWeekOfYear = "getWeekOfYear";
+
+ public static final String getMonth = "getMonth";
+
+ public static final String getYear = "getYear";
+
+ public static final String isWithin = "isWithin";
+
+ public static final String toMilliseconds = "toMilliseconds";
+
+ public static final String minInCollection = "minInCollection";
+
+ public static final String inCollection = "inCollection";
+
+ public static final String union = "union";
+
+ public static final String maxInCollection = "maxInCollection";
+
+ public static final String collectionSize = "collectionSize";
+
+ public static final String sum = "sum";
+
+ public static final String avrgInCollection = "avrgInCollection";
+
+ public static final String eqCollections = "eqCollections";
+
+ public static final String subCollection = "subCollection";
+
+ public static final String sdInCollection = "sdInCollection";
+
+ public static final String medianInCollection = "medianInCollection";
+
+ public static final String allInCollection = "allInCollection";
+
+ public static final String anyInCollection = "anyInCollection";
+
+ public static final String applyToCollection = "applyToCollection";
+
+ public static final String log10 = "log10";
+
+ public static final String ln = "ln";
+
+ public static final String getCurrentTime = "getCurrentTime";
+
+ public static final String invokePolicy = "invokePolicy";
+
+ public static final String returnValue = "ReturnValue";
+
+ public static Expression createExpression(String id1, String id2,
+ List pList, SPLSymbolTable symTab) throws SPLException
+ {
+
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "createExpression");
+
+
+ boolean recurse = true;
+ Expression returnExpr = null;
+ if (!id1.equals("") && !id2.equals(""))
+ {
+ /*
+ * if(symTab.symbolExists(id1 + "." + id2, recurse)) { Symbol symbol =
+ * symTab.getSymbol(id1 + "." + id2); if(symbol instanceof
+ * MethodSymbol) { returnExpr = new
+ * MethodExpression((MethodSymbol)symbol,pList,symTab); } else {
+ * throw new SPLException("undefined method" + id1 + "." + id2); } }
+ */
+ logger.severe( "id1.id2 type of method calls not allowed");
+
+ throw new SPLException(
+ "id1.id2 type of method calls not allowed");
+ }
+ else if (!id1.equals("") && id2.equals(""))
+ {
+
+ if (symTab.symbolExists(id1, recurse))
+ {
+ Symbol symbol = symTab.getSymbol(id1);
+ if (symbol instanceof MacroSymbol)
+ {
+ returnExpr = new MacroExpression((MacroSymbol) symbol,
+ (ArrayList)pList, symTab);
+
+ }
+ else if (symbol instanceof MethodSymbol)
+ {
+ logger.severe( "id1.id2 type of method calls not allowed");
+
+ throw new SPLException(
+ "id1.id2 type of method calls not allowed");
+ }
+ }
+ else
+ {
+ if (ACPLParserMap.isKnownOperatorExpressionType(id1))
+ {
+ //System.out.println("creating inbuilt function expression");
+ returnExpr = createBuiltInExpression(id1, pList, symTab);
+ }
+ else
+ {
+ logger.severe(Thread.currentThread().getName()+" "+"the symbol does not exist in the symbol table and is not a known inbuilt function");
+
+ throw new SPLException(
+ "the symbol does not exist in the symbol table and is not a known inbuilt function");
+ }
+ }
+ }
+
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "createExpression");
+
+ return returnExpr;
+ }
+
+ public static Expression createBuiltInExpression(String expName,
+ List paramList, SPLSymbolTable symTab)
+ throws SPLException
+ {
+
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "createBuiltInExpression");
+
+ boolean isAction = false;
+ Expression returnExpression = _createBuiltInType(expName,paramList,symTab,isAction);
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "createBuiltInExpression");
+
+ return returnExpression;
+ }
+
+ public static Expression createBuiltInAction(String expName,
+ List paramList, SPLSymbolTable symTab)
+ throws SPLException
+ {
+
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "createBuiltInAction");
+
+ boolean isAction = true;
+ Expression returnExpression = _createBuiltInType(expName,paramList,symTab,isAction);
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "createBuiltInAction");
+
+ return returnExpression;
+ }
+
+
+ private static Expression _createBuiltInType(String expName,
+ List paramList, SPLSymbolTable symTab, boolean isAction)
+ throws SPLException
+ {
+
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "createACPLExpression");
+
+
+// String methodName = "createExpression(String expName,ArrayList parameters, SPLSymbolTable symTab)";
+ //System.out.println("createACPLExpression::MethodExpressionFactory "+ expName);
+ Expression returnExpression = null;
+ // logger.entry(className, methodName, new Object[] { element });
+ Boolean validateExpression = Boolean.TRUE;
+ if (symTab.getSymbolTableType() == SPLSymbolTable.COLLECT)
+ {
+ validateExpression = Boolean.FALSE;
+ }
+ // String elementName = element.getLocalName();
+ Class handlerClass = null;
+ try
+ {
+ if(!isAction)
+ {
+ //System.out.println("ACPLParserMap.getClassForKnownType(expName) "+ expName);
+ handlerClass = ACPLParserMap.getClassForOperatorExpressionType(expName);
+ }
+ else
+ {
+ handlerClass = ACPLParserMap.getClassForActionExpressionType(expName);
+ }
+ //System.out.println("handlerClass " + handlerClass.toString());
+
+ }
+ catch (ClassNotFoundException e)
+ {
+// Object[] args = new Object[]
+// {
+// expName.toString()
+// };
+ // {ERROR_EXPRESSION_CREATION_CLASS_PATH,
+ // "Autonomic Manager Library cannot create an expression for
+ // element {0}
+ // because the expression handler class could not be found or
+ // loaded."},
+ logger.severe(Thread.currentThread().getName()+" "+"No such expression" + expName);
+
+ throw new SPLException("No such expression" + expName);
+
+ }
+
+ /*
+ * There are two cases:
+ *
+ * 1) the "regular" case like And expression, where the element has only
+ * children elements representing known functions. In the regular case,
+ * the children are converted to expression and passed as a Vector to
+ * the appropriate expression handler.
+ *
+ * 2) a "SpecialCase" where the element has attributes or supporting
+ * elements that are not known functions (like PolicyTimePeriod). In
+ * this case, the whole element is passed to a SpecialCaseElementParser
+ * that does a special conversion to the appropriate expression handler.
+ */
+ {
+ // Do the normal case when the element just has children elements
+ // Do all children
+
+ Class[] argClassArray =
+ {
+ List.class, boolean.class
+ };
+ Object[] argObjectArray =
+ {
+ paramList, validateExpression
+ };
+
+ // Try to build the expression now
+ /*
+ * Constructor expressionConstructor; try { expressionConstructor =
+ * handlerClass.getConstructor(new Class[] { List.class,
+ * Boolean.class }); return
+ * (Expression)expressionConstructor.newInstance( new Object[] {
+ * parameters,validateExpression }); } catch (Exception e1) {
+ * Object[] elementArg = new Object[] { expName, handlerClass };
+ *
+ * throw new SPLException("error instantiating"); }
+ */
+
+ Constructor exprConstructor;
+ try
+ {
+ Constructor[] ctors = handlerClass.getConstructors();
+ for (int k = 0; k < ctors.length; k++)
+ {
+ //System.out.println("Constructor name: "+ ctors[k].getName());
+ Class[] paramTps = ctors[k].getParameterTypes();
+ for (int z = 0; z < paramTps.length; z++)
+ {
+ //System.out.println("param type " + paramTps[z].getName());
+ }
+ }
+ exprConstructor = handlerClass.getConstructor(argClassArray);
+ returnExpression = (Expression) exprConstructor
+ .newInstance(argObjectArray);
+ //System.out.println("returnExpression "+ returnExpression.toString());
+
+ }
+ catch (Exception e)
+ {
+ logger.severe(Thread.currentThread().getName()+" "+"error instantiating" + e.getMessage());
+ throw new SPLException("error instantiating" + e.getMessage());
+ }
+ }
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "createACPLExpression");
+
+ return returnExpression;
+ }
+
+
+
+}
Propchange: incubator/imperius/trunk/imperius-splcore/src/main/java/org/apache/imperius/spl/parser/factory/BuitInOperationExpressionFactory.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/imperius/trunk/imperius-splcore/src/main/java/org/apache/imperius/spl/parser/factory/ExpressionFactory.java
URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/imperius-splcore/src/main/java/org/apache/imperius/spl/parser/factory/ExpressionFactory.java?rev=611261&r1=611260&r2=611261&view=diff
==============================================================================
--- incubator/imperius/trunk/imperius-splcore/src/main/java/org/apache/imperius/spl/parser/factory/ExpressionFactory.java (original)
+++ incubator/imperius/trunk/imperius-splcore/src/main/java/org/apache/imperius/spl/parser/factory/ExpressionFactory.java Fri Jan 11 10:56:30 2008
@@ -1,417 +1,417 @@
-/*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-//
-
-/**
- * @author Neeraj Joshi <jn...@us.ibm.com>
- *
- */
-package org.apache.imperius.spl.parser.factory;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Calendar;
-import java.util.TimeZone;
-import java.util.logging.Logger;
-
-import org.apache.imperius.spl.external.Expression;
-import org.apache.imperius.spl.external.TypeConstants;
-import org.apache.imperius.spl.parser.compiler.SPLTreeParserTokenTypes;
-import org.apache.imperius.spl.parser.compiler.symboltable.SPLSymbolTable;
-import org.apache.imperius.spl.parser.exceptions.SPLException;
-import org.apache.imperius.spl.parser.expression.primary.*;
-import org.apache.imperius.spl.parser.expressions.impl.Addition;
-import org.apache.imperius.spl.parser.expressions.impl.AssignmentExpression;
-import org.apache.imperius.spl.parser.expressions.impl.BooleanConstant;
-import org.apache.imperius.spl.parser.expressions.impl.CharConstant;
-import org.apache.imperius.spl.parser.expressions.impl.DateTime;
-import org.apache.imperius.spl.parser.expressions.impl.DateTimeConstant;
-import org.apache.imperius.spl.parser.expressions.impl.Division;
-import org.apache.imperius.spl.parser.expressions.impl.DoubleConstant;
-import org.apache.imperius.spl.parser.expressions.impl.Equal;
-import org.apache.imperius.spl.parser.expressions.impl.FloatConstant;
-import org.apache.imperius.spl.parser.expressions.impl.Greater;
-import org.apache.imperius.spl.parser.expressions.impl.GreaterOrEqual;
-import org.apache.imperius.spl.parser.expressions.impl.IntegerConstant;
-import org.apache.imperius.spl.parser.expressions.impl.Less;
-import org.apache.imperius.spl.parser.expressions.impl.LessOrEqual;
-import org.apache.imperius.spl.parser.expressions.impl.LogicalAnd;
-import org.apache.imperius.spl.parser.expressions.impl.LogicalOr;
-import org.apache.imperius.spl.parser.expressions.impl.LogicalXor;
-import org.apache.imperius.spl.parser.expressions.impl.LongConstant;
-import org.apache.imperius.spl.parser.expressions.impl.NotEqual;
-import org.apache.imperius.spl.parser.expressions.impl.Product;
-import org.apache.imperius.spl.parser.expressions.impl.ShortConstant;
-import org.apache.imperius.spl.parser.expressions.impl.StringConstant;
-import org.apache.imperius.spl.parser.expressions.impl.Subtraction;
-import org.apache.imperius.spl.parser.expressions.impl.UnaryMinusExpression;
-import org.apache.imperius.spl.parser.expressions.impl.UnaryNotExpression;
-import org.apache.imperius.spl.parser.expressions.impl.UnaryPlusExpression;
-import org.apache.imperius.spl.parser.util.ExpressionUtility;
-import org.apache.imperius.util.SPLLogger;
-
-
-
-
-
-//PB: have added a utility to create java Calendar from the CIMDateTime string
-//PB: have added a utility to check if a string is a CIMDateTime string
-//that is parsed
-public class ExpressionFactory
-{
-
- private static String GMT = "GMT";
-
- private static int UTC_MULTIPLIER = 60000;
-
- private static Logger logger = SPLLogger.getSPLLogger().getLogger();
-
- private static final String sourceClass="ExpressionFactory";
-
-
- public static Expression createExpression(Expression e1, Expression e2,
- int type, SPLSymbolTable sTab) throws SPLException
- {
- logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "createExpression");
-
- //System.out.println("creating expression " + e1.getClass() + " "+ e2.getClass() + " " + type);
- Expression returnExpr = null;
- List exprList = new ArrayList();
-
- exprList.add(e1);
- exprList.add(e2);
- boolean validateExpr = true;
- if (sTab.getSymbolTableType() == SPLSymbolTable.COLLECT)
- {
- //System.out.println("sTab.getSymbolTableType() == SPLSymbolTable.COLLECT");
- validateExpr = false;
- }
- switch (type)
- {
- case SPLTreeParserTokenTypes.ASSIGN:
- //System.out.println("Expression Factory::Creating assignment expression");
- returnExpr = new AssignmentExpression(exprList, validateExpr);
- break;
-
- case SPLTreeParserTokenTypes.LOR:
- returnExpr = new LogicalOr(exprList, validateExpr);
- break;
-
- case SPLTreeParserTokenTypes.LAND:
- returnExpr = new LogicalAnd(exprList, validateExpr);
- break;
-
- case SPLTreeParserTokenTypes.BXOR:
- returnExpr = new LogicalXor(exprList, validateExpr);
- break;
-
- case SPLTreeParserTokenTypes.NOT_EQUAL:
- returnExpr = new NotEqual(exprList, validateExpr);
- break;
-
- case SPLTreeParserTokenTypes.EQUAL:
- returnExpr = new Equal(exprList, validateExpr);
- break;
-
- case SPLTreeParserTokenTypes.LT:
- returnExpr = new Less(exprList, validateExpr);
- break;
-
- case SPLTreeParserTokenTypes.GT:
- returnExpr = new Greater(exprList, validateExpr);
- break;
-
- case SPLTreeParserTokenTypes.LE:
- returnExpr = new LessOrEqual(exprList, validateExpr);
- break;
-
- case SPLTreeParserTokenTypes.GE:
- returnExpr = new GreaterOrEqual(exprList, validateExpr);
- break;
-
- case SPLTreeParserTokenTypes.PLUS:
- returnExpr = new Addition(exprList, validateExpr);
- break;
-
- case SPLTreeParserTokenTypes.MINUS:
- returnExpr = new Subtraction(exprList, validateExpr);
- break;
-
- case SPLTreeParserTokenTypes.DIV:
- returnExpr = new Division(exprList, validateExpr);
- break;
-
- case SPLTreeParserTokenTypes.STAR:
- returnExpr = new Product(exprList, validateExpr);
- break;
-
- }
-
- logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "createExpression");
-
- return returnExpr;
-
- }
-
- public static Expression createExpression(Expression e1, int type,
- SPLSymbolTable sTab) throws SPLException
- {
- logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "createExpression");
-
- Expression returnExpr = null;
-
- List exprList = new ArrayList();
- exprList.add(e1);
- boolean validateExpr = true;
- if (sTab.getSymbolTableType() == SPLSymbolTable.COLLECT)
- {
- validateExpr = false;
- }
- switch (type)
- {
- case SPLTreeParserTokenTypes.UNARY_MINUS:
- returnExpr = new UnaryMinusExpression(exprList, validateExpr);
- break;
-
- case SPLTreeParserTokenTypes.UNARY_PLUS:
- returnExpr = new UnaryPlusExpression(exprList, validateExpr);
- break;
-
- case SPLTreeParserTokenTypes.UNARY_NOT:
- returnExpr = new UnaryNotExpression(exprList, validateExpr);
-
- }
-
-
- logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "createExpression");
-
- return returnExpr;
-
- }
-
- public static Expression createExpression(String val, int type)
- throws SPLException
- {
- logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "createExpression");
-
- Expression returnExpr = null;
- switch (type)
- {
- case TypeConstants.dateTime:
- //System.out.println("Expression factory creating new date time: "+ val.toString());
- returnExpr = new DateTimeConstant(val);
- break;
-
- case TypeConstants.charType:
- char[] cArr = val.toCharArray();
- returnExpr = new CharConstant(cArr[0]);
- break;
-
- case TypeConstants.doubleType:
- returnExpr = new DoubleConstant(Double.valueOf(val)
- .doubleValue());
- break;
-
- case TypeConstants.floatType:
- returnExpr = new FloatConstant(Float.valueOf(val).floatValue());
- break;
-
- case TypeConstants.intType:
- returnExpr = new IntegerConstant(Integer.valueOf(val)
- .intValue());
- break;
- case TypeConstants.shortType:
- returnExpr = new ShortConstant(Short.valueOf(val).shortValue());
- break;
-
- case TypeConstants.longType:
- if(val.endsWith("L") ||val.endsWith("l"))
- {
- val=val.substring(0, val.length()-2);
- }
- returnExpr = new LongConstant(Long.valueOf(val).longValue());
- break;
-
- case TypeConstants.stringType:
- String dateStr=(String) val;
- if(DateTime.isDateTimeString(dateStr))
- {
- //System.out.println("string is a date string createJavaDateTime "+val);
- int size=dateStr.length();
- returnExpr = new DateTimeConstant(dateStr.substring(1, size-1));
- }
- else
- {
- returnExpr = new StringConstant(val);
- }
-
- break;
-
- case TypeConstants.booleanType:
- returnExpr = new BooleanConstant(Boolean.valueOf(val)
- .booleanValue());
- break;
-
- /*
- * case TypeConstants.referenceType : try { returnExpr = new
- * SelfExpression(); } catch (NonExistentSymbolException e) { //
- * TODO Auto-generated catch block e.printStackTrace(); } catch
- * (IllegalSymbolReferenceException e) { // TODO Auto-generated
- * catch block e.printStackTrace(); } catch
- * (IllegalExpressionTypeException e) { // TODO Auto-generated catch
- * block e.printStackTrace(); } break;
- */
-
- }
-
- logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "createExpression");
-
- return returnExpr;
-
- }
-
- public static Expression createSelfExpression(SPLSymbolTable st)throws SPLException
- {
- logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "createSelfExpression");
-
-
- Expression expression = new SelfExpression(st);
- //System.out.println("created self expression " + expression.toString());
-
- logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "createSelfExpression");
-
- return expression;
- }
-
- public static Expression createCollectExpression(ArrayList pList,
- Expression postCollect, SPLSymbolTable sTab)
- throws SPLException
- {
- logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "createCollectExpression");
-
- Expression returnExpr = null;
- returnExpr = new CollectOperation(pList, postCollect, sTab);
-
- logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "createCollectExpression");
-
- return returnExpr;
- }
-
- // exp =
- // ExpressionFactory.createPostCollectExpression(id.getText(),arrExp,pList);
-
- public static Expression createPostCollectExpression(Expression arr1,
- String propOrMethodName, Expression arrExp, ArrayList pList,
- SPLSymbolTable sTab)throws SPLException
- {
- logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "createPostCollectExpression");
-
-
- Expression returnExpr = null;
- returnExpr = new PostCollectExpression(arr1, propOrMethodName, arrExp,
- pList, sTab);
- logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "createPostCollectExpression");
-
- return returnExpr;
-
- }
-
- public static Expression createBasicCollectExpression(ArrayList pList,
- SPLSymbolTable sTab) throws SPLException
- {
- logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "createBasicCollectExpression");
-
- Expression returnExpr = null;
- returnExpr = new BasicCollectionExpression(pList, sTab);
- if (returnExpr == null)
- {
- logger.severe(Thread.currentThread().getName()+" "+"Constructor BasicCollectionExpression(pList,sTab) returned null expression");
- throw new SPLException(
- "Constructor BasicCollectionExpression(pList,sTab) returned null expression");
-
- }
-
- logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "createBasicCollectExpression");
-
- return returnExpr;
- }
-
- public static Expression createExpression(String classOrOperationName,
- List paramOrIdentTupleList,
- boolean isBuiltInOperation,
- SPLSymbolTable symTab) throws SPLException
- {
- Expression returnExpr = null;
- if (isBuiltInOperation)
- {
- //System.out.println("isBuiltInOperation=true ");
- if(symTab ==null)
- {
- //System.out.println("ExpressionFactory : symTab is null ");
- }
- returnExpr = BuitInOperationExpressionFactory.createExpression(classOrOperationName,
- "", paramOrIdentTupleList, symTab);
-
- }
- else
- {
- //System.out.println("isBuiltInOperation=false "+classOrOperationName);
- if(symTab ==null)
- {
- //System.out.println("ExpressionFactory : symTab is null ");
- }
- returnExpr = new PrimaryExpression(classOrOperationName,
- paramOrIdentTupleList,symTab);
- }
-
-
- return returnExpr;
-
- }
-
-
-
- /*public static Expression createExpression(String className,
- String methodOrPropName, Expression arrExp, List pList,
- boolean isMethod, SPLSymbolTable sTab) throws SPLException
- {
- logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "createExpression");
-
- Expression returnExpr = null;
-
- if (isMethod)
- {
-
- returnExpr = BuitInOperationExpressionFactory.createExpression(className,
- methodOrPropName, pList, sTab);
-
- }
- else
- {
-
- returnExpr = new PrimaryExpression(className, methodOrPropName,
- arrExp, sTab);
-
- }
-
-
- logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "createExpression");
-
- return returnExpr;
-
- }*/
-
-
-
-}
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+//
+
+/**
+ * @author Neeraj Joshi <jn...@us.ibm.com>
+ *
+ */
+package org.apache.imperius.spl.parser.factory;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Calendar;
+import java.util.TimeZone;
+import java.util.logging.Logger;
+
+import org.apache.imperius.spl.external.Expression;
+import org.apache.imperius.spl.external.TypeConstants;
+import org.apache.imperius.spl.parser.compiler.SPLTreeParserTokenTypes;
+import org.apache.imperius.spl.parser.compiler.symboltable.SPLSymbolTable;
+import org.apache.imperius.spl.parser.exceptions.SPLException;
+import org.apache.imperius.spl.parser.expression.primary.*;
+import org.apache.imperius.spl.parser.expressions.impl.Addition;
+import org.apache.imperius.spl.parser.expressions.impl.AssignmentExpression;
+import org.apache.imperius.spl.parser.expressions.impl.BooleanConstant;
+import org.apache.imperius.spl.parser.expressions.impl.CharConstant;
+import org.apache.imperius.spl.parser.expressions.impl.DateTime;
+import org.apache.imperius.spl.parser.expressions.impl.DateTimeConstant;
+import org.apache.imperius.spl.parser.expressions.impl.Division;
+import org.apache.imperius.spl.parser.expressions.impl.DoubleConstant;
+import org.apache.imperius.spl.parser.expressions.impl.Equal;
+import org.apache.imperius.spl.parser.expressions.impl.FloatConstant;
+import org.apache.imperius.spl.parser.expressions.impl.Greater;
+import org.apache.imperius.spl.parser.expressions.impl.GreaterOrEqual;
+import org.apache.imperius.spl.parser.expressions.impl.IntegerConstant;
+import org.apache.imperius.spl.parser.expressions.impl.Less;
+import org.apache.imperius.spl.parser.expressions.impl.LessOrEqual;
+import org.apache.imperius.spl.parser.expressions.impl.LogicalAnd;
+import org.apache.imperius.spl.parser.expressions.impl.LogicalOr;
+import org.apache.imperius.spl.parser.expressions.impl.LogicalXor;
+import org.apache.imperius.spl.parser.expressions.impl.LongConstant;
+import org.apache.imperius.spl.parser.expressions.impl.NotEqual;
+import org.apache.imperius.spl.parser.expressions.impl.Product;
+import org.apache.imperius.spl.parser.expressions.impl.ShortConstant;
+import org.apache.imperius.spl.parser.expressions.impl.StringConstant;
+import org.apache.imperius.spl.parser.expressions.impl.Subtraction;
+import org.apache.imperius.spl.parser.expressions.impl.UnaryMinusExpression;
+import org.apache.imperius.spl.parser.expressions.impl.UnaryNotExpression;
+import org.apache.imperius.spl.parser.expressions.impl.UnaryPlusExpression;
+import org.apache.imperius.spl.parser.util.ExpressionUtility;
+import org.apache.imperius.util.SPLLogger;
+
+
+
+
+
+//PB: have added a utility to create java Calendar from the CIMDateTime string
+//PB: have added a utility to check if a string is a CIMDateTime string
+//that is parsed
+public class ExpressionFactory
+{
+
+ private static String GMT = "GMT";
+
+ private static int UTC_MULTIPLIER = 60000;
+
+ private static Logger logger = SPLLogger.getSPLLogger().getLogger();
+
+ private static final String sourceClass="ExpressionFactory";
+
+
+ public static Expression createExpression(Expression e1, Expression e2,
+ int type, SPLSymbolTable sTab) throws SPLException
+ {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "createExpression");
+
+ //System.out.println("creating expression " + e1.getClass() + " "+ e2.getClass() + " " + type);
+ Expression returnExpr = null;
+ List exprList = new ArrayList();
+
+ exprList.add(e1);
+ exprList.add(e2);
+ boolean validateExpr = true;
+ if (sTab.getSymbolTableType() == SPLSymbolTable.COLLECT)
+ {
+ //System.out.println("sTab.getSymbolTableType() == SPLSymbolTable.COLLECT");
+ validateExpr = false;
+ }
+ switch (type)
+ {
+ case SPLTreeParserTokenTypes.ASSIGN:
+ //System.out.println("Expression Factory::Creating assignment expression");
+ returnExpr = new AssignmentExpression(exprList, validateExpr);
+ break;
+
+ case SPLTreeParserTokenTypes.LOR:
+ returnExpr = new LogicalOr(exprList, validateExpr);
+ break;
+
+ case SPLTreeParserTokenTypes.LAND:
+ returnExpr = new LogicalAnd(exprList, validateExpr);
+ break;
+
+ case SPLTreeParserTokenTypes.BXOR:
+ returnExpr = new LogicalXor(exprList, validateExpr);
+ break;
+
+ case SPLTreeParserTokenTypes.NOT_EQUAL:
+ returnExpr = new NotEqual(exprList, validateExpr);
+ break;
+
+ case SPLTreeParserTokenTypes.EQUAL:
+ returnExpr = new Equal(exprList, validateExpr);
+ break;
+
+ case SPLTreeParserTokenTypes.LT:
+ returnExpr = new Less(exprList, validateExpr);
+ break;
+
+ case SPLTreeParserTokenTypes.GT:
+ returnExpr = new Greater(exprList, validateExpr);
+ break;
+
+ case SPLTreeParserTokenTypes.LE:
+ returnExpr = new LessOrEqual(exprList, validateExpr);
+ break;
+
+ case SPLTreeParserTokenTypes.GE:
+ returnExpr = new GreaterOrEqual(exprList, validateExpr);
+ break;
+
+ case SPLTreeParserTokenTypes.PLUS:
+ returnExpr = new Addition(exprList, validateExpr);
+ break;
+
+ case SPLTreeParserTokenTypes.MINUS:
+ returnExpr = new Subtraction(exprList, validateExpr);
+ break;
+
+ case SPLTreeParserTokenTypes.DIV:
+ returnExpr = new Division(exprList, validateExpr);
+ break;
+
+ case SPLTreeParserTokenTypes.STAR:
+ returnExpr = new Product(exprList, validateExpr);
+ break;
+
+ }
+
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "createExpression");
+
+ return returnExpr;
+
+ }
+
+ public static Expression createExpression(Expression e1, int type,
+ SPLSymbolTable sTab) throws SPLException
+ {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "createExpression");
+
+ Expression returnExpr = null;
+
+ List exprList = new ArrayList();
+ exprList.add(e1);
+ boolean validateExpr = true;
+ if (sTab.getSymbolTableType() == SPLSymbolTable.COLLECT)
+ {
+ validateExpr = false;
+ }
+ switch (type)
+ {
+ case SPLTreeParserTokenTypes.UNARY_MINUS:
+ returnExpr = new UnaryMinusExpression(exprList, validateExpr);
+ break;
+
+ case SPLTreeParserTokenTypes.UNARY_PLUS:
+ returnExpr = new UnaryPlusExpression(exprList, validateExpr);
+ break;
+
+ case SPLTreeParserTokenTypes.UNARY_NOT:
+ returnExpr = new UnaryNotExpression(exprList, validateExpr);
+
+ }
+
+
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "createExpression");
+
+ return returnExpr;
+
+ }
+
+ public static Expression createExpression(String val, int type)
+ throws SPLException
+ {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "createExpression");
+
+ Expression returnExpr = null;
+ switch (type)
+ {
+ case TypeConstants.dateTime:
+ //System.out.println("Expression factory creating new date time: "+ val.toString());
+ returnExpr = new DateTimeConstant(val);
+ break;
+
+ case TypeConstants.charType:
+ char[] cArr = val.toCharArray();
+ returnExpr = new CharConstant(cArr[0]);
+ break;
+
+ case TypeConstants.doubleType:
+ returnExpr = new DoubleConstant(Double.valueOf(val)
+ .doubleValue());
+ break;
+
+ case TypeConstants.floatType:
+ returnExpr = new FloatConstant(Float.valueOf(val).floatValue());
+ break;
+
+ case TypeConstants.intType:
+ returnExpr = new IntegerConstant(Integer.valueOf(val)
+ .intValue());
+ break;
+ case TypeConstants.shortType:
+ returnExpr = new ShortConstant(Short.valueOf(val).shortValue());
+ break;
+
+ case TypeConstants.longType:
+ if(val.endsWith("L") ||val.endsWith("l"))
+ {
+ val=val.substring(0, val.length()-2);
+ }
+ returnExpr = new LongConstant(Long.valueOf(val).longValue());
+ break;
+
+ case TypeConstants.stringType:
+ String dateStr=(String) val;
+ if(DateTime.isDateTimeString(dateStr))
+ {
+ //System.out.println("string is a date string createJavaDateTime "+val);
+ int size=dateStr.length();
+ returnExpr = new DateTimeConstant(dateStr.substring(1, size-1));
+ }
+ else
+ {
+ returnExpr = new StringConstant(val);
+ }
+
+ break;
+
+ case TypeConstants.booleanType:
+ returnExpr = new BooleanConstant(Boolean.valueOf(val)
+ .booleanValue());
+ break;
+
+ /*
+ * case TypeConstants.referenceType : try { returnExpr = new
+ * SelfExpression(); } catch (NonExistentSymbolException e) { //
+ * TODO Auto-generated catch block e.printStackTrace(); } catch
+ * (IllegalSymbolReferenceException e) { // TODO Auto-generated
+ * catch block e.printStackTrace(); } catch
+ * (IllegalExpressionTypeException e) { // TODO Auto-generated catch
+ * block e.printStackTrace(); } break;
+ */
+
+ }
+
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "createExpression");
+
+ return returnExpr;
+
+ }
+
+ public static Expression createSelfExpression(SPLSymbolTable st)throws SPLException
+ {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "createSelfExpression");
+
+
+ Expression expression = new SelfExpression(st);
+ //System.out.println("created self expression " + expression.toString());
+
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "createSelfExpression");
+
+ return expression;
+ }
+
+ public static Expression createCollectExpression(ArrayList pList,
+ Expression postCollect, SPLSymbolTable sTab)
+ throws SPLException
+ {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "createCollectExpression");
+
+ Expression returnExpr = null;
+ returnExpr = new CollectOperation(pList, postCollect, sTab);
+
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "createCollectExpression");
+
+ return returnExpr;
+ }
+
+ // exp =
+ // ExpressionFactory.createPostCollectExpression(id.getText(),arrExp,pList);
+
+ public static Expression createPostCollectExpression(Expression arr1,
+ String propOrMethodName, Expression arrExp, ArrayList pList,
+ SPLSymbolTable sTab)throws SPLException
+ {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "createPostCollectExpression");
+
+
+ Expression returnExpr = null;
+ returnExpr = new PostCollectExpression(arr1, propOrMethodName, arrExp,
+ pList, sTab);
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "createPostCollectExpression");
+
+ return returnExpr;
+
+ }
+
+ public static Expression createBasicCollectExpression(ArrayList pList,
+ SPLSymbolTable sTab) throws SPLException
+ {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "createBasicCollectExpression");
+
+ Expression returnExpr = null;
+ returnExpr = new BasicCollectionExpression(pList, sTab);
+ if (returnExpr == null)
+ {
+ logger.severe(Thread.currentThread().getName()+" "+"Constructor BasicCollectionExpression(pList,sTab) returned null expression");
+ throw new SPLException(
+ "Constructor BasicCollectionExpression(pList,sTab) returned null expression");
+
+ }
+
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "createBasicCollectExpression");
+
+ return returnExpr;
+ }
+
+ public static Expression createExpression(String classOrOperationName,
+ List paramOrIdentTupleList,
+ boolean isBuiltInOperation,
+ SPLSymbolTable symTab) throws SPLException
+ {
+ Expression returnExpr = null;
+ if (isBuiltInOperation)
+ {
+ //System.out.println("isBuiltInOperation=true ");
+ if(symTab ==null)
+ {
+ //System.out.println("ExpressionFactory : symTab is null ");
+ }
+ returnExpr = BuitInOperationExpressionFactory.createExpression(classOrOperationName,
+ "", paramOrIdentTupleList, symTab);
+
+ }
+ else
+ {
+ //System.out.println("isBuiltInOperation=false "+classOrOperationName);
+ if(symTab ==null)
+ {
+ //System.out.println("ExpressionFactory : symTab is null ");
+ }
+ returnExpr = new PrimaryExpression(classOrOperationName,
+ paramOrIdentTupleList,symTab);
+ }
+
+
+ return returnExpr;
+
+ }
+
+
+
+ /*public static Expression createExpression(String className,
+ String methodOrPropName, Expression arrExp, List pList,
+ boolean isMethod, SPLSymbolTable sTab) throws SPLException
+ {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "createExpression");
+
+ Expression returnExpr = null;
+
+ if (isMethod)
+ {
+
+ returnExpr = BuitInOperationExpressionFactory.createExpression(className,
+ methodOrPropName, pList, sTab);
+
+ }
+ else
+ {
+
+ returnExpr = new PrimaryExpression(className, methodOrPropName,
+ arrExp, sTab);
+
+ }
+
+
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "createExpression");
+
+ return returnExpr;
+
+ }*/
+
+
+
+}
Propchange: incubator/imperius/trunk/imperius-splcore/src/main/java/org/apache/imperius/spl/parser/factory/ExpressionFactory.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/imperius/trunk/imperius-splcore/src/main/java/org/apache/imperius/spl/parser/statements/ActionBlock.java
URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/imperius-splcore/src/main/java/org/apache/imperius/spl/parser/statements/ActionBlock.java?rev=611261&r1=611260&r2=611261&view=diff
==============================================================================
--- incubator/imperius/trunk/imperius-splcore/src/main/java/org/apache/imperius/spl/parser/statements/ActionBlock.java (original)
+++ incubator/imperius/trunk/imperius-splcore/src/main/java/org/apache/imperius/spl/parser/statements/ActionBlock.java Fri Jan 11 10:56:30 2008
@@ -1,29 +1,29 @@
-/*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-//
-
-/**
- * @author Neeraj Joshi <jn...@us.ibm.com>
- *
- */
-package org.apache.imperius.spl.parser.statements;
-
-
-import org.apache.imperius.spl.external.Actuator;
-
-public interface ActionBlock {
-
- boolean execute(Actuator ac);
-
-}
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+//
+
+/**
+ * @author Neeraj Joshi <jn...@us.ibm.com>
+ *
+ */
+package org.apache.imperius.spl.parser.statements;
+
+
+import org.apache.imperius.spl.external.Actuator;
+
+public interface ActionBlock {
+
+ boolean execute(Actuator ac);
+
+}
Propchange: incubator/imperius/trunk/imperius-splcore/src/main/java/org/apache/imperius/spl/parser/statements/ActionBlock.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/imperius/trunk/imperius-splcore/src/main/java/org/apache/imperius/spl/parser/statements/BasicActionBlock.java
URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/imperius-splcore/src/main/java/org/apache/imperius/spl/parser/statements/BasicActionBlock.java?rev=611261&r1=611260&r2=611261&view=diff
==============================================================================
--- incubator/imperius/trunk/imperius-splcore/src/main/java/org/apache/imperius/spl/parser/statements/BasicActionBlock.java (original)
+++ incubator/imperius/trunk/imperius-splcore/src/main/java/org/apache/imperius/spl/parser/statements/BasicActionBlock.java Fri Jan 11 10:56:30 2008
@@ -1,25 +1,25 @@
-/*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-//
-
-/**
- * @author Neeraj Joshi <jn...@us.ibm.com>
- *
- */
-package org.apache.imperius.spl.parser.statements;
-
-public interface BasicActionBlock extends ActionBlock
-{
-
-}
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+//
+
+/**
+ * @author Neeraj Joshi <jn...@us.ibm.com>
+ *
+ */
+package org.apache.imperius.spl.parser.statements;
+
+public interface BasicActionBlock extends ActionBlock
+{
+
+}
Propchange: incubator/imperius/trunk/imperius-splcore/src/main/java/org/apache/imperius/spl/parser/statements/BasicActionBlock.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/imperius/trunk/imperius-splcore/src/main/java/org/apache/imperius/spl/parser/statements/PolicyStatement.java
URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/imperius-splcore/src/main/java/org/apache/imperius/spl/parser/statements/PolicyStatement.java?rev=611261&r1=611260&r2=611261&view=diff
==============================================================================
--- incubator/imperius/trunk/imperius-splcore/src/main/java/org/apache/imperius/spl/parser/statements/PolicyStatement.java (original)
+++ incubator/imperius/trunk/imperius-splcore/src/main/java/org/apache/imperius/spl/parser/statements/PolicyStatement.java Fri Jan 11 10:56:30 2008
@@ -1,37 +1,37 @@
-/*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-//
-
-/**
- * @author Neeraj Joshi <jn...@us.ibm.com>
- *
- */
-package org.apache.imperius.spl.parser.statements;
-
-import org.apache.imperius.spl.external.Actuator;
-import org.apache.imperius.spl.external.DataCollector;
-import org.apache.imperius.spl.parser.exceptions.SPLException;
-
-
-public interface PolicyStatement
-{
-
- int getPriority();
-
- int evaluate(DataCollector dc,Actuator ac) throws SPLException;
-
- String toString();
-
- String getAuditLogString();
-}
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+//
+
+/**
+ * @author Neeraj Joshi <jn...@us.ibm.com>
+ *
+ */
+package org.apache.imperius.spl.parser.statements;
+
+import org.apache.imperius.spl.external.Actuator;
+import org.apache.imperius.spl.external.DataCollector;
+import org.apache.imperius.spl.parser.exceptions.SPLException;
+
+
+public interface PolicyStatement
+{
+
+ int getPriority();
+
+ int evaluate(DataCollector dc,Actuator ac) throws SPLException;
+
+ String toString();
+
+ String getAuditLogString();
+}
Propchange: incubator/imperius/trunk/imperius-splcore/src/main/java/org/apache/imperius/spl/parser/statements/PolicyStatement.java
------------------------------------------------------------------------------
svn:eol-style = native