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 jn...@apache.org on 2007/12/22 19:34:03 UTC
svn commit: r606479 [12/30] - in /incubator/imperius/trunk/trunk: ./
modules/ modules/imperius-javaspl/ modules/imperius-javaspl/resources/
modules/imperius-javaspl/resources/samples/
modules/imperius-javaspl/resources/samples/computersystem/ modules/i...
Added: incubator/imperius/trunk/trunk/modules/imperius-splcore/src/org/apache/imperius/spl/parser/expressions/MethodExpression.java
URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/trunk/modules/imperius-splcore/src/org/apache/imperius/spl/parser/expressions/MethodExpression.java?rev=606479&view=auto
==============================================================================
--- incubator/imperius/trunk/trunk/modules/imperius-splcore/src/org/apache/imperius/spl/parser/expressions/MethodExpression.java (added)
+++ incubator/imperius/trunk/trunk/modules/imperius-splcore/src/org/apache/imperius/spl/parser/expressions/MethodExpression.java Sat Dec 22 11:33:46 2007
@@ -0,0 +1,118 @@
+/*
+ * 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 Prashant Baliga <pr...@in.ibm.com>
+ *
+ */
+
+package org.apache.imperius.spl.parser.expressions;
+
+import java.util.ArrayList;
+import java.util.logging.Logger;
+
+import org.apache.imperius.spl.external.Expression;
+import org.apache.imperius.spl.parser.compiler.symboltable.MethodSymbol;
+import org.apache.imperius.spl.parser.compiler.symboltable.SPLSymbolTable;
+import org.apache.imperius.spl.parser.exceptions.SPLException;
+import org.apache.imperius.spl.parser.util.TypeInfo;
+import org.apache.imperius.util.SPLLogger;
+
+
+public class MethodExpression implements Expression
+{
+
+ private TypeInfo returnType = new TypeInfo();
+
+ private ArrayList passedParams;
+
+// private SPLSymbolTable symTab;
+
+ private static Logger logger = SPLLogger.getSPLLogger().getLogger();
+ private final String sourceClass="MethodExpression";
+
+
+ public MethodExpression(MethodSymbol ms, ArrayList pList,
+ SPLSymbolTable symTab)
+ {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "MethodExpression");
+
+
+ returnType = ms.getType();
+ passedParams = pList;
+// this.symTab = symTab;
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "MethodExpression");
+
+ }
+
+ public Object evaluate()
+ {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "evaluate");
+
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "evaluate");
+
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public TypeInfo getType()
+ {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "getType");
+
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "getType");
+
+ // TODO Auto-generated method stub
+ return returnType;
+ }
+
+ public boolean validate() throws SPLException
+ {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "validate");
+
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "validate");
+
+ // TODO Auto-generated method stub
+ return true;
+ }
+
+ public boolean isArray()
+ {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "isArray");
+
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "isArray");
+
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public String toString()
+ {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "toString");
+
+ String className=this.getClass().getName();
+
+ String str=className.substring(className.lastIndexOf(".")+1, className.length())+"[ "+ this.passedParams.toString()+" ]";
+
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "toString");
+
+ return str;
+ }
+
+ public String getReferenceTypeName() throws SPLException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
Added: incubator/imperius/trunk/trunk/modules/imperius-splcore/src/org/apache/imperius/spl/parser/expressions/MultipleArgumentExpression.java
URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/trunk/modules/imperius-splcore/src/org/apache/imperius/spl/parser/expressions/MultipleArgumentExpression.java?rev=606479&view=auto
==============================================================================
--- incubator/imperius/trunk/trunk/modules/imperius-splcore/src/org/apache/imperius/spl/parser/expressions/MultipleArgumentExpression.java (added)
+++ incubator/imperius/trunk/trunk/modules/imperius-splcore/src/org/apache/imperius/spl/parser/expressions/MultipleArgumentExpression.java Sat Dec 22 11:33:46 2007
@@ -0,0 +1,165 @@
+/*
+ * 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 Prashant Baliga <pr...@in.ibm.com>
+ *
+ */
+
+package org.apache.imperius.spl.parser.expressions;
+
+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.exceptions.SPLException;
+import org.apache.imperius.spl.parser.util.TypeInfo;
+import org.apache.imperius.util.SPLLogger;
+
+
+public abstract class MultipleArgumentExpression implements Expression
+{
+
+ protected List _expressions;
+
+ // protected Expression rhsExp;
+
+
+ private static Logger logger = SPLLogger.getSPLLogger().getLogger();
+ private final String sourceClass="MultipleArgumentExpression";
+
+
+ protected TypeInfo _dataType = new TypeInfo();
+
+ public MultipleArgumentExpression(List exprList)
+ {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "MultipleArgumentExpression");
+
+
+ if (exprList != null)
+ {
+
+ if (exprList.size() != 0)
+ {
+ this._expressions = new ArrayList();
+ for (int i = 0; i < exprList.size(); i++)
+ {
+
+ Expression l = (Expression) exprList.get(i);
+
+ if (l == null)
+ {
+ logger.severe( "expression passed in is null.");
+
+ throw new IllegalArgumentException(
+ "expression passed in is null.");
+ }
+ else
+ {
+ this._expressions.add(l);
+
+ }
+ }
+ }
+ else
+ {
+ logger.severe(Thread.currentThread().getName()+" "+"No of arguments should be > 0, but is "
+ + exprList.size());
+
+ throw new IllegalArgumentException(
+ "No of arguments should be > 0, but is "
+ + exprList.size());
+ }
+ }
+ else
+ {
+ logger.severe(Thread.currentThread().getName()+" "+"No of arguments passed required number of arguments is 2");
+
+ throw new IllegalArgumentException(
+ "No of arguments passed required number of arguments is 2");
+ }
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "MultipleArgumentExpression");
+
+ }
+
+ public abstract Object evaluate() throws SPLException;
+
+ public TypeInfo getType()
+ {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "getType");
+
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "getType");
+
+ return _dataType;
+ }
+
+ public boolean isArray()
+ {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "isArray");
+
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "isArray");
+
+ return this._dataType.getIsArray();
+ }
+
+ public String toString()
+ {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "toString");
+
+ String className=this.getClass().getName();
+
+ String str=className.substring(className.lastIndexOf(".")+1, className.length())+"( ";
+
+ if (this._expressions.size() != 0)
+ {
+
+ for (int i = 0; i < this._expressions.size(); i++)
+ {
+
+ Expression l = (Expression) this._expressions.get(i);
+
+ if (l == null)
+ {
+ logger.severe( "expression passed in is null.");
+
+ throw new IllegalArgumentException(
+ "expression passed in is null.");
+ }
+ else
+ {
+ str+=l.toString();
+
+ }
+ if(i != this._expressions.size() -1){
+ str+=" , ";
+ }
+ }
+ str+=" )";
+ }
+
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "toString");
+
+ return str;
+ }
+
+ public abstract boolean validate() throws SPLException;
+
+ public String getReferenceTypeName() throws SPLException
+ {
+ //throw new SPLException("Expression not of Reference type");
+ return null;
+ }
+}
Added: incubator/imperius/trunk/trunk/modules/imperius-splcore/src/org/apache/imperius/spl/parser/expressions/NumericExpression.java
URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/trunk/modules/imperius-splcore/src/org/apache/imperius/spl/parser/expressions/NumericExpression.java?rev=606479&view=auto
==============================================================================
--- incubator/imperius/trunk/trunk/modules/imperius-splcore/src/org/apache/imperius/spl/parser/expressions/NumericExpression.java (added)
+++ incubator/imperius/trunk/trunk/modules/imperius-splcore/src/org/apache/imperius/spl/parser/expressions/NumericExpression.java Sat Dec 22 11:33:46 2007
@@ -0,0 +1,28 @@
+/*
+ * 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 Prashant Baliga <pr...@in.ibm.com>
+ *
+ */
+
+package org.apache.imperius.spl.parser.expressions;
+
+import org.apache.imperius.spl.external.Expression;
+
+public interface NumericExpression extends Expression
+{
+
+}
Added: incubator/imperius/trunk/trunk/modules/imperius-splcore/src/org/apache/imperius/spl/parser/expressions/QuadrupleArgumentExpression.java
URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/trunk/modules/imperius-splcore/src/org/apache/imperius/spl/parser/expressions/QuadrupleArgumentExpression.java?rev=606479&view=auto
==============================================================================
--- incubator/imperius/trunk/trunk/modules/imperius-splcore/src/org/apache/imperius/spl/parser/expressions/QuadrupleArgumentExpression.java (added)
+++ incubator/imperius/trunk/trunk/modules/imperius-splcore/src/org/apache/imperius/spl/parser/expressions/QuadrupleArgumentExpression.java Sat Dec 22 11:33:46 2007
@@ -0,0 +1,148 @@
+/*
+ * 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 Xiping Wang
+ *
+ */
+package org.apache.imperius.spl.parser.expressions;
+
+import java.util.List;
+import java.util.logging.Logger;
+
+import org.apache.imperius.spl.external.Expression;
+import org.apache.imperius.spl.parser.exceptions.SPLException;
+import org.apache.imperius.spl.parser.util.TypeInfo;
+import org.apache.imperius.util.SPLLogger;
+
+
+
+public abstract class QuadrupleArgumentExpression implements Expression
+{
+
+ protected Expression _exp1;
+
+ protected Expression _exp2;
+
+ protected Expression _exp3;
+
+ protected Expression _exp4;
+
+
+
+ protected TypeInfo _dataType = new TypeInfo();
+
+ private static Logger logger = SPLLogger.getSPLLogger().getLogger();
+ private static final String sourceClass="class";
+
+
+
+ public boolean isArray()
+ {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "isArray");
+
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "isArray");
+
+
+ return _dataType.getIsArray();
+ }
+
+
+
+ public QuadrupleArgumentExpression(List exprList)
+ {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "QuadrupleArgumentExpression");
+
+ if (exprList != null)
+ {
+ if (exprList.size() == 4)
+ {
+ Expression e1 = (Expression) exprList.get(0);
+ Expression e2 = (Expression) exprList.get(1);
+ Expression e3 = (Expression) exprList.get(2);
+ Expression e4 = (Expression) exprList.get(3);
+ if (e1 == null)
+ {
+ logger.severe(
+ "first expression passed in is null.");
+
+ throw new IllegalArgumentException(
+ "first expression passed in is null.");
+ }
+
+ if (e2 == null)
+ {
+ logger.severe(
+ "second expression passed in is null.");
+
+ throw new IllegalArgumentException(
+ "second expression passed in is null.");
+ }
+
+ if (e3 == null)
+ {
+ logger.severe(
+ "third expression passed in is null.");
+
+ throw new IllegalArgumentException(
+ "third expression passed in is null.");
+ }
+
+ if (e4 == null)
+ {
+ logger.severe(
+ "fourth expression passed in is null.");
+
+ throw new IllegalArgumentException(
+ "fourth expression passed in is null.");
+ }
+
+ this._exp1 = e1;
+ this._exp2 = e2;
+ this._exp3 = e3;
+ this._exp4 = e4;
+
+ }
+ else
+ {
+ logger.severe(Thread.currentThread().getName()+" "+"number of parameters not 4");
+
+ throw new IllegalArgumentException("number of parameters not 4");
+ }
+ }
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "QuadrupleArgumentExpression");
+
+ }
+
+ public abstract Object evaluate() throws SPLException;
+
+ public TypeInfo getType()
+ {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "getType");
+
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "getType");
+
+ return _dataType;
+ }
+
+ public abstract boolean validate() throws SPLException;
+
+ public String getReferenceTypeName() throws SPLException
+ {
+ return null;
+ //throw new SPLException("ReferenceTypeName not supported");
+ }
+
+}
Added: incubator/imperius/trunk/trunk/modules/imperius-splcore/src/org/apache/imperius/spl/parser/expressions/ReferenceExpression.java
URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/trunk/modules/imperius-splcore/src/org/apache/imperius/spl/parser/expressions/ReferenceExpression.java?rev=606479&view=auto
==============================================================================
--- incubator/imperius/trunk/trunk/modules/imperius-splcore/src/org/apache/imperius/spl/parser/expressions/ReferenceExpression.java (added)
+++ incubator/imperius/trunk/trunk/modules/imperius-splcore/src/org/apache/imperius/spl/parser/expressions/ReferenceExpression.java Sat Dec 22 11:33:46 2007
@@ -0,0 +1,30 @@
+/*
+ * 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 Prashant Baliga <pr...@in.ibm.com>
+ *
+ */
+
+package org.apache.imperius.spl.parser.expressions;
+
+import org.apache.imperius.spl.external.Expression;
+
+public interface ReferenceExpression extends Expression
+{
+
+ String getReferenceTypeName();
+
+}
Added: incubator/imperius/trunk/trunk/modules/imperius-splcore/src/org/apache/imperius/spl/parser/expressions/SingleArgumentExpression.java
URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/trunk/modules/imperius-splcore/src/org/apache/imperius/spl/parser/expressions/SingleArgumentExpression.java?rev=606479&view=auto
==============================================================================
--- incubator/imperius/trunk/trunk/modules/imperius-splcore/src/org/apache/imperius/spl/parser/expressions/SingleArgumentExpression.java (added)
+++ incubator/imperius/trunk/trunk/modules/imperius-splcore/src/org/apache/imperius/spl/parser/expressions/SingleArgumentExpression.java Sat Dec 22 11:33:46 2007
@@ -0,0 +1,118 @@
+/*
+ * 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
+ *
+ */
+
+package org.apache.imperius.spl.parser.expressions;
+
+import java.util.List;
+import java.util.logging.Logger;
+
+import org.apache.imperius.spl.external.Expression;
+import org.apache.imperius.spl.parser.exceptions.SPLException;
+import org.apache.imperius.spl.parser.util.TypeInfo;
+import org.apache.imperius.util.SPLLogger;
+
+
+public abstract class SingleArgumentExpression implements Expression
+{
+ protected Expression _exp;
+
+ private static Logger logger = SPLLogger.getSPLLogger().getLogger();
+
+ private final String sourceClass="SingleArgumentExpression";
+
+ protected TypeInfo _dataType = new TypeInfo();;
+
+
+
+ public boolean isArray()
+ {
+ return _dataType.getIsArray();
+ }
+
+ public SingleArgumentExpression(List exprList)
+ {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "SingleArgumentExpression");
+
+ if (exprList != null)
+ {
+ if (exprList.size() == 1)
+ {
+ Expression e = (Expression) exprList.get(0);
+ if (e == null)
+ {
+ logger.severe(Thread.currentThread().getName()+" "+"expression passed in is null.");
+ throw new IllegalArgumentException(
+ "expression passed in is null.");
+ }
+
+ this._exp = e;
+
+ }
+ else
+ {
+ logger.severe( "expression List size is not equal to one.");
+ throw new IllegalArgumentException(
+ "expression List size is not equal to one.");
+ }
+ }
+ else
+ {
+ logger.severe( "expression List passed in is null.");
+ throw new IllegalArgumentException(
+ "expression List passed in is null.");
+ }
+
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "SingleArgumentExpression");
+
+ }
+
+ public abstract Object evaluate() throws SPLException;
+
+ public TypeInfo getType()
+ {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "getType");
+
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "getType");
+
+ return _dataType;
+ }
+
+ public String toString()
+ {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "toString");
+
+ String className=this.getClass().getName();
+
+ String str=className.substring(className.lastIndexOf(".")+1, className.length())+"( "+ this._exp.toString()+" )";
+
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "toString");
+
+ return str;
+ }
+
+ public abstract boolean validate() throws SPLException;
+
+ public String getReferenceTypeName() throws SPLException
+ {
+ //throw new SPLException("Expression not a referenceExpression");
+ return null;
+ }
+
+}
Added: incubator/imperius/trunk/trunk/modules/imperius-splcore/src/org/apache/imperius/spl/parser/expressions/StringExpression.java
URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/trunk/modules/imperius-splcore/src/org/apache/imperius/spl/parser/expressions/StringExpression.java?rev=606479&view=auto
==============================================================================
--- incubator/imperius/trunk/trunk/modules/imperius-splcore/src/org/apache/imperius/spl/parser/expressions/StringExpression.java (added)
+++ incubator/imperius/trunk/trunk/modules/imperius-splcore/src/org/apache/imperius/spl/parser/expressions/StringExpression.java Sat Dec 22 11:33:46 2007
@@ -0,0 +1,28 @@
+/*
+ * 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 Prashant Baliga <pr...@in.ibm.com>
+ *
+ */
+
+package org.apache.imperius.spl.parser.expressions;
+
+import org.apache.imperius.spl.external.Expression;
+
+public interface StringExpression extends Expression
+{
+
+}
Added: incubator/imperius/trunk/trunk/modules/imperius-splcore/src/org/apache/imperius/spl/parser/expressions/TimeZoneExpression.java
URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/trunk/modules/imperius-splcore/src/org/apache/imperius/spl/parser/expressions/TimeZoneExpression.java?rev=606479&view=auto
==============================================================================
--- incubator/imperius/trunk/trunk/modules/imperius-splcore/src/org/apache/imperius/spl/parser/expressions/TimeZoneExpression.java (added)
+++ incubator/imperius/trunk/trunk/modules/imperius-splcore/src/org/apache/imperius/spl/parser/expressions/TimeZoneExpression.java Sat Dec 22 11:33:46 2007
@@ -0,0 +1,163 @@
+/*
+ * 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 Prashant Baliga <pr...@in.ibm.com>
+ *
+ */
+
+package org.apache.imperius.spl.parser.expressions;
+
+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.external.TypeConstants;
+import org.apache.imperius.spl.parser.compiler.symboltable.SPLSymbolTable;
+import org.apache.imperius.spl.parser.exceptions.SPLException;
+import org.apache.imperius.spl.parser.expressions.impl.StringConstant;
+import org.apache.imperius.spl.parser.util.TypeInfo;
+import org.apache.imperius.spl.parser.util.TypeResolver;
+import org.apache.imperius.util.SPLLogger;
+
+
+public class TimeZoneExpression extends SingleArgumentExpression implements
+ StringExpression
+{
+
+ public static final String className = TimeZoneExpression.class.getName();
+
+
+
+ private static Logger logger = SPLLogger.getSPLLogger().getLogger();
+
+ private static final String sourceClass="TimeZoneExpression";
+
+
+ public boolean isArray()
+ {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "isArray");
+
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "isArray");
+
+
+ return _dataType.getIsArray();
+ }
+
+ public TimeZoneExpression(List exprList, boolean validateExpression)
+ throws SPLException
+ {
+
+ super(exprList);
+
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "TimeZoneExpression");
+
+ if (validateExpression)
+ {
+ if (!validate())
+ {
+ logger.severe(Thread.currentThread().getName()+" "+"validation error: " + className
+ + " has wrong data type passed in.");
+
+ throw new SPLException("validation error: " + className
+ + " has wrong data type passed in.");
+ }
+ }
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "TimeZoneExpression");
+
+ }
+
+ public Object evaluate() throws SPLException
+ {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "evaluate");
+
+
+ try
+ {
+
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "evaluate");
+
+ return this._exp.evaluate();
+ }
+ catch (Exception e)
+ {
+ logger.severe(Thread.currentThread().getName()+" "+"evaluation errro: " + e.toString());
+ throw new SPLException("evaluation errro: " + e.toString());
+ }
+
+ }
+
+ public static TimeZoneExpression getInstance(String tzid,
+ SPLSymbolTable sTab) throws SPLException
+ {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "getType");
+
+
+ Expression e = new StringConstant(tzid);
+ List aList = new ArrayList();
+ aList.add(e);
+ boolean validateExp = true;
+ if (sTab.getSymbolTableType() == SPLSymbolTable.COLLECT)
+ {
+ validateExp = false;
+ }
+
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "getType");
+
+ return new TimeZoneExpression(aList, validateExp);
+ }
+
+ public boolean validate() throws SPLException
+ {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "validate");
+
+
+ TypeInfo eType = _exp.getType();
+
+ _dataType = new TypeInfo(TypeConstants.stringType,null,false);
+ if (TypeResolver.isString(eType))
+ {
+
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "validate");
+
+ return true;
+ }
+
+
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "validate");
+
+ return false;
+ }
+
+ public String toString()
+ {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "toString");
+
+String className=this.getClass().getName();
+
+ String str=className.substring(className.lastIndexOf(".")+1, className.length())+"( "+ this._exp.toString()+" )";
+
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "toString");
+
+ return str;
+ }
+
+ public String getReferenceTypeName() throws SPLException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
Added: incubator/imperius/trunk/trunk/modules/imperius-splcore/src/org/apache/imperius/spl/parser/expressions/TripleArgumentExpression.java
URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/trunk/modules/imperius-splcore/src/org/apache/imperius/spl/parser/expressions/TripleArgumentExpression.java?rev=606479&view=auto
==============================================================================
--- incubator/imperius/trunk/trunk/modules/imperius-splcore/src/org/apache/imperius/spl/parser/expressions/TripleArgumentExpression.java (added)
+++ incubator/imperius/trunk/trunk/modules/imperius-splcore/src/org/apache/imperius/spl/parser/expressions/TripleArgumentExpression.java Sat Dec 22 11:33:46 2007
@@ -0,0 +1,147 @@
+/*
+ * 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 Prashant Baliga <pr...@in.ibm.com>
+ *
+ */
+
+package org.apache.imperius.spl.parser.expressions;
+
+import java.util.List;
+import java.util.logging.Logger;
+
+import org.apache.imperius.spl.external.Expression;
+import org.apache.imperius.spl.parser.exceptions.SPLException;
+import org.apache.imperius.spl.parser.util.TypeInfo;
+import org.apache.imperius.util.SPLLogger;
+
+
+public abstract class TripleArgumentExpression implements Expression
+{
+
+ protected Expression _lhsExp;
+
+ protected Expression _midExp;
+
+ protected Expression _rhsExp;
+
+ protected TypeInfo _dataType = new TypeInfo();
+
+ private static Logger logger = SPLLogger.getSPLLogger().getLogger();
+
+ private final String sourceClass="TripleArgumentExpression";
+
+
+
+ public boolean isArray()
+ {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "isArray");
+
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "isArray");
+
+
+ return _dataType.getIsArray();
+ }
+
+
+
+ public TripleArgumentExpression(List exprList) throws SPLException
+ {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "TripleArgumentExpression");
+
+
+ if (exprList != null)
+ {
+ if (exprList.size() == 3)
+ {
+ Expression l = (Expression) exprList.get(0);
+ Expression m = (Expression) exprList.get(1);
+ Expression r = (Expression) exprList.get(2);
+ if (l == null)
+ {
+ logger.severe(Thread.currentThread().getName()+" "+"left hand side expression passed in is null.");
+ throw new IllegalArgumentException(
+ "left hand side expression passed in is null.");
+ }
+
+ if (m == null)
+ {
+ logger.severe(Thread.currentThread().getName()+" "+"middle expression passed in is null.");
+ throw new IllegalArgumentException(
+ "middle expression passed in is null.");
+ }
+
+ if (r == null)
+ {
+ logger.severe(Thread.currentThread().getName()+" "+"right hand side expression passed in is null.");
+ throw new IllegalArgumentException(
+ "right hand side expression passed in is null.");
+ }
+
+ this._lhsExp = l;
+ this._midExp = m;
+ this._rhsExp = r;
+
+ }
+ else
+ {
+ logger.severe(Thread.currentThread().getName()+" "+"number of parameters passed is not 3.");
+ throw new IllegalArgumentException(
+ "number of parameters passed is not 3.");
+ }
+ }
+ else
+ {
+ logger.severe(Thread.currentThread().getName()+" "+"parameters passed are null.");
+ throw new IllegalArgumentException("parameters passed are null.");
+ }
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "TripleArgumentExpression");
+
+ }
+
+ public abstract Object evaluate() throws SPLException;
+
+ public TypeInfo getType()
+ {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "getType");
+
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "getType");
+
+ return _dataType;
+ }
+
+ public String toString()
+ {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "toString");
+
+ String className=this.getClass().getName();
+
+ String str=className.substring(className.lastIndexOf(".")+1, className.length())+"( "+this._lhsExp.toString()+" , "+this._midExp.toString()+" , "+this._rhsExp.toString()+" )";
+
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "toString");
+
+ return str;
+ }
+
+
+ public abstract boolean validate() throws SPLException;
+
+ public String getReferenceTypeName() throws SPLException
+ {
+ //throw new SPLException("Expression is not of type reference");
+ return null;
+ }
+}
Added: incubator/imperius/trunk/trunk/modules/imperius-splcore/src/org/apache/imperius/spl/parser/expressions/ZeroArgumentExpression.java
URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/trunk/modules/imperius-splcore/src/org/apache/imperius/spl/parser/expressions/ZeroArgumentExpression.java?rev=606479&view=auto
==============================================================================
--- incubator/imperius/trunk/trunk/modules/imperius-splcore/src/org/apache/imperius/spl/parser/expressions/ZeroArgumentExpression.java (added)
+++ incubator/imperius/trunk/trunk/modules/imperius-splcore/src/org/apache/imperius/spl/parser/expressions/ZeroArgumentExpression.java Sat Dec 22 11:33:46 2007
@@ -0,0 +1,93 @@
+/*
+ * 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 Prashant Baliga <pr...@in.ibm.com>
+ *
+ */
+
+package org.apache.imperius.spl.parser.expressions;
+
+import java.util.List;
+import java.util.logging.Logger;
+
+import org.apache.imperius.spl.external.Expression;
+import org.apache.imperius.spl.parser.exceptions.SPLException;
+import org.apache.imperius.spl.parser.util.TypeInfo;
+import org.apache.imperius.util.SPLLogger;
+
+
+public abstract class ZeroArgumentExpression implements Expression
+{
+ private static Logger logger = SPLLogger.getSPLLogger().getLogger();
+
+ private final String sourceClass="ZeroArgumentExpression";
+
+ protected TypeInfo _dataType = new TypeInfo();
+
+
+
+ public boolean isArray()
+ {
+ return this._dataType.getIsArray();
+ }
+
+ public ZeroArgumentExpression(List exprList)
+ {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "ZeroArgumentExpression");
+
+ /*if (exprList != null)
+ { throw new IllegalArgumentException(
+ "ZeroArgumentExpression expression should not be passed arguments");
+
+ }*/
+
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "ZeroArgumentExpression");
+
+ }
+
+ public abstract Object evaluate() throws SPLException;
+
+ public TypeInfo getType()
+ {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "getType");
+
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "getType");
+
+ return _dataType;
+ }
+
+ public String toString()
+ {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "toString");
+
+ String className=this.getClass().getName();
+
+ String str=className.substring(className.lastIndexOf(".")+1, className.length())+"()";
+
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "toString");
+
+ return str;
+ }
+
+ public abstract boolean validate() throws SPLException;
+
+ public String getReferenceTypeName() throws SPLException
+ {
+ //throw new SPLException("This expression is not of reference type");
+ return null;
+ }
+
+}
Added: incubator/imperius/trunk/trunk/modules/imperius-splcore/src/org/apache/imperius/spl/parser/expressions/impl/Abs.java
URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/trunk/modules/imperius-splcore/src/org/apache/imperius/spl/parser/expressions/impl/Abs.java?rev=606479&view=auto
==============================================================================
--- incubator/imperius/trunk/trunk/modules/imperius-splcore/src/org/apache/imperius/spl/parser/expressions/impl/Abs.java (added)
+++ incubator/imperius/trunk/trunk/modules/imperius-splcore/src/org/apache/imperius/spl/parser/expressions/impl/Abs.java Sat Dec 22 11:33:46 2007
@@ -0,0 +1,164 @@
+/*
+ * 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 Xiping Change Log: 3/9/07: Neeraj Joshi: Changed signature to take a
+ * list of expressions and boolean This will help in reflection
+ *
+ */
+
+package org.apache.imperius.spl.parser.expressions.impl;
+
+import java.util.List;
+import java.util.logging.Logger;
+
+import org.apache.imperius.spl.external.TypeConstants;
+import org.apache.imperius.spl.parser.exceptions.SPLException;
+import org.apache.imperius.spl.parser.expressions.NumericExpression;
+import org.apache.imperius.spl.parser.expressions.SingleArgumentExpression;
+import org.apache.imperius.spl.parser.util.TypeInfo;
+import org.apache.imperius.spl.parser.util.TypeResolver;
+import org.apache.imperius.util.SPLLogger;
+
+
+
+public class Abs extends SingleArgumentExpression implements NumericExpression
+{
+
+ public static final String className = Abs.class.getName();
+
+ private static Logger logger = SPLLogger.getSPLLogger().getLogger();
+
+
+ private static final String sourceClass="Abs";
+
+
+
+ public Abs(List exprList, boolean validateExpression)
+ throws SPLException
+ {
+ super(exprList);
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "Abs");
+
+
+ if (validateExpression)
+ {
+ if (!validate())
+ {
+ logger.severe(Thread.currentThread().getName()+" "+"validation error: " + className
+ + " has wrong data type passed in.");
+ throw new SPLException("validation error: " + className
+ + " has wrong data type passed in.");
+ }
+ }
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "Abs");
+
+ }
+
+ public Object evaluate() throws SPLException
+ {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "evaluate");
+ Object returnVal = abs((Number) _exp.evaluate());
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "evaluate" + returnVal);
+
+ return returnVal;
+ }
+
+ public static Number abs(Number o1) throws SPLException
+ {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "Number");
+
+ try
+ {
+ Number[] o = new Number[1];
+ o[0] = o1;
+
+ int resolvedType = TypeResolver.resolveType(o);
+
+ if (resolvedType == TypeConstants.doubleType)
+ {
+ Double dVal = new Double(Math.abs(o1.doubleValue()));
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "Number" + dVal);
+
+ return dVal;
+ }
+ else if (resolvedType == TypeConstants.floatType)
+ {
+ Float fVal = new Float(Math.abs(o1.floatValue()));
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "Number" + fVal);
+
+ return fVal;
+ }
+ else if (resolvedType == TypeConstants.longType)
+ {
+ Long lVal = new Long(Math.abs(o1.longValue()));
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "Number" + lVal);
+
+ return lVal;
+ }
+ else
+ {
+ Integer iVal = new Integer(Math.abs(o1.intValue()));
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "Number" + iVal);
+
+ return iVal;
+ }
+ }
+ catch (Exception e)
+ {
+ logger.severe(Thread.currentThread().getName()+" "+"evaluation error: " + e.toString());
+
+ throw new SPLException("evaluation error: " + e.toString());
+ }
+ }
+
+ public boolean validate() throws SPLException
+ {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "validate");
+
+ TypeInfo eType = _exp.getType();
+
+ // dataType = TypeConstants.numericType;
+ if (TypeResolver.isNumeric(eType) && !eType.getIsArray())
+ {
+ _dataType.copy(eType);
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "validate");
+
+ return true;
+ }
+
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "validate");
+
+ return false;
+ }
+
+ public String getReferenceTypeName() throws SPLException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public String toString()
+ {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "toString");
+
+ String str = "Abs("+ this._exp.toString() + ")";
+
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "toString");
+
+ return str;
+ }
+
+}
Added: incubator/imperius/trunk/trunk/modules/imperius-splcore/src/org/apache/imperius/spl/parser/expressions/impl/Addition.java
URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/trunk/modules/imperius-splcore/src/org/apache/imperius/spl/parser/expressions/impl/Addition.java?rev=606479&view=auto
==============================================================================
--- incubator/imperius/trunk/trunk/modules/imperius-splcore/src/org/apache/imperius/spl/parser/expressions/impl/Addition.java (added)
+++ incubator/imperius/trunk/trunk/modules/imperius-splcore/src/org/apache/imperius/spl/parser/expressions/impl/Addition.java Sat Dec 22 11:33:46 2007
@@ -0,0 +1,180 @@
+/*
+ * 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 Xiping Change Log: 3/9/07: Neeraj Joshi: Changed signature to take a
+ * list of expressions and boolean This will help in reflection 3/9/07:
+ * Neeraj Joshi: Updated the method for determining return type to use
+ * binary numeric promotion
+ *
+ */
+
+package org.apache.imperius.spl.parser.expressions.impl;
+
+import java.util.List;
+import java.util.logging.Logger;
+
+import org.apache.imperius.spl.external.TypeConstants;
+import org.apache.imperius.spl.parser.exceptions.IllegalExpressionTypeException;
+import org.apache.imperius.spl.parser.exceptions.SPLException;
+import org.apache.imperius.spl.parser.expressions.DoubleArgumentExpression;
+import org.apache.imperius.spl.parser.expressions.NumericExpression;
+import org.apache.imperius.spl.parser.util.TypeInfo;
+import org.apache.imperius.spl.parser.util.TypeResolver;
+import org.apache.imperius.util.SPLLogger;
+
+
+
+public class Addition extends DoubleArgumentExpression implements
+ NumericExpression
+{
+
+ public static final String className = Addition.class.getName();
+
+ private static Logger logger = SPLLogger.getSPLLogger().getLogger();
+ private static final String sourceClass="Addition";
+
+
+
+ public Addition(List exprList, boolean evaluateExpression)
+ throws SPLException
+ {
+ super(exprList);
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "Addition");
+
+
+ if (evaluateExpression)
+ {
+
+ if (!validate())
+ {
+
+ logger.severe(Thread.currentThread().getName()+" "+"validation error: wrong data type passed into "
+ + className + ".");
+
+ throw new SPLException(
+ "validation error: wrong data type passed into "
+ + className + ".");
+ }
+ }
+
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "Addition");
+
+ }
+
+ public Object evaluate() throws SPLException
+ {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "evaluate");
+
+ try
+ {
+ Number lhs = (Number) _lhsExp.evaluate();
+ Number rhs = (Number) _rhsExp.evaluate();
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "evaluate");
+
+ return plus(lhs, rhs);
+ }
+ catch (Exception e)
+ {
+ logger.severe(Thread.currentThread().getName()+" "+"evaluation error: " + e.toString());
+
+ throw new SPLException("evaluation error: " + e.toString());
+ }
+
+ }
+
+ private static Number plus(Number o1, Number o2)
+ throws IllegalExpressionTypeException
+ {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "plus");
+
+ Number[] o = new Number[2];
+ o[0] = o1;
+ o[1] = o2;
+
+ int resolvedType = TypeResolver.resolveType(o);
+
+ if (resolvedType == TypeConstants.doubleType)
+ {
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "plus");
+
+ return new Double(o1.doubleValue() + o2.doubleValue());
+ }
+ else if (resolvedType == TypeConstants.floatType)
+ {
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "plus");
+
+ return new Float(o1.floatValue() + o2.floatValue());
+ }
+ else if (resolvedType == TypeConstants.longType)
+ {
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "plus");
+
+ return new Long(o1.longValue() + o2.longValue());
+ }
+ else if (resolvedType == TypeConstants.shortType)
+ {
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "plus");
+
+ return new Long(o1.shortValue() + o2.shortValue());
+ }
+ else if (resolvedType == TypeConstants.byteType)
+ {
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "plus");
+
+ return new Long(o1.byteValue() + o2.byteValue());
+ }
+ else
+ {
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "plus");
+
+ return new Integer(o1.intValue() + o2.intValue());
+ }
+ }
+
+ public boolean validate() throws SPLException
+ {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "validate");
+
+ TypeInfo lType = _lhsExp.getType();
+ TypeInfo rType = _rhsExp.getType();
+
+ // dataType = TypeConstants.numericType;
+ if (TypeResolver.isNumeric(lType) && TypeResolver.isNumeric(rType) &&
+ !lType.getIsArray() && !rType.getIsArray())
+ {
+ _dataType = TypeResolver.binaryNumericPromotionResolver(lType, rType);
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "validate");
+
+ return true;
+ }
+
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "validate");
+
+ return false;
+ }
+
+ public String toString()
+ {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "toString");
+
+ String str = this._lhsExp.toString() + " + " + this._rhsExp.toString();
+
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "toString");
+
+ return str;
+ }
+}
Added: incubator/imperius/trunk/trunk/modules/imperius-splcore/src/org/apache/imperius/spl/parser/expressions/impl/AllInCollection.java
URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/trunk/modules/imperius-splcore/src/org/apache/imperius/spl/parser/expressions/impl/AllInCollection.java?rev=606479&view=auto
==============================================================================
--- incubator/imperius/trunk/trunk/modules/imperius-splcore/src/org/apache/imperius/spl/parser/expressions/impl/AllInCollection.java (added)
+++ incubator/imperius/trunk/trunk/modules/imperius-splcore/src/org/apache/imperius/spl/parser/expressions/impl/AllInCollection.java Sat Dec 22 11:33:46 2007
@@ -0,0 +1,474 @@
+/*
+ * 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 Prashant Baliga <pr...@in.ibm.com>
+ *
+ */
+
+package org.apache.imperius.spl.parser.expressions.impl;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+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.exceptions.IllegalParameterTypeException;
+import org.apache.imperius.spl.parser.exceptions.SPLException;
+import org.apache.imperius.spl.parser.expressions.TripleArgumentExpression;
+import org.apache.imperius.spl.parser.util.ExpressionUtility;
+import org.apache.imperius.spl.parser.util.TypeInfo;
+import org.apache.imperius.spl.parser.util.TypeResolver;
+import org.apache.imperius.util.SPLLogger;
+
+
+public class AllInCollection extends TripleArgumentExpression implements
+ Expression
+{
+
+ public String className = InCollection.class.toString();
+
+ public List expressionList = null;
+
+ public String operationString = null;
+
+ private static Logger logger = SPLLogger.getSPLLogger().getLogger();
+ private static final String sourceClass="AllInCollection";
+
+
+
+ public static final String LOR = "OR";
+
+ public static final String LAND = "AND";
+
+ public static final String BXOR = "XOR";
+
+ public static final String NOT_EQUAL = "NOT_EQUAL";
+
+ public static final String EQUAL = "EQUAL";
+
+ public static final String LT = "LESS";
+
+ public static final String GT = "GREATER";
+
+ public static final String LE = "LESS_OR_EQUAL";
+
+ public static final String GE = "GREATER_OR_EQUAL";
+
+ public static final String PLUS = "PLUS";
+
+ public static final String MINUS = "MINUS";
+
+ public static final String STAR = "MULTIPLY";
+
+ public static final String DIV = "DIVIDE";
+
+ public AllInCollection(List exprList, boolean evaluateExpression)
+ throws SPLException
+ {
+ super(exprList);
+
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "AllInCollection");
+
+ //System.out.println("AllInCollection");
+ if (evaluateExpression)
+ {
+ //System.out.println("evaluateExpression " + evaluateExpression);
+ if (!validate())
+ {
+
+ logger.severe(
+ "validation error: wrong data type passed in "
+ + this._dataType);
+
+ throw new SPLException(
+ "validation error: wrong data type passed in "
+ + this._dataType);
+ }
+ }
+ _dataType.setType(TypeConstants.booleanType);
+ this._dataType.setIsArray(false);
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "AllInCollection");
+
+ }
+
+ public Object evaluate() throws SPLException
+ {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "evaluate");
+ //System.out.println("AllInCollection:evaluate");
+ Expression lhsExpression = (Expression) this._lhsExp;
+ Expression rhsExpression = (Expression) this._rhsExp;
+
+ if (rhsExpression.isArray())
+ {
+ //System.out.println("rhs is of type Basic Collection");
+ Object rhsResult = rhsExpression.evaluate();
+ //System.out.println("rhsResult , class " + rhsResult + " "+ rhsResult.getClass());
+ if (!(rhsResult instanceof java.util.List))
+ {
+
+ logger.severe(
+ "rhsResult is not of type List");
+
+ throw new SPLException("rhsResult is not of type List");
+ }
+ Boolean result = Boolean.FALSE;
+ ArrayList rhsResultArray = (ArrayList) rhsResult;
+ //System.out.println("resultArray size " + rhsResultArray.size()+ " to string " + rhsResultArray.toString());
+ //System.out.println("LHS expression is of type "+ lhsExpression.getType());
+ if ((rhsResultArray != null) && (!rhsResultArray.isEmpty()))
+ {
+ Object lhsResult = (Object) lhsExpression.evaluate();
+ //System.out.println("lhsResult " + lhsResult.toString());
+ Iterator rhsResultIt = rhsResultArray.iterator();
+ while (rhsResultIt.hasNext())
+ {
+ Object value = (Object) rhsResultIt.next();
+ //System.out.println("rhsResult element " + value.toString());
+ //System.out.println("operationString " + operationString);
+ if (operationString.equalsIgnoreCase(LAND))
+ {
+ if ((!(value instanceof Boolean))
+ || (!(lhsResult instanceof Boolean)))
+ {
+ logger.severe(
+ "LHS or RHS result is not of type Boolean");
+
+ throw new SPLException(
+ "LHS or RHS result is not of type Boolean");
+ }
+ else
+ {
+ Boolean Value1 = (Boolean) lhsResult;
+ Boolean Value2 = (Boolean) value;
+ boolean res = Value1.booleanValue()
+ && Value2.booleanValue();
+ if (!res)
+ {
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "AllInCollection");
+
+ return new Boolean(!res);
+ }
+ }
+ }
+ else if (operationString.equalsIgnoreCase(LOR))
+ {
+ if ((!(value instanceof Boolean))
+ || (!(lhsResult instanceof Boolean)))
+ {
+ logger.severe(
+ "LHS or RHS result is not of type Boolean");
+
+ throw new SPLException(
+ "LHS or RHS result is not of type Boolean");
+ }
+ else
+ {
+ Boolean Value1 = (Boolean) lhsResult;
+ Boolean Value2 = (Boolean) value;
+ boolean res = Value1.booleanValue()
+ || Value2.booleanValue();
+ if (!res)
+ {
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "AllInCollection");
+
+ return new Boolean(!res);
+ }
+ }
+
+ }
+ else if (operationString.equalsIgnoreCase(BXOR))
+ {
+ if ((!(value instanceof Boolean))
+ || (!(lhsResult instanceof Boolean)))
+ {
+ logger.severe(
+ "LHS or RHS result is not of type Boolean");
+
+ throw new SPLException(
+ "LHS or RHS result is not of type Boolean");
+ }
+ else
+ {
+ Boolean Value1 = (Boolean) lhsResult;
+ Boolean Value2 = (Boolean) value;
+ boolean res = (Value1.booleanValue() && !Value2
+ .booleanValue())
+ || (!Value1.booleanValue() && Value2
+ .booleanValue());
+ if (!res)
+ {
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "AllInCollection");
+
+ return new Boolean(!res);
+ }
+ }
+
+ }
+
+ else if (operationString.equalsIgnoreCase(EQUAL))
+ {
+ Object Value1 = lhsResult;
+ Object Value2 = value;
+ if (!(ExpressionUtility.compare(Value2, Value1) == 0))
+ {
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "AllInCollection");
+
+ return Boolean.FALSE;
+ }
+ }
+ else if (operationString.equalsIgnoreCase(NOT_EQUAL))
+ {
+ Object Value1 = lhsResult;
+ Object Value2 = value;
+ if (!(ExpressionUtility.compare(Value2, Value1) != 0))
+ {
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "AllInCollection");
+
+ return Boolean.FALSE;
+ }
+ }
+ else if (operationString.equalsIgnoreCase(GT))
+ {
+ Object Value1 = lhsResult;
+ Object Value2 = value;
+ // //System.out.println("Value1 GT Value2 "+Value1+"
+ // "+Value2);
+ if (!(ExpressionUtility.compare(Value2, Value1) > 0))
+ {
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "AllInCollection");
+
+ return Boolean.FALSE;
+ }
+
+ }
+ else if (operationString.equalsIgnoreCase(GE))
+ {
+ Object Value1 = lhsResult;
+ Object Value2 = value;
+ if (!(ExpressionUtility.compare(Value2, Value1) >= 0))
+ {
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "AllInCollection");
+
+ return Boolean.FALSE;
+ }
+ }
+ else if (operationString.equalsIgnoreCase(LT))
+ {
+ Object Value1 = lhsResult;
+ Object Value2 = value;
+ // //System.out.println("Value1 LT Value2 "+Value1+"
+ // "+Value2);
+ if (!(ExpressionUtility.compare(Value2, Value1) < 0))
+ {
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "AllInCollection");
+
+ return Boolean.FALSE;
+ }
+
+ }
+ else if (operationString.equalsIgnoreCase(LE))
+ {
+ Object Value1 = lhsResult;
+ Object Value2 = value;
+ if (!(ExpressionUtility.compare(Value2, Value1) <= 0))
+ {
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "AllInCollection");
+
+ return Boolean.FALSE;
+ }
+ }
+ else
+ {
+
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "AllInCollection");
+
+ //System.out.println("did not match");
+ return Boolean.FALSE;
+ }
+
+ }
+ //System.out.println("result=true");
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "AllInCollection");
+
+ result = Boolean.TRUE;
+
+ return result;
+ }
+ else
+ {
+ logger.severe(
+ "the RHS of AllInCollection expression is null BasicCollection");
+
+ throw new IllegalParameterTypeException(
+ "the RHS of AllInCollection expression is null BasicCollection");
+ }
+ }
+ else
+ {
+ logger.severe(
+ "the RHS of AllInCollection expression should be of BasicCollection type");
+
+ throw new IllegalParameterTypeException(
+ "the RHS of AllInCollection expression should be of BasicCollection type");
+ }
+
+ }
+
+ public boolean validate() throws SPLException
+ {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "validate");
+
+ //System.out.println("AllInCollection : validate ");
+ Expression expression1 = (Expression) this._lhsExp;
+ Expression expression2 = (Expression) this._midExp;
+ Expression expression3 = (Expression) this._rhsExp;
+ TypeInfo leftType = expression1.getType();
+ TypeInfo middleType = expression2.getType();
+ TypeInfo rightType = expression3.getType();
+
+ if (!rightType.getIsArray())
+ {
+ logger.severe(
+ "Last Expression should be a collection");
+
+ throw new SPLException("Last Expression should be a collection");
+ }
+
+ if (leftType.getIsArray())
+ {
+ logger.severe(
+ "First Expression cannot be a collection");
+
+ throw new SPLException("First Expression cannot be a collection");
+ }
+
+ if (!TypeResolver.isString(middleType))
+ {
+ logger.severe(
+ "Middle Expression should be a string describing the Operation");
+ throw new SPLException(
+ "Middle Expression should be a string describing the Operation");
+ }
+ this.operationString = (String) expression2.evaluate();
+ if (this.operationString == null)
+ {
+ logger.severe(
+ "Operation string is null");
+
+ throw new SPLException("Operation string is null");
+ }
+ if (this.operationString == null)
+ {
+ logger.severe(
+ "Operation type is "
+ + this.operationString);
+
+ throw new SPLException("Operation type is "
+ + this.operationString);
+ }
+
+ if (operationString.equalsIgnoreCase(LAND)
+ || operationString.equalsIgnoreCase(LOR)
+ || operationString.equalsIgnoreCase(BXOR))
+ {
+ if (TypeResolver.isBoolean(leftType))
+ {
+ if (TypeResolver.isBoolean(rightType))
+ {
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "validate");
+
+ return true;
+
+ }
+ else
+ {
+ logger.severe(
+ "LHS is of type Boolean but RHS is not of type Boolean");
+
+ throw new SPLException(
+ "LHS is of type Boolean but RHS is not of type Boolean");
+ }
+ }
+ else
+ {
+ logger.severe(
+ "Operation is of type Boolean but LHS is not of type boolean");
+
+ throw new SPLException(
+ "Operation is of type Boolean but LHS is not of type boolean");
+ }
+ }
+ else if (operationString.equalsIgnoreCase(EQUAL)
+ || operationString.equalsIgnoreCase(NOT_EQUAL)
+ || operationString.equalsIgnoreCase(GT)
+ || operationString.equalsIgnoreCase(GE)
+ || operationString.equalsIgnoreCase(LT)
+ || operationString.equalsIgnoreCase(LE))
+ {
+
+ if (TypeResolver.isTypeAssignableForEquality(leftType, rightType))
+ {
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "validate");
+
+ return true;
+ }
+ else if (TypeResolver.isTypeAssignableForRelation(leftType,
+ rightType))
+ {
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "validate");
+
+ return true;
+ }
+ else
+ {
+ logger.severe(
+ "types are not assignable for Relation or Equality");
+
+ throw new SPLException(
+ "types are not assignable for Relation or Equality");
+ }
+ }
+ else
+ {
+
+ logger.severe(
+ "operationString is not supported by AllInCollection");
+
+ throw new SPLException(
+ "operationString is not supported by AllInCollection");
+ }
+
+ }
+
+ public String getReferenceTypeName() throws SPLException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public String toString()
+ {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "toString");
+
+ String str = "AllInCollection("+ this._lhsExp.toString() + "," + this._midExp.toString() + "," + this._rhsExp.toString() + ")";
+
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "toString");
+
+ return str;
+ }
+
+}