From imperius-commits-return-23-apmail-incubator-imperius-commits-archive=incubator.apache.org@incubator.apache.org Sat Dec 22 21:03:46 2007 Return-Path: Delivered-To: apmail-incubator-imperius-commits-archive@locus.apache.org Received: (qmail 44886 invoked from network); 22 Dec 2007 21:03:46 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 22 Dec 2007 21:03:46 -0000 Received: (qmail 85014 invoked by uid 500); 22 Dec 2007 21:03:35 -0000 Delivered-To: apmail-incubator-imperius-commits-archive@incubator.apache.org Received: (qmail 85004 invoked by uid 500); 22 Dec 2007 21:03:35 -0000 Mailing-List: contact imperius-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: imperius-dev@incubator.apache.org Delivered-To: mailing list imperius-commits@incubator.apache.org Delivered-To: moderator for imperius-commits@incubator.apache.org Received: (qmail 38978 invoked by uid 99); 22 Dec 2007 19:35:36 -0000 X-ASF-Spam-Status: No, hits=-100.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r606479 [23/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... Date: Sat, 22 Dec 2007 19:34:03 -0000 To: imperius-commits@incubator.apache.org From: jneeraj@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20071222193440.E82F61A9859@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Added: incubator/imperius/trunk/trunk/modules/imperius-splcore/src/org/apache/imperius/spl/parser/util/InternalClientFactory.java URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/trunk/modules/imperius-splcore/src/org/apache/imperius/spl/parser/util/InternalClientFactory.java?rev=606479&view=auto ============================================================================== --- incubator/imperius/trunk/trunk/modules/imperius-splcore/src/org/apache/imperius/spl/parser/util/InternalClientFactory.java (added) +++ incubator/imperius/trunk/trunk/modules/imperius-splcore/src/org/apache/imperius/spl/parser/util/InternalClientFactory.java Sat Dec 22 11:33:46 2007 @@ -0,0 +1,39 @@ +/* + * 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 + * + */ + +package org.apache.imperius.spl.parser.util; + +import org.apache.imperius.spl.external.InternalClient; + +public class InternalClientFactory +{ + private static InternalClient _internalClient; + + public static void registerInternalClient(InternalClient dc) + { + _internalClient = dc; + } + + public static InternalClient getInternalClient() + { + return _internalClient; + } + +} Added: incubator/imperius/trunk/trunk/modules/imperius-splcore/src/org/apache/imperius/spl/parser/util/KeyStringToMapConvertor.java URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/trunk/modules/imperius-splcore/src/org/apache/imperius/spl/parser/util/KeyStringToMapConvertor.java?rev=606479&view=auto ============================================================================== --- incubator/imperius/trunk/trunk/modules/imperius-splcore/src/org/apache/imperius/spl/parser/util/KeyStringToMapConvertor.java (added) +++ incubator/imperius/trunk/trunk/modules/imperius-splcore/src/org/apache/imperius/spl/parser/util/KeyStringToMapConvertor.java Sat Dec 22 11:33:46 2007 @@ -0,0 +1,111 @@ +/* + * 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 + * + */ +package org.apache.imperius.spl.parser.util; + +import java.util.HashMap; +import java.util.Map; +import java.util.logging.Level; +import java.util.logging.Logger; + +import org.apache.imperius.util.SPLLogger; + + +public class KeyStringToMapConvertor +{ + private static Logger logger = SPLLogger.getSPLLogger().getLogger(); + + private static final String sourceClass="ExpressionUtility"; + + + public static Map getMapOfKeys(String keyValues) + { + logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "getMapOfKeys"); + + String keyString = keyValues; + if(logger.isLoggable(Level.FINE)) + logger.fine(Thread.currentThread().getName()+"keyString "+keyString); + + //System.out.println("keyValues " + keyValues); + keyString = keyString.substring(keyString.indexOf('.') + 1); + Map keysMap = new HashMap(); + if (keyString.startsWith("&&")) + { + keyString = keyString.substring(2); + } + while (keyString.indexOf('$') != -1) + { + String keyValue = ""; + String keyName = keyString.substring(0, keyString.indexOf('$')); + //System.out.println(" keyString keyName keyValue " + keyString + " "+ keyName + " " + keyValue); + if (keyName.indexOf('.') != -1) + { + keyName = keyName.substring(keyName.indexOf('.') + 1); + //System.out.println(" keyString keyName keyValue " + keyString+ " " + keyName + " " + keyValue); + } + keyName = keyName.trim().toLowerCase(); + keyString = keyString.substring(keyString.indexOf('$') + 1); + //System.out.println(" keyString keyName keyValue " + keyString + " "+ keyName + " " + keyValue); + if (keyString.indexOf("&&") != -1) + { + keyValue = keyString.substring(0, keyString.indexOf("&&")); + //System.out.println(" keyString keyName keyValue " + keyString+ " " + keyName + " " + keyValue); + keyString = keyString.substring(keyString.indexOf("&&") + 2); + //System.out.println(" keyString keyName keyValue " + keyString+ " " + keyName + " " + keyValue); + } + else + { + keyValue = keyString; + //System.out.println(" keyString keyName keyValue " + keyString+ " " + keyName + " " + keyValue); + keyString = ""; + //System.out.println(" keyString keyName keyValue " + keyString+ " " + keyName + " " + keyValue); + } + //System.out.println(" keyString keyName keyValue " + keyString + " "+ keyName + " " + keyValue); + //System.out.println("CIMObjectInstance keyName: "+ keyName.toLowerCase() + " keyValue : " + keyValue); + if(logger.isLoggable(Level.FINE)) + logger.fine(Thread.currentThread().getName()+"keyName, keyValue "+keyName+ " , "+ keyValue); + + keysMap.put(keyName, keyValue); + } + + logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "getMapOfKeys"); + + return keysMap; + } + + public static String KeyStringToClassName(String keyValues) + { + logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "KeyStringToClassName"); + + + String className = keyValues.substring(0, keyValues.indexOf('.')); + if (className != null) + { + logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "KeyStringToClassName"); + + return className; + } + else + { + logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "KeyStringToClassName"); + + return null; + } + } +} Added: incubator/imperius/trunk/trunk/modules/imperius-splcore/src/org/apache/imperius/spl/parser/util/TypeInfo.java URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/trunk/modules/imperius-splcore/src/org/apache/imperius/spl/parser/util/TypeInfo.java?rev=606479&view=auto ============================================================================== --- incubator/imperius/trunk/trunk/modules/imperius-splcore/src/org/apache/imperius/spl/parser/util/TypeInfo.java (added) +++ incubator/imperius/trunk/trunk/modules/imperius-splcore/src/org/apache/imperius/spl/parser/util/TypeInfo.java Sat Dec 22 11:33:46 2007 @@ -0,0 +1,102 @@ +/* + * 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 + * + */ + +package org.apache.imperius.spl.parser.util; + +import org.apache.imperius.spl.external.TypeConstants; +import org.apache.imperius.spl.parser.exceptions.SPLException; + + +public class TypeInfo +{ + private int _splType = TypeConstants.INVALID; + private String _referenceTypeName = null; + private boolean _isArray = false; + + + public TypeInfo() + { + + + } + public TypeInfo(int type) + { + _splType = type; + _referenceTypeName = null; + _isArray = false; + } + + public TypeInfo(TypeInfo type) + { + _splType = type.getType(); + _referenceTypeName = type.getReferenceTypeName(); + _isArray = type.getIsArray(); + } + + public TypeInfo(int splType, String referenceTypeName, boolean isArr) throws SPLException + { + if(TypeResolver.isValidType(splType)) + { + _splType = splType; + _referenceTypeName = referenceTypeName; + _isArray = isArr; + } + else + { + throw new SPLException("invalid type" + splType); + } + } + + public String getReferenceTypeName() { + return _referenceTypeName; + } + + public void setReferenceTypeName(String typeName) { + _referenceTypeName = typeName; + } + + public int getType() { + return _splType; + } + + public void setType(int type) { + _splType = type; + } + + public boolean getIsArray() { + return _isArray; + } + + + public void setIsArray(boolean array) { + _isArray = array; + } + + public void copy(TypeInfo tp) + { + _isArray = tp.getIsArray(); + _splType = tp.getType(); + _referenceTypeName = tp.getReferenceTypeName(); + } + + + + +} Added: incubator/imperius/trunk/trunk/modules/imperius-splcore/src/org/apache/imperius/spl/parser/util/TypeResolver.java URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/trunk/modules/imperius-splcore/src/org/apache/imperius/spl/parser/util/TypeResolver.java?rev=606479&view=auto ============================================================================== --- incubator/imperius/trunk/trunk/modules/imperius-splcore/src/org/apache/imperius/spl/parser/util/TypeResolver.java (added) +++ incubator/imperius/trunk/trunk/modules/imperius-splcore/src/org/apache/imperius/spl/parser/util/TypeResolver.java Sat Dec 22 11:33:46 2007 @@ -0,0 +1,522 @@ +/* + * 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.util; + + + +import java.util.List; + +import org.apache.imperius.spl.external.Expression; +import org.apache.imperius.spl.external.TypeConstants; +import org.apache.imperius.spl.parser.exceptions.IllegalExpressionTypeException; +import org.apache.imperius.spl.parser.exceptions.IllegalParameterTypeException; +import org.apache.imperius.spl.parser.exceptions.SPLException; +import org.apache.imperius.spl.parser.exceptions.TypesNotAssignableException; + + + + +/** + * Provides Number Expression Type resolution. + * + */ +public class TypeResolver +{ + + + +// private static final String sourceClass="TypeConstants"; + + + + /* + * public static final byte BYTE = 0; public static final byte SHORT = 1; + * public static final byte INTEGER = 2; public static final byte LONG = 3; + * public static final byte FLOAT = 4; public static final byte DOUBLE = 5; + */ + + /** + * Determines the numeric type that should be used to interpret a collection + * of Number operands. Throws a + * ClassCastException if the operands collection contains + * objects that are not of type Number. + * + * + * @param operands + * an array of Number operands + * @return a byte code corresponding to the resolved type + * @throws ClassCastException + * if the collection does not contain Number + * operands[i]s + * @throws IllegalExpressionTypeException + */ + public static int resolveType(Number[] operands) + throws IllegalExpressionTypeException + { + + + int resolvedType = TypeConstants.byteType; + + for (int i = 0; i < operands.length; i++) + { + if (operands[i] instanceof Double) + { + resolvedType = TypeConstants.doubleType; + break; + } + else if (operands[i] instanceof Float) + { + if (resolvedType < TypeConstants.floatType) + resolvedType = TypeConstants.floatType; + } + else if (operands[i] instanceof Long) + { + if (resolvedType < TypeConstants.longType) + resolvedType = TypeConstants.longType; + } + else if (operands[i] instanceof Integer) + { + if (resolvedType < TypeConstants.intType) + resolvedType = TypeConstants.intType; + } + else if (operands[i] instanceof Short) + { + if (resolvedType < TypeConstants.shortType) + resolvedType = TypeConstants.shortType; + } + } + + + + return resolvedType; + } + + /** + * Determines the numeric type that should be used to interpret the Object + * operands of a binary expression accoring to the Java Numeric Promotion + * rules. + *

+ * + * For reference: 2.6.9 Numeric Promotion Numeric promotion is applied to + * the operands of an arithmetic operator. Numeric promotion contexts allow + * the use of an identity conversion (Section 2.6.1) or a widening primitive + * conversion (Section 2.6.2). Numeric promotions are used to convert the + * operands of a numeric operator to a common type where an operation can be + * performed. The two kinds of numeric promotion are unary numeric promotion + * and binary numeric promotion. The analogous conversions in C are called + * "the usual unary conversions" and "the usual binary conversions." Numeric + * promotion is not a general feature of Java, but rather a property of the + * specific definitions of built-in operators. An operator that applies + * unary numeric promotion to a single operand of numeric type converts an + * operand of type byte, short, or char to int, and otherwise leaves the + * operand alone. The operands of the shift operators are promoted + * independently using unary numeric promotions. + *

+ * + * When an operator applies binary numeric promotion to a pair of numeric + * operands, the following rules apply, in order, using widening conversion + * (Section 2.6.2) to convert operands as necessary: If either operand is of + * type double, the other is converted to double. Otherwise, if either + * operand is of type float, the other is converted to float. Otherwise, if + * either operand is of type long, the other is converted to long. + * Otherwise, both operands are converted to type int. + *

+ * Throws a NullPointerException if either operand is null. + * + * @param leftOperand + * left operand of a binary expression + * @param rightOperand + * right operand of a binary expression + * @return a byte code corresponding to the resolved type + * @throws SPLException + * @throws java.lang.NullPointerException + * if there is null operand + */ + public static TypeInfo binaryNumericPromotionResolver(TypeInfo ltOperand, + TypeInfo rtOperand) throws SPLException + { + int leftOperand = ltOperand.getType(); + int rightOperand = rtOperand.getType(); + + + if (leftOperand == TypeConstants.doubleType + || rightOperand == TypeConstants.doubleType) + { + + + return new TypeInfo(TypeConstants.doubleType); + } + else if (leftOperand == TypeConstants.floatType + || rightOperand == TypeConstants.floatType) + { + + + return new TypeInfo(TypeConstants.floatType); + } + else if (leftOperand == TypeConstants.longType + || rightOperand == TypeConstants.longType) + { + + + return new TypeInfo(TypeConstants.longType); + } + else + { + + + return new TypeInfo(TypeConstants.intType,null,false); + } + + } + + /** + * Determines the numeric type that should be used to interpret the Object + * operand of a unary expression accoring to the Java Numeric Promotion + * rules. + *

+ * + * For reference: 2.6.9 Numeric Promotion Numeric promotion is applied to + * the operands of an arithmetic operator. Numeric promotion contexts allow + * the use of an identity conversion (Section 2.6.1) or a widening primitive + * conversion (Section 2.6.2). Numeric promotions are used to convert the + * operands of a numeric operator to a common type where an operation can be + * performed. The two kinds of numeric promotion are unary numeric promotion + * and binary numeric promotion. The analogous conversions in C are called + * "the usual unary conversions" and "the usual binary conversions." Numeric + * promotion is not a general feature of Java, but rather a property of the + * specific definitions of built-in operators. An operator that applies + * unary numeric promotion to a single operand of numeric type converts an + * operand of type byte, short, or char to int, and otherwise leaves the + * operand alone. The operands of the shift operators are promoted + * independently using unary numeric promotions. + *

+ * + * When an operator applies binary numeric promotion to a pair of numeric + * operands, the following rules apply, in order, using widening conversion + * (Section 2.6.2) to convert operands as necessary: If either operand is of + * type double, the other is converted to double. Otherwise, if either + * operand is of type float, the other is converted to float. Otherwise, if + * either operand is of type long, the other is converted to long. + * Otherwise, both operands are converted to type int. + *

+ * Throws a NullPointerException if either operand is null. + * + * @param operand + * operand of a unary expression + * @return a byte code corresponding to the resolved type + * @throws TypesNotAssignableException + * @throws java.lang.NullPointerException + * if the operand is null + * + * public static byte unaryNumericPromotionResolver(Number operand) throws + * NullPointerException { + * + * if (operand instanceof Double) { return DOUBLE; } + * + * if (operand instanceof Float) { return FLOAT; } + * + * if(operand instanceof Long ) { return LONG; } // short byte char get + * converted to integer return INTEGER; h} + */ + + public static boolean isTypeAssignableForEquality(TypeInfo leftType, + TypeInfo rightType) + { + + + boolean res = false; + //System.out.println("isTypeAssignableForEquality"); + if (isNumeric(leftType) && isNumeric(rightType)) + { + res = true; + } + else if (isBoolean(leftType) && isBoolean(rightType)) + { + res = true; + } + else if (isString(leftType) && isString(rightType)) + { + res = true; + } + else if (isCalendar(leftType) && isCalendar(rightType)) + { + res = true; + } + else if (isReference(leftType) && isReference(rightType)) + { + res = true; + } + + + + return res; + } + + public static boolean isTypeAssignableForRelation(TypeInfo leftType, + TypeInfo rightType) + { + + + boolean res = false; + if (isNumeric(leftType) && isNumeric(rightType)) + { + res = true; + } + else if (isString(leftType) && isString(rightType)) + { + res = true; + } + else if (isCalendar(leftType) && isCalendar(rightType)) + { + res = true; + } + + + + return res; + } + + public static TypeInfo resolveType(TypeInfo leftType, TypeInfo rightType) + throws SPLException + { + + + // TBD + return binaryNumericPromotionResolver(leftType, rightType); + + } + + public static boolean isNumeric(TypeInfo type) + { + int tp = type.getType(); + + if (tp == TypeConstants.byteType || tp == TypeConstants.shortType + || tp == TypeConstants.intType || tp == TypeConstants.longType + || tp == TypeConstants.floatType + || tp == TypeConstants.doubleType) + { + + + return true; + } + + + + return false; + } + + public static boolean isBoolean(TypeInfo type) + { + int tp = type.getType(); + + if (tp == TypeConstants.booleanType) + { + + + return true; + } + + + + return false; + } + + public static boolean isReference(TypeInfo type) + { + int tp = type.getType(); + + if (tp == TypeConstants.referenceType) + { + + + return true; + } + + + + return false; + } + + + public static boolean isString(TypeInfo tp) + { + int type = tp.getType(); + + if (type == TypeConstants.stringType) + { + + + return true; + } + + + + return false; + } + + public static boolean isCalendar(TypeInfo tp) + { + int type = tp.getType(); + + if (type == TypeConstants.dateTime) + { + + + return true; + } + + + + return false; + } + + /*public static boolean validateActualParameterTypes(ArrayList formalParams, + ArrayList passedParams) throws SPLException + { + + + + if (formalParams.size() == passedParams.size()) + { + for (int i = 0; i < formalParams.size(); i++) + { + Integer fParam = (Integer) formalParams.get(i); + Expression pParam = (Expression) passedParams.get(i); + + if (!TypeResolver.isTypeAssignableForEquality( + fParam.intValue(), pParam.getType())) + { + //System.out.println("type mismatch fParam.intValue()="+fParam.intValue()+" pParam.getType()"+pParam.getType()); + + throw new IllegalParameterTypeException("param mismatch"); + } + + } + } + + + return true; + }*/ + + public static TypeInfo unaryNumericPromotionResolver(TypeInfo te) + throws NullPointerException + { + int type = te.getType(); + TypeInfo retType = new TypeInfo(); + + + if (type == TypeConstants.doubleType) + { + retType.setType(TypeConstants.doubleType); + + return retType; + } + + if (type == TypeConstants.floatType) + { + + retType.setType(TypeConstants.floatType); + return retType; + } + + if (type == TypeConstants.longType) + { + retType.setType(TypeConstants.longType); + + return retType; + } + + + + // short byte char get converted to integer + retType.setType(TypeConstants.intType); + return retType; + } + + public static boolean validateActualParameterTypes(List formalParams, + List passedParams) throws SPLException + { + + + + if (formalParams.size() == passedParams.size()) + { + for (int i = 0; i < formalParams.size(); i++) + { + TypeInfo fParam = (TypeInfo) formalParams.get(i); + Expression pParam = (Expression) passedParams.get(i); + + if (!TypeResolver.isTypeAssignableForEquality( + fParam, pParam.getType())) + { + //System.out.println("type mismatch fParam.intValue()="+fParam+" pParam.getType()"+pParam.getType()); + + throw new IllegalParameterTypeException("param mismatch"); + } + + } + } + + + return true; + } + + public static boolean areTypesEqual(TypeInfo t1, TypeInfo t2) + { + boolean result = false; + if(t1.getType() == t2.getType() && t1.getIsArray() == t2.getIsArray()) + { + + if(t1.getType() == TypeConstants.referenceType) + { + if(t1.getReferenceTypeName().equalsIgnoreCase(t2.getReferenceTypeName())) + { + result = true; + } + else{ + result = false; + } + } + else + { + result = true; + } + + } + + + return result; + } + + public static boolean isValidType(int tp) + { + + if (tp > 0 && tp < 14) + { + return true; + } + else + { + return false; + } + } + +}