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 [22/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/statements/impl/PolicyDefinition.java
URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/trunk/modules/imperius-splcore/src/org/apache/imperius/spl/parser/statements/impl/PolicyDefinition.java?rev=606479&view=auto
==============================================================================
--- incubator/imperius/trunk/trunk/modules/imperius-splcore/src/org/apache/imperius/spl/parser/statements/impl/PolicyDefinition.java (added)
+++ incubator/imperius/trunk/trunk/modules/imperius-splcore/src/org/apache/imperius/spl/parser/statements/impl/PolicyDefinition.java Sat Dec 22 11:33:46 2007
@@ -0,0 +1,346 @@
+/*
+ * 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.impl;
+
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.apache.imperius.spl.external.Actuator;
+import org.apache.imperius.spl.external.DataCollector;
+import org.apache.imperius.spl.external.Expression;
+import org.apache.imperius.spl.parser.compiler.symboltable.SPLSymbolTable;
+import org.apache.imperius.spl.parser.exceptions.SPLException;
+import org.apache.imperius.spl.parser.statements.ActionBlock;
+import org.apache.imperius.spl.parser.statements.PolicyStatement;
+import org.apache.imperius.util.SPLLogger;
+
+
+public class PolicyDefinition implements PolicyStatement
+{
+ private DeclarationStatement _declStmt;
+ private Expression _condition;
+ private ActionBlock _decision;
+ int _priority;
+ private SPLSymbolTable _symTab;
+ private String auditloggerString = "";
+
+ private static Logger logger = SPLLogger.getSPLLogger().getLogger();
+
+// private static Logger auditLogger = SPLLogger.getSPLLogger().getAuditLogger();
+
+ private static final String sourceClass="PolicyDefinition";
+
+
+
+ public PolicyDefinition(DeclarationStatement d, Expression con, ActionBlock dec,
+ String priority, SPLSymbolTable sTab)
+ {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "PolicyDefinition");
+
+ _declStmt = d;
+ _condition = con;
+ if(con==null){
+ if(logger.isLoggable(Level.FINE))
+ logger.fine(Thread.currentThread().getName()+"PolicyDefinition condition is null");
+ }
+ else{
+ if(logger.isLoggable(Level.FINE))
+ logger.fine(Thread.currentThread().getName()+"PolicyDefinition condition "+con.toString());
+ }
+ _decision = dec;
+ if(dec==null){
+ if(logger.isLoggable(Level.FINE))
+ logger.fine(Thread.currentThread().getName()+"PolicyDefinition decision is null");
+ }
+ else{
+ if(logger.isLoggable(Level.FINE))
+ logger.fine(Thread.currentThread().getName()+"PolicyDefinition decision "+dec.toString());
+ }
+
+ _priority = Integer.parseInt(priority);
+ _symTab = sTab;
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "PolicyDefinition");
+
+ }
+
+ public Expression getCondition() {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "getCondition");
+
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "getCondition");
+
+ return _condition;
+ }
+
+ public void setCondition(Expression condition) {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "setCondition");
+
+ _condition = condition;
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "setCondition");
+
+ }
+
+ public ActionBlock getDecision() {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "getDecision");
+
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "getDecision");
+
+ return _decision;
+ }
+
+ public void setDecision(ActionBlock decision) {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "setDecision");
+
+ _decision = decision;
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "setDecision");
+
+ }
+
+ public DeclarationStatement getDeclStmt() {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "getDeclStmt");
+
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "getDeclStmt");
+
+ return _declStmt;
+ }
+
+ public void setDeclStmt(DeclarationStatement declStmt) {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "setDeclStmt");
+
+ _declStmt = declStmt;
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "setDeclStmt");
+
+ }
+
+ public int getPriority() {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "getPriority");
+
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "getPriority");
+
+ return _priority;
+ }
+
+ public void setPriority(int priority) {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "setPriority");
+ _priority = priority;
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "setPriority");
+
+
+ }
+
+ public SPLSymbolTable getSymTab() {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "getSymTab");
+
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "getSymTab");
+
+ return _symTab;
+ }
+
+ public void setSymTab(SPLSymbolTable symTab) {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "setSymTab");
+
+ _symTab = symTab;
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "setSymTab");
+
+ }
+
+ public int evaluate(DataCollector dc , Actuator ac) throws SPLException
+ {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "evaluate");
+ this.auditloggerString="";
+ int result = SPLPolicy.POLICY_EVALUATED_SUCCESSFULLY;
+ if(_declStmt != null)
+ {
+ _declStmt.evaluate();
+ }
+ if(_condition != null)
+ {
+
+ if(logger.isLoggable(Level.FINE))
+ {
+ logger.fine(Thread.currentThread().getName()+
+ "evaluating condition of Policy Definition");
+ }
+ Boolean conditionResult = (Boolean)_condition.evaluate();
+ System.out.println(" "+"policy :"+_condition.toString());
+ auditloggerString+=" "+"policy :"+_condition.toString()+"\n";
+ System.out.println(" "+"result :"+conditionResult);
+ auditloggerString+=" "+"result :"+conditionResult+"\n";
+
+
+// System.out.println("condition : "+_condition.toString());
+// System.out.println("evaluated to : "+conditionResult);
+
+ if(logger.isLoggable(Level.FINE))
+ {
+ logger.fine(Thread.currentThread().getName()+
+ "condition="+_condition.toString());
+ logger.fine(Thread.currentThread().getName()+
+ "evaluation of condition complete, return value="+conditionResult);
+ }
+// if(auditLogger.isLoggable(Level.FINE))
+// {
+// auditLogger.fine(Thread.currentThread().getName()+
+// "Condition : "+this.getCondition().toString());
+// }
+//
+// if(auditLogger.isLoggable(Level.FINE))
+// {
+// auditLogger.fine(Thread.currentThread().getName()+
+// "Condition Evaluated to : "+conditionResult.toString());
+// }
+
+ if(conditionResult.booleanValue())
+ {
+ if(logger.isLoggable(Level.FINE))
+ logger.fine(Thread.currentThread().getName()+"Condition is True!");
+ //modifyInstance(String className,String namespace,Map instanceKeys, Map properties)
+ if(logger.isLoggable(Level.FINE))
+ logger.fine(Thread.currentThread().getName()+"executing Decision of Policy Definition");
+ //System.out.println("keys string : "+this.symTab.getInstance().getKeys());
+// if(auditLogger.isLoggable(Level.FINE))
+// auditLogger.fine(Thread.currentThread().getName()+" Executing Decision ");
+ boolean executionResult =
+ _decision.execute(ac);
+ System.out.println(" "+"decision executed :"+executionResult);
+ auditloggerString+=" "+"decision executed :"+executionResult+"\n";
+
+// if(auditLogger.isLoggable(Level.FINE))
+// auditLogger.fine(Thread.currentThread().getName()+"PolicyDefinition decision.execute return value="+executionResult);
+
+ if(executionResult)
+ {
+// if(auditLogger.isLoggable(Level.FINE))
+// auditLogger.fine(Thread.currentThread().getName()+" Policy Evaluated Successfully ");
+
+ result = SPLPolicy.POLICY_EVALUATED_SUCCESSFULLY;
+ System.out.println(" "+"sub policy decision execution successful");
+ auditloggerString+=" "+"sub policy decision execution successful"+"\n";
+
+ if(logger.isLoggable(Level.FINE))
+ logger.fine(Thread.currentThread().getName()+"Policy was executed successfully");
+ //System.out.println(" POLICY_EVALUATED_SUCCESSFULLY ");
+
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "evaluate");
+
+ return result;
+ }
+ else{
+
+// auditLogger.severe(Thread.currentThread().getName()+" "+" Policy Evaluation Failed ");
+
+ result = SPLPolicy.POLICY_EVALUATION_FAILED;
+ System.out.println(" "+"sub policy decision execution failed");
+ auditloggerString+=" "+"sub policy decision execution failed"+"\n";
+
+// auditLogger.severe(Thread.currentThread().getName()+" "+"PolicyDefinition Evalaute return value="+result);
+ //System.out.println(" POLICY_EVALUATION_FAILED ");
+
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "evaluate");
+
+ return result;
+ }
+
+ }
+ else
+ {
+// if(auditLogger.isLoggable(Level.FINE))
+// auditLogger.fine(Thread.currentThread().getName()+" Policy was not Evaluated as Condition evaluated to False ");
+
+ if(logger.isLoggable(Level.FINE))
+ logger.fine(Thread.currentThread().getName()+"Condition is False!");
+ //result = SPLPolicy.POLICY_NOT_EVALUATED;
+ if(logger.isLoggable(Level.FINE))
+ logger.fine(Thread.currentThread().getName()+"Policy was not executed");
+ //System.out.println(" CONDITION evaluated to FALSE ");
+
+ System.out.println(" "+"sub policy decision not executed");
+ auditloggerString+=" "+"sub policy decision not executed"+"\n";
+
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "evaluate");
+ if(logger.isLoggable(Level.FINE))
+ logger.fine(Thread.currentThread().getName()+"PolicyDefinition Evalaute return value="+result);
+
+ return result;
+ }
+ }
+ else
+ {
+ System.out.println(" "+"sub policy has no condition");
+ auditloggerString+=" "+"sub policy has no condition"+"\n";
+
+ boolean executionResult=_decision.execute(ac);
+ if(logger.isLoggable(Level.FINE))
+ logger.fine(Thread.currentThread().getName()+"PolicyDefinition decision.execute return value="+executionResult);
+ System.out.println(" "+"decision executed :"+executionResult);
+ auditloggerString+=" "+"decision executed :"+executionResult+"\n";
+
+ if(executionResult)
+ {
+// if(auditLogger.isLoggable(Level.FINE))
+// auditLogger.fine(Thread.currentThread().getName()+"Policy without condition, was executed successfully");
+
+ result = SPLPolicy.POLICY_EVALUATED_SUCCESSFULLY;
+ System.out.println(" "+"sub policy decision execution successful");
+ auditloggerString+=" "+"sub policy decision execution successful"+"\n";
+
+ if(logger.isLoggable(Level.FINE))
+ logger.fine(Thread.currentThread().getName()+"Policy without condition, was executed successfully");
+ //System.out.println(" POLICY_EVALUATED_SUCCESSFULLY ");
+
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "evaluate");
+ if(logger.isLoggable(Level.FINE))
+ logger.fine(Thread.currentThread().getName()+"PolicyDefinition Evalaute return value="+result);
+
+ return result;
+ }
+ else{
+// if(auditLogger.isLoggable(Level.FINE))
+// auditLogger.fine(Thread.currentThread().getName()+"Evaluation of Policy without condition Failed");
+
+ result = SPLPolicy.POLICY_EVALUATION_FAILED;
+ System.out.println(" "+"sub policy decision execution failed");
+ auditloggerString+=" "+"sub policy decision execution failed"+"\n";
+
+ //System.out.println(" POLICY_EVALUATION_FAILED ");
+
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "evaluate");
+ if(logger.isLoggable(Level.FINE))
+ logger.fine(Thread.currentThread().getName()+"PolicyDefinition Evalaute return value="+result);
+
+ return result;
+ }
+ }
+
+
+ }
+
+
+ public String toString(){
+
+ return this._condition.toString();
+
+ }
+
+ public String getAuditLogString() {
+
+ return this.auditloggerString;
+ }
+
+}
Added: incubator/imperius/trunk/trunk/modules/imperius-splcore/src/org/apache/imperius/spl/parser/statements/impl/PolicyGroup.java
URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/trunk/modules/imperius-splcore/src/org/apache/imperius/spl/parser/statements/impl/PolicyGroup.java?rev=606479&view=auto
==============================================================================
--- incubator/imperius/trunk/trunk/modules/imperius-splcore/src/org/apache/imperius/spl/parser/statements/impl/PolicyGroup.java (added)
+++ incubator/imperius/trunk/trunk/modules/imperius-splcore/src/org/apache/imperius/spl/parser/statements/impl/PolicyGroup.java Sat Dec 22 11:33:46 2007
@@ -0,0 +1,191 @@
+/*
+ * 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.impl;
+
+import java.util.logging.Logger;
+
+import org.apache.imperius.spl.external.Actuator;
+import org.apache.imperius.spl.external.DataCollector;
+import org.apache.imperius.spl.parser.compiler.symboltable.SPLSymbolTable;
+import org.apache.imperius.spl.parser.exceptions.SPLException;
+import org.apache.imperius.spl.parser.statements.PolicyStatement;
+import org.apache.imperius.util.SPLLogger;
+
+
+public class PolicyGroup implements PolicyStatement
+{
+
+ private String assocName = "CIM_Component";
+ private String role1="GroupComponent";
+ private String role2="PartComponent";
+ private String auditloggerString = "";
+
+
+ private SPLPolicy cimPolicy;
+ private int priority;
+ private SPLSymbolTable symTab;
+ private static Logger logger = SPLLogger.getSPLLogger().getLogger();
+ private static final String sourceClass="PolicyGroup";
+
+
+
+ public PolicyGroup(String assocName,String role1,String role2,SPLPolicy c,String priority, SPLSymbolTable sTab)
+ {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "PolicyGroup");
+
+ if(!assocName.equals(""))
+ this.assocName = assocName;
+ if(!role1.equals(""))
+ this.role1 = role1;
+ if(!role2.equals(""))
+ this.role2 = role2;
+
+ this.cimPolicy = c;
+ this.priority = Integer.parseInt(priority);
+ this.symTab = sTab;
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "PolicyGroup");
+
+
+ }
+
+
+ public String getAssocName() {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "getAssocName");
+
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "getAssocName");
+
+ return assocName;
+ }
+
+
+ public void setAssocName(String assocName) {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "setAssocName");
+
+ this.assocName = assocName;
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "setAssocName");
+
+ }
+
+
+ public SPLPolicy getCimPolicy() {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "getCimPolicy");
+
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "getCimPolicy");
+
+ return cimPolicy;
+ }
+
+
+ public void setCimPolicy(SPLPolicy cimPolicy) {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "setCimPolicy");
+
+ this.cimPolicy = cimPolicy;
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "setCimPolicy");
+
+ }
+
+
+ public int getPriority() {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "getPriority");
+
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "getPriority");
+
+ return priority;
+ }
+
+
+ public void setPriority(int priority) {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "setPriority");
+
+ this.priority = priority;
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "setPriority");
+
+ }
+
+
+ public String getRole1() {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "getRole1");
+
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "getRole1");
+
+ return role1;
+ }
+
+
+ public void setRole1(String role1) {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "setRole1");
+
+ this.role1 = role1;
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "setRole1");
+
+ }
+
+
+ public String getRole2() {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "getRole2");
+
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "getRole2");
+
+ return role2;
+ }
+
+
+ public void setRole2(String role2) {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "setRole2");
+
+ this.role2 = role2;
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "setRole2");
+
+ }
+
+ public int evaluate(DataCollector dc,Actuator ac) throws SPLException
+ {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "evaluate");
+ this.auditloggerString="";
+ int result = SPLPolicy.POLICY_EVALUATION_FAILED;
+ //System.out.println("Policy Gp::evaluate::symTab.getInstance().getCimObjectName() "+symTab.getAnchorClassList());
+// Map classToInstanceMap = null;
+// Iterator it = classToInstanceMap.keySet().iterator();
+// Object instance = null;
+// while(it.hasNext())
+// {
+// String key = (String)it.next();
+// instance = classToInstanceMap.get(key);
+// }
+ String anchorClassName=(String)symTab.getAnchorClassList().get(0);
+ System.out.println("-----------"+"Starting Evaluation of Policy Group"+"-----------");
+
+ this.auditloggerString+="-----------"+"Starting Evaluation of Policy Group"+"-----------"+"\n";
+ result = cimPolicy.evaluate(dc,ac,anchorClassName,symTab.getDefaultQualifier(),symTab.getInstance(anchorClassName),assocName,role1,role2);
+ this.auditloggerString+=cimPolicy.getAuditLogString();
+ this.auditloggerString+="-----------"+"Completed Evaluation of Policy Group"+"-----------"+"\n";
+ System.out.println("-----------"+"Completed Evaluation of Policy Group"+"-----------");
+
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "evaluate");
+
+ return result;
+ }
+
+
+ public String getAuditLogString() {
+
+ return this.auditloggerString;
+ }
+}
Added: incubator/imperius/trunk/trunk/modules/imperius-splcore/src/org/apache/imperius/spl/parser/statements/impl/PolicyInfo.java
URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/trunk/modules/imperius-splcore/src/org/apache/imperius/spl/parser/statements/impl/PolicyInfo.java?rev=606479&view=auto
==============================================================================
--- incubator/imperius/trunk/trunk/modules/imperius-splcore/src/org/apache/imperius/spl/parser/statements/impl/PolicyInfo.java (added)
+++ incubator/imperius/trunk/trunk/modules/imperius-splcore/src/org/apache/imperius/spl/parser/statements/impl/PolicyInfo.java Sat Dec 22 11:33:46 2007
@@ -0,0 +1,85 @@
+/*
+ * 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.statements.impl;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.apache.imperius.spl.parser.compiler.symboltable.AnchorData;
+import org.apache.imperius.spl.parser.compiler.symboltable.SPLSymbolTable;
+import org.apache.imperius.util.SPLLogger;
+
+public class PolicyInfo {
+
+ private List importStmtList=null;
+ private static Logger logger = SPLLogger.getSPLLogger().getLogger();
+
+ private static String sourceClass = "PolicyInfo";
+
+
+ public PolicyInfo(List importStmtList){
+ this.importStmtList=importStmtList;
+ }
+
+ public Map getClassQualifierMap(){
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+"createInstance");
+
+ Map classQualifier=new HashMap();
+ Iterator it=importStmtList.iterator();
+ while(it.hasNext())
+ {
+
+ if(logger.isLoggable(Level.FINE))
+ logger.fine(Thread.currentThread().getName()+" 1Creating SPL Policy instance :"+importStmtList);
+
+ ImportStatement importStmt=(ImportStatement)it.next();
+ if(logger.isLoggable(Level.FINE))
+ logger.fine(Thread.currentThread().getName()+" 2Creating SPL Policy instance :"+importStmt);
+
+ SPLSymbolTable symtab=importStmt.getSymTab();
+ if(logger.isLoggable(Level.FINE))
+ logger.fine(Thread.currentThread().getName()+" 3Creating SPL Policy instance :"+symtab);
+
+ AnchorData anchor=symtab.getAnchorData();
+ if(logger.isLoggable(Level.FINE))
+ logger.fine(Thread.currentThread().getName()+" 4Creating SPL Policy instance :"+anchor);
+
+ List classes=anchor.getAnchorClassList();
+ if(logger.isLoggable(Level.FINE))
+ logger.fine(Thread.currentThread().getName()+" 5Creating SPL Policy instance :"+classes);
+
+ Iterator classIt=classes.iterator();
+ while(classIt.hasNext()){
+ String classname=(String)classIt.next();
+ String qualifier=anchor.getQualifierForClass(classname);
+ classQualifier.put(classname, qualifier);
+ }
+ }
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+"createInstance");
+
+ return classQualifier;
+ }
+
+}
Added: incubator/imperius/trunk/trunk/modules/imperius-splcore/src/org/apache/imperius/spl/parser/statements/impl/SPLPolicy.java
URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/trunk/modules/imperius-splcore/src/org/apache/imperius/spl/parser/statements/impl/SPLPolicy.java?rev=606479&view=auto
==============================================================================
--- incubator/imperius/trunk/trunk/modules/imperius-splcore/src/org/apache/imperius/spl/parser/statements/impl/SPLPolicy.java (added)
+++ incubator/imperius/trunk/trunk/modules/imperius-splcore/src/org/apache/imperius/spl/parser/statements/impl/SPLPolicy.java Sat Dec 22 11:33:46 2007
@@ -0,0 +1,508 @@
+/*
+ * 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.impl;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.apache.imperius.spl.external.Actuator;
+import org.apache.imperius.spl.external.DataCollector;
+import org.apache.imperius.spl.external.InstanceInfo;
+import org.apache.imperius.spl.parser.compiler.symboltable.SPLSymbolTable;
+import org.apache.imperius.spl.parser.exceptions.SPLException;
+import org.apache.imperius.spl.parser.statements.PolicyStatement;
+import org.apache.imperius.util.SPLLogger;
+//import org.pegasus.jmpi.CIMObjectPath;
+
+//import com.ibm.ac.javaspl.parser.compiler.symboltable.CIMObjectInstance;
+
+
+public class SPLPolicy
+{
+ private List _importStmtList;
+ private StrategyStatement _strgyStmt;
+ private DeclarationStatement _declaration;
+ private ArrayList _policyList;
+ private SPLSymbolTable _symTab;
+ public static final int POLICY_EVALUATED_SUCCESSFULLY = 1;
+ public static final int POLICY_NOT_EVALUATED = 0;
+ public static final int POLICY_EVALUATION_FAILED = -1;
+ private static Logger logger = SPLLogger.getSPLLogger().getLogger();
+ private String auditloggerString = "";
+
+ private static final String sourceClass="SPLPolicy";
+
+
+
+ public SPLPolicy(List importStatementList, StrategyStatement s,DeclarationStatement decl,ArrayList pList, SPLSymbolTable symTab2)
+ {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "SPLPolicy");
+
+
+ this._importStmtList = importStatementList;
+ this._strgyStmt = s;
+ this._declaration = decl;
+ this._policyList = sortPoliciesByPriority(pList);
+
+ this._symTab = symTab2;
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "SPLPolicy");
+
+ }
+
+ private ArrayList sortPoliciesByPriority(ArrayList list)
+ {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "sortPoliciesByPriority");
+
+
+ for(int i=0; i<list.size(); i++)
+ {
+ for(int j=i+1; j<list.size()-1; j++)
+ {
+ PolicyStatement pStatement = (PolicyStatement)list.get(i);
+ PolicyStatement pStatementNext = (PolicyStatement)list.get(j);
+ if(pStatement.getPriority() < pStatementNext.getPriority())
+ {
+ PolicyStatement temp = pStatement;
+ pStatement = pStatementNext;
+ pStatementNext = temp;
+
+
+ }
+
+
+
+ }
+ }
+
+
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "sortPoliciesByPriority");
+ return list;
+ }
+
+
+
+ private int _evaluatePolicies(Map instanceMap,
+ DataCollector dc,
+ Actuator ac)
+ throws SPLException
+ {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "evaluatePolicies");
+
+ // Iterate over the List of maps
+ int result = POLICY_EVALUATED_SUCCESSFULLY;
+ Iterator instanceMapKeyIt = instanceMap.keySet().iterator();
+ System.out.println("Iterating over all instances of Anchor class");
+
+ while(instanceMapKeyIt.hasNext())
+ {
+
+ String className = (String)instanceMapKeyIt.next();
+ List instancesForClass = (List)instanceMap.get(className);
+ Iterator instancesForClassIt = instancesForClass.iterator();
+ if(logger.isLoggable(Level.FINE))
+ logger.fine(Thread.currentThread().getName()+" iterating over instances ");
+// System.out.println(">>>>>>>>>>>"+"Starting policy Evaluation"+"<<<<<<<<<<<");
+// auditloggerString+=">>>>>>>>>>>"+"Starting policy Evaluation"+"<<<<<<<<<<<"+"\n";
+ int instanceCount=1;
+ while(instancesForClassIt.hasNext())
+ {
+ System.out.println("+++++++++++"+"Evaluating policy against instance "+instanceCount+"+++++++++++");
+ auditloggerString+="+++++++++++"+"Evaluating policy against instance "+instanceCount+"+++++++++++"+"\n";
+
+
+ InstanceInfo instanceOfClass = (InstanceInfo)instancesForClassIt.next();
+ String instanceName = instanceOfClass.getInstanceName();
+ Object instance = instanceOfClass.getInstance();
+ Map instanceSymbolMap = instanceOfClass.getInstanceSymbolsMap();
+ // populate the symboltable with information from the map
+ _symTab.populateInstanceValuesForInstance(className, instanceName,instance, instanceSymbolMap);
+ }
+ }
+ //evaluate the declaration to populate the values for the constants
+
+ if(_declaration != null)
+ {
+ _declaration.evaluate();
+ }
+ // iterate over all the policies
+ for(int j=0; j<_policyList.size();j++)
+ {
+
+ System.out.println("***********"+"evaluating sub policy number "+(j+1)+"***********");
+ auditloggerString+="***********"+"evaluating sub policy number "+(j+1)+"***********"+"\n";
+ PolicyStatement pStatement = (PolicyStatement)_policyList.get(j);
+ // evaluate each policy
+ int result1 = pStatement.evaluate(dc,ac);
+ auditloggerString+=pStatement.getAuditLogString();
+
+ if(result1 == POLICY_EVALUATION_FAILED) // report failure even if a single policy fails
+ {
+ result = result1;
+ System.out.println(" "+"SPLPolicy evaluation failed ");
+ auditloggerString+=" "+"SPLPolicy evaluation failed "+"\n";
+
+ logger.severe(Thread.currentThread().getName()+"SPLPolicy evaluation failed return value="+result);
+
+
+ }
+ else
+ {
+ System.out.println(" "+"SPLPolicy evaluation successful ");
+ auditloggerString+=" "+"SPLPolicy evaluation successful "+"\n";
+ }
+ // if strategy is to execute first applicable and if the policy has been evaluated
+ // terminate
+
+ if(_strgyStmt.getStrategy().equals("Execute_First_Applicable"))
+ {
+ if(result1 == POLICY_EVALUATED_SUCCESSFULLY || result1 == POLICY_EVALUATION_FAILED)
+ {
+ System.out.println("***********"+"completed evaluation of sub policy number "+(j+1)+"***********");
+ auditloggerString+="***********"+"completed evaluation of sub policy number "+(j+1)+"***********"+"\n";
+
+ break;
+ }
+ }
+
+ System.out.println("***********"+"completed evaluation of sub policy number "+(j+1)+"***********");
+ auditloggerString+="***********"+"completed evaluation of sub policy number "+(j+1)+"***********"+"\n";
+
+ }
+
+
+ if(logger.isLoggable(Level.FINE))
+ logger.fine(Thread.currentThread().getName()+"SPLPolicy EvaluatePolicies return value="+result);
+
+ if(logger.isLoggable(Level.FINE))
+ logger.fine(Thread.currentThread().getName()+auditloggerString);
+
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "evaluatePolicies");
+
+ return result;
+ }
+
+
+
+ public DeclarationStatement getDeclarationStatement() {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "getDeclarationStatement");
+
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "getDeclarationStatement");
+
+ return _declaration;
+ }
+
+ public void setDeclList(DeclarationStatement decl) {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "setDeclList");
+
+ this._declaration = decl;
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "setDeclList");
+
+ }
+
+ public List getImportStmtList() {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "getImportStmt");
+
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "getImportStmt");
+
+ return _importStmtList;
+ }
+
+ public void setImportStmtList(List importStmtList) {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "setImportStmt");
+
+ this._importStmtList = importStmtList;
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "setImportStmt");
+
+ }
+
+ public ArrayList getPolicyList() {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "getPolicyList");
+
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "getPolicyList");
+
+ return _policyList;
+ }
+
+ public void setPolicyList(ArrayList policyList) {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "setPolicyList");
+
+ this._policyList = policyList;
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "setPolicyList");
+
+ }
+
+ public StrategyStatement getStrgyStmt() {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "getStrgyStmt");
+
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "getStrgyStmt");
+
+ return _strgyStmt;
+ }
+
+ public void setStrgyStmt(StrategyStatement strgyStmt) {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "setStrgyStmt");
+
+ this._strgyStmt = strgyStmt;
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "setStrgyStmt");
+
+ }
+
+ public DeclarationStatement getDeclaration() {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "getDeclaration");
+
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "getDeclaration");
+
+ return _declaration;
+ }
+
+ public void setDeclaration(DeclarationStatement declaration) {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "setDeclaration");
+ this._declaration = declaration;
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "setDeclaration");
+
+
+ }
+
+ public SPLSymbolTable getSymTab() {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "getSymTab");
+
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "getSymTab");
+
+ return _symTab;
+ }
+
+ public void setSymTab(SPLSymbolTable symTab) {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "setSymTab");
+ this._symTab = symTab;
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "setSymTab");
+
+
+ }
+
+ public int evaluate(DataCollector dc, Actuator ac,
+ String anchorClassName,String anchornamespace,
+ Object anchorInstance, String assocName, String role1,
+ String role2) throws SPLException
+ {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "evaluate");
+ this.auditloggerString="";
+
+ int result = POLICY_EVALUATED_SUCCESSFULLY;
+ System.out.println("cimObjectName "+anchorClassName+" "+anchornamespace+" "+anchorInstance.toString());
+ //Map keys=this.symTab.getInstance().getMapOfKeys();
+ ImportStatement imp=(ImportStatement)this._importStmtList.get(0);
+ InstanceInfo ii=(InstanceInfo)imp.getImportInstanceInfoList().get(0);
+ String targetclassnm = ii.getInstanceName();
+ List targetClassInstances = dc.getAssociatedInstanceReferences(anchorInstance, anchornamespace, targetclassnm, assocName, role1, role2);
+
+ Iterator it=targetClassInstances.iterator();
+ System.out.println(">>>>>>>>>>>"+"Policy Group Evaluation - number of associated instances :"+targetClassInstances.size()+"<<<<<<<<<<<");
+
+ auditloggerString+=">>>>>>>>>>>"+"Policy Group Evaluation - number of associated instances :"+targetClassInstances.size()+"<<<<<<<<<<<"+"\n";
+
+ while(it.hasNext()){
+ Object inst=it.next();
+ InstanceInfo iinfo=new InstanceInfo(targetclassnm,inst);
+ List instanceInfoList=new ArrayList();
+ instanceInfoList.add(iinfo);
+
+ Map objMap=new HashMap();
+ objMap.put(targetclassnm, instanceInfoList);
+ result = evaluate(dc,ac,objMap);
+
+ }
+// System.out.println(">>>>>>>>>>>"+"policy evaluation complete, result :"+result+"<<<<<<<<<<<");
+// auditloggerString+=">>>>>>>>>>>"+"policy evaluation complete, result :"+result+"<<<<<<<<<<<"+"\n";
+
+
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "evaluate");
+
+ return result;
+ }
+
+
+ public int evaluate(DataCollector dc, Actuator ac, Map instanceMap) throws SPLException
+ {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "evaluate2");
+ this.auditloggerString="";
+ if (logger.isLoggable(Level.FINE))
+ logger.fine(Thread.currentThread().getName()+"evaluating policy against instances cimPolicy");
+
+
+ // List inputInstanceSymbols = new ArrayList();
+ Iterator instanceDataIterator = instanceMap.keySet().iterator();
+
+ while(instanceDataIterator.hasNext())
+ {
+ String instanceClassName = (String)instanceDataIterator.next();
+ List instanceInfoList = (List)instanceMap.get(instanceClassName);
+
+ if(_instancesPassImportFilter(dc,instanceInfoList)) // TBD
+ {
+
+ Iterator instanceInfoIt = instanceInfoList.iterator();
+ while(instanceInfoIt.hasNext())
+ {
+ InstanceInfo instanceInfo = (InstanceInfo)instanceInfoIt.next();
+ Object instance = instanceInfo.getInstance();
+ String qualifier = _symTab.getQualifierForClass(instanceClassName);
+ Map symbolsForInstance = dc.getSymbolsForInstance(instanceClassName,
+ qualifier,
+ instance);
+ instanceInfo.setInstanceSymbolsMap(symbolsForInstance);
+ }
+
+ }
+ else
+ {
+ //instances don't pass import filters
+ break;
+ }
+
+ }
+ int result = POLICY_EVALUATION_FAILED;
+ if(!instanceMap.isEmpty())
+ {
+ if (logger.isLoggable(Level.FINE))
+ {
+ logger.fine(Thread.currentThread().getName()+
+ "number of instances passed in for evaluation is "+instanceMap.size());
+ }
+ System.out.println(">>>>>>>>>>>"+"number of instances passed in for evaluation is :"+instanceMap.size()+"<<<<<<<<<<<");
+
+ auditloggerString+=">>>>>>>>>>>"+"number of instances passed in for evaluation is :"+instanceMap.size()+"<<<<<<<<<<<"+"\n";
+
+
+ result = _evaluatePolicies(instanceMap,dc,ac);
+
+ System.out.println(">>>>>>>>>>>"+"policy evaluation complete, result :"+result+"<<<<<<<<<<<");
+ auditloggerString+=">>>>>>>>>>>"+"policy evaluation complete, result :"+result+"<<<<<<<<<<<"+"\n";
+
+
+ }
+ else
+ {
+
+ logger.warning(Thread.currentThread().getName()+" "+"No valid instances for policy evaluation");
+ //throw new SPLException("Out of the Instances that were passed in for Evaluation, none have passed the filter");
+ }
+ if (logger.isLoggable(Level.FINE))
+ logger.fine(Thread.currentThread().getName()+"result of evaluation is "+result);
+
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "evaluate2");
+
+ return result;
+ }
+
+ public String getAuditLogString() {
+
+ return this.auditloggerString;
+ }
+
+ private boolean _instancesPassImportFilter(DataCollector dc,Object instance)
+ {
+ return true;
+ /*logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "instanceFilterByCOP");
+ String classnm=this.importStmt.getClassName();
+ String namespc=this.importStmt.getNameSpace();
+
+ String copShouldStartWith=this.getSymTab().getAnchor();
+ //System.out.println("cop Should contain : "+copShouldStartWith);
+ //System.out.println("cop is : "+cop);
+ if(cop.toString().indexOf(copShouldStartWith) != -1)
+ {
+ try
+ {
+ Map instMap=dc.getInstanceMap(classnm, namespc, cop.toString());
+ symTab.populateSymbolTableWithInstanceValues(instMap);
+ Expression importFilterExpression = importStmt.getExpr();
+ if(importFilterExpression != null)
+ {
+ if (logger.isLoggable(Level.FINE))
+ logger.fine(Thread.currentThread().getName()+"importFilterExpression != null");
+ // filter the List of Maps based on the import statement filter expression
+ Boolean filterResult = (Boolean)importFilterExpression.evaluate();
+ if(filterResult.booleanValue())
+ {
+ if (logger.isLoggable(Level.FINE))
+ logger.fine(Thread.currentThread().getName()+"filterResult.booleanValue() = true");
+ return true;
+ }
+ else
+ {
+ if (logger.isLoggable(Level.FINE))
+ logger.fine(Thread.currentThread().getName()+"filterResult.booleanValue() = false");
+ return false;
+ }
+ }
+ else
+ {
+ // no filtering required
+ return true;
+ }
+
+ }
+ catch(SPLException e)
+ {
+ logger.severe(e.getMessage());
+ }
+
+
+
+ //System.out.println("passed the filter");
+
+ }
+ //System.out.println("did not passed the filter");
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "instanceFilterByCOP");
+
+ return false;*/
+ }
+
+ /* private List filterInstancesByImportFilter(List instSymbolMaps, Expression importFilterExpression) throws SPLException
+ {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "filterInstancesByImportFilter");
+
+ List filteredList = new ArrayList();
+ Iterator listIt = instSymbolMaps.iterator();
+ while(listIt.hasNext())
+ {
+ Map instSymbols = (Map)listIt.next();
+ symTab.populateSymbolTableWithInstanceValues(instSymbols);
+ Boolean filterResult = (Boolean)importFilterExpression.evaluate();
+ if(filterResult.booleanValue())
+ {
+ filteredList.add(instSymbols);
+ }
+ }
+
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "filterInstancesByImportFilter");
+
+ return filteredList;
+ }*/
+
+
+
+
+}
Added: incubator/imperius/trunk/trunk/modules/imperius-splcore/src/org/apache/imperius/spl/parser/statements/impl/StrategyStatement.java
URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/trunk/modules/imperius-splcore/src/org/apache/imperius/spl/parser/statements/impl/StrategyStatement.java?rev=606479&view=auto
==============================================================================
--- incubator/imperius/trunk/trunk/modules/imperius-splcore/src/org/apache/imperius/spl/parser/statements/impl/StrategyStatement.java (added)
+++ incubator/imperius/trunk/trunk/modules/imperius-splcore/src/org/apache/imperius/spl/parser/statements/impl/StrategyStatement.java Sat Dec 22 11:33:46 2007
@@ -0,0 +1,58 @@
+/*
+ * 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.impl;
+
+import java.util.logging.Logger;
+
+import org.apache.imperius.util.SPLLogger;
+
+
+public class StrategyStatement
+{
+ private String strategy;
+ private static Logger logger = SPLLogger.getSPLLogger().getLogger();
+ private static final String sourceClass="StrategyStatement";
+
+
+ public String getStrategy() {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "getStrategy");
+
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "getStrategy");
+
+ return strategy;
+ }
+
+ public void setStrategy(String strategy) {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "setStrategy");
+
+ this.strategy = strategy;
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "setStrategy");
+
+ }
+
+ public StrategyStatement(String st)
+ {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "StrategyStatement");
+
+ strategy = st;
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "StrategyStatement");
+
+ }
+}
Added: incubator/imperius/trunk/trunk/modules/imperius-splcore/src/org/apache/imperius/spl/parser/util/ActuatorFactory.java
URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/trunk/modules/imperius-splcore/src/org/apache/imperius/spl/parser/util/ActuatorFactory.java?rev=606479&view=auto
==============================================================================
--- incubator/imperius/trunk/trunk/modules/imperius-splcore/src/org/apache/imperius/spl/parser/util/ActuatorFactory.java (added)
+++ incubator/imperius/trunk/trunk/modules/imperius-splcore/src/org/apache/imperius/spl/parser/util/ActuatorFactory.java Sat Dec 22 11:33:46 2007
@@ -0,0 +1,41 @@
+/*
+ * 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.util;
+
+import org.apache.imperius.spl.external.Actuator;
+
+public class ActuatorFactory
+{
+ private static Actuator _actuator;
+
+ public static void registerActuator(Actuator ac)
+ {
+ _actuator = ac;
+ }
+
+ public static Actuator getActuator()
+ {
+ return _actuator;
+ }
+
+
+
+}
Added: incubator/imperius/trunk/trunk/modules/imperius-splcore/src/org/apache/imperius/spl/parser/util/DataCollectorFactory.java
URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/trunk/modules/imperius-splcore/src/org/apache/imperius/spl/parser/util/DataCollectorFactory.java?rev=606479&view=auto
==============================================================================
--- incubator/imperius/trunk/trunk/modules/imperius-splcore/src/org/apache/imperius/spl/parser/util/DataCollectorFactory.java (added)
+++ incubator/imperius/trunk/trunk/modules/imperius-splcore/src/org/apache/imperius/spl/parser/util/DataCollectorFactory.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 <pr...@in.ibm.com>
+ *
+ */
+
+package org.apache.imperius.spl.parser.util;
+
+import org.apache.imperius.spl.external.DataCollector;
+
+public class DataCollectorFactory
+{
+ private static DataCollector _dataCollector;
+
+ public static void registerDataCollector(DataCollector dc)
+ {
+ _dataCollector = dc;
+ }
+
+ public static DataCollector getDataCollector()
+ {
+ return _dataCollector;
+ }
+
+}
Added: incubator/imperius/trunk/trunk/modules/imperius-splcore/src/org/apache/imperius/spl/parser/util/ExpressionUtility.java
URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/trunk/modules/imperius-splcore/src/org/apache/imperius/spl/parser/util/ExpressionUtility.java?rev=606479&view=auto
==============================================================================
--- incubator/imperius/trunk/trunk/modules/imperius-splcore/src/org/apache/imperius/spl/parser/util/ExpressionUtility.java (added)
+++ incubator/imperius/trunk/trunk/modules/imperius-splcore/src/org/apache/imperius/spl/parser/util/ExpressionUtility.java Sat Dec 22 11:33:46 2007
@@ -0,0 +1,919 @@
+/*
+ * 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.util;
+
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.GregorianCalendar;
+import java.util.List;
+import java.util.Properties;
+import java.util.StringTokenizer;
+import java.util.TimeZone;
+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.impl.DateTime;
+import org.apache.imperius.util.PropertiesLoader;
+import org.apache.imperius.util.SPLLogger;
+import org.w3c.dom.Element;
+
+
+public class ExpressionUtility
+{
+
+ private static String GMT = "GMT";
+
+ private static int UTC_MULTIPLIER = 60000;
+
+ private static Logger logger = SPLLogger.getSPLLogger().getLogger();
+ private static final String sourceClass="ExpressionUtility";
+
+
+ /**
+ * Returns 0 if the given <code>Object</code>s have equal values from the
+ * view-point of ACPL data types, and a nonzero integer otherwise. If the
+ * two given <code>Object</code>s cannot be compared to each other, then
+ * a <code>ClassCastException</code> is thrown.
+ * <p>
+ *
+ * Furthermore, if the values of given <code>Object</code>s can be
+ * ordered, then a positive integer (or a negative integer, respectively) is
+ * returned if the value of first <code>Object</code> is greater than (or
+ * less than, respectively) than the value of the second <code>Object</code>.
+ * This code is intended to follow IEEE 754 guidelines if the given objects
+ * are non-arbitrary precision instances of <code>Number</code>.
+ *
+ * @param o1
+ * the first <code>Object</code> to be compared
+ * @param o2
+ * the second <code>Object</code> to be compared
+ * @return an integer indicating the equality and possibly relative order of
+ * specified arguments
+ * @throws ClassCastException
+ * if the specified <code>Object</code>s cannot be compared
+ * to each other.
+ */
+ public static int compare(Object o1, Object o2) throws SPLException
+ {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "compare");
+
+ // first take care of the case where either o1 or o2 is null.
+ if (o1 == null || o2 == null)
+ {
+
+ }
+ /*
+ * In PMAC, we have the following data types: String, Boolean, Calendar,
+ * Numeric, CompositeData. Two objects of different datatypes cannot be
+ * compared to each other.
+ *
+ * We cannot use a straightforward <code>Comparable</code> interface
+ * since Numeric represents five Java classes, Short, Integer, Long,
+ * Float, and Double and CompositeData and Boolean does not implement
+ * <code>Comparable</code>.
+ */
+ // take care of a simple datatypes that implement
+ // <code>Comparable</code>
+ if (o1 instanceof String)
+ {
+ return ((Comparable) o1).compareTo(o2);
+ }
+
+ // Calendar has to use After/Before
+ if (o1 instanceof Calendar)
+ {
+ Calendar o1cal = (Calendar) o1;
+ Calendar o2cal = (Calendar) o2;
+ if (o1cal.after(o2cal))
+ {
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "compare");
+
+ return 1;
+ }
+ else if (o2cal.after(o1cal))
+ {
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "compare");
+
+ return -1;
+ }
+ else
+ {
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "compare");
+
+ return 0;
+ }
+
+ }
+
+ // take care of two datatypes that are not ordered
+ if (o1 instanceof Boolean)
+ {
+ if (o1.equals(o2))
+ {
+
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "compare");
+
+ return 0;
+
+ }
+
+ else
+ {
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "compare");
+
+ return -1;
+ }
+ }
+
+ // take care of Numeric dataypes
+ /*
+ * Cannot convert short, int, and long to double since there is a
+ * precision loss in those conversions, that is when comparing two longs
+ * after converting them to double, they may come out to be equal even
+ * if they are not.
+ */
+ boolean isFirstObjectInteger = false;
+ boolean isSecondObjectInteger = false;
+ // check for byte class also just in case, it is included in Numeric
+ // datatypes in future
+ if (o1 instanceof Byte || o1 instanceof Short || o1 instanceof Integer
+ || o1 instanceof Long)
+ {
+ isFirstObjectInteger = true;
+ }
+ if (o2 instanceof Byte || o2 instanceof Short || o2 instanceof Integer
+ || o2 instanceof Long)
+ {
+ isSecondObjectInteger = true;
+ }
+
+ if (isFirstObjectInteger)
+ {
+ if (isSecondObjectInteger)
+ {
+ // since both objects have integer values, we can perform
+ // integer arithmetic.
+ long firstValue = ((Number) o1).longValue();
+ long secondValue = ((Number) o2).longValue();
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "compare");
+
+ return (new Long(firstValue)).compareTo(new Long(secondValue));
+ }
+ else
+ {
+ /*
+ * first is integer and second is floating point, the best bet
+ * is to use comparison operators.
+ */
+ long firstValue = ((Number) o1).longValue();
+ double secondValue = ((Number) o2).doubleValue();
+ if (firstValue > secondValue)
+ {
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "compare");
+
+ return 1;
+ }
+ else if (firstValue < secondValue)
+ {
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "compare");
+
+ return -1;
+ }
+ else
+ {
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "compare");
+
+ return 0;
+ }
+
+ }
+ }
+ else
+ {
+ if (isSecondObjectInteger)
+ {
+ /*
+ * first is floating point and second is integer, the best bet
+ * is to use comparison operators.
+ */
+ double firstValue = ((Number) o1).doubleValue();
+ long secondValue = ((Number) o2).longValue();
+ if (firstValue > secondValue)
+ {
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "compare");
+
+ return 1;
+ }
+ else if (firstValue < secondValue)
+ {
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "compare");
+
+
+ return -1;
+ }
+ else
+ {
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "compare");
+
+ return 0;
+ }
+
+ }
+ else
+ {
+ // both are floating point and we can use Double class to
+ // compare
+ double firstValue = ((Number) o1).doubleValue();
+ double secondValue = ((Number) o2).doubleValue();
+
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "compare");
+
+ return (new Double(firstValue)
+ .compareTo(new Double(secondValue)));
+ }
+ }
+ }
+
+ public 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());
+ 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 static Number division(Number o1, Number o2) throws SPLException
+ {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "division");
+
+ 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()+" "+ "division");
+
+ return new Double(o1.doubleValue() / o2.doubleValue());
+ }
+ else if (resolvedType == TypeConstants.floatType)
+ {
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "division");
+
+ return new Double(o1.doubleValue() / o2.doubleValue());
+ }
+ else if (resolvedType == TypeConstants.longType)
+ {
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "division");
+
+ return new Double(o1.doubleValue() / o2.doubleValue());
+ }
+ else if (resolvedType == TypeConstants.intType)
+ {
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "division");
+
+ return new Double(o1.doubleValue() / o2.doubleValue());
+ }
+ else if (resolvedType == TypeConstants.shortType)
+ {
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "division");
+
+ return new Double(o1.doubleValue() / o2.doubleValue());
+ }
+ else if (resolvedType == TypeConstants.byteType)
+ {
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "division");
+
+ return new Double(o1.doubleValue() / o2.doubleValue());
+ }
+ else
+ {
+ logger.severe(Thread.currentThread().getName()+" "+"wrong operand type.");
+
+ throw new SPLException("wrong operand type.");
+ }
+ }
+
+ public static Number multiplication(Number o1, Number o2)
+ throws SPLException
+ {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "multiplication");
+
+ 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()+" "+ "multiplication");
+
+ return new Double(o1.doubleValue() * o2.doubleValue());
+ }
+ else if (resolvedType == TypeConstants.floatType)
+ {
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "multiplication");
+
+ return new Float(o1.floatValue() * o2.floatValue());
+ }
+ else if (resolvedType == TypeConstants.longType)
+ {
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "multiplication");
+
+ return new Long(o1.longValue() * o2.longValue());
+ }
+ else if (resolvedType == TypeConstants.intType)
+ {
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "multiplication");
+
+ return new Integer(o1.intValue() * o2.intValue());
+ }
+ else if (resolvedType == TypeConstants.shortType)
+ {
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "multiplication");
+
+ return new Short((short) (o1.shortValue() * o2.shortValue()));
+ }
+ else if (resolvedType == TypeConstants.byteType)
+ {
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "multiplication");
+
+ return new Byte((byte) (o1.byteValue() * o2.byteValue()));
+ }
+ else
+ {
+ logger.severe(Thread.currentThread().getName()+" "+"wrong operand type.");
+
+ throw new SPLException("wrong operand type.");
+ }
+
+ }
+
+ public static Number minus(Number o1, Number o2) throws SPLException
+ {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "minus");
+
+ Number[] o = new Number[2];
+ o[0] = o1;
+ o[1] = o2;
+
+ int resolvedType = TypeResolver.resolveType(o);
+
+ if (resolvedType == TypeConstants.doubleType)
+ {
+ double result = o1.doubleValue() - o2.doubleValue();
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "minus");
+
+
+ return new Double(result);
+ }
+ else if (resolvedType == TypeConstants.floatType)
+ {
+ float result = o1.floatValue() - o2.floatValue();
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "minus");
+
+
+ return new Float(result);
+ }
+ else if (resolvedType == TypeConstants.longType)
+ {
+ long result = o1.longValue() - o2.longValue();
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "minus");
+
+
+ return new Long(result);
+ }
+ else if (resolvedType == TypeConstants.shortType)
+ {
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "minus");
+
+
+ return new Long(o1.shortValue() - o2.shortValue());
+ }
+ else if (resolvedType == TypeConstants.byteType)
+ {
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "minus");
+
+
+ return new Long(o1.byteValue() - o2.byteValue());
+ }
+ else
+ {
+ int result = o1.intValue() - o2.intValue();
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "minus");
+
+
+ return new Integer(result);
+ }
+ }
+
+ /*
+ * public static int getTypeOfOperationForCollections(String operation)
+ * throws CIMSPLException { int LOR = 52; int LAND = 53; int BXOR = 54; int
+ * NOT_EQUAL = 55; int EQUAL = 56; int LT = 102; int GT = 58; int LE = 59;
+ * int GE = 60; int PLUS = 61; int MINUS = 62; int STAR = 63; int DIV = 64;
+ *
+ *
+ * String stringLOR = "LOR"; String stringLAND = "LAND"; String stringBXOR =
+ * "BXOR";
+ *
+ * String stringNOT_EQUAL = "NOT_EQUAL"; String stringEQUAL = "EQUAL";
+ * String stringLT = "LT"; String stringGT = "GT"; String stringLE = "LE";
+ * String stringGE = "GE"; String stringPLUS = "PLUS"; String stringMINUS =
+ * "MINUS"; String stringSTAR = "STAR"; String stringDIV = "DIV";
+ *
+ *
+ * if(operation.equalsIgnoreCase(stringLOR)) return LOR; else
+ * if(operation.equalsIgnoreCase(stringLAND)) return LAND; else
+ * if(operation.equalsIgnoreCase(stringBXOR)) return BXOR; else
+ * if(operation.equalsIgnoreCase(stringNOT_EQUAL)) return NOT_EQUAL; else
+ * if(operation.equalsIgnoreCase(stringEQUAL)) return EQUAL; else
+ * if(operation.equalsIgnoreCase(stringLT)) return LT; else
+ * if(operation.equalsIgnoreCase(stringGT)) return GT; else
+ * if(operation.equalsIgnoreCase(stringLE)) return LE; else
+ * if(operation.equalsIgnoreCase(stringGE)) return GE; else
+ * if(operation.equalsIgnoreCase(stringPLUS)) return PLUS; else
+ * if(operation.equalsIgnoreCase(stringMINUS)) return MINUS; else
+ * if(operation.equalsIgnoreCase(stringSTAR)) return STAR; else
+ * if(operation.equalsIgnoreCase(stringDIV)) return DIV;
+ *
+ * else { throw new CIMSPLException("Operation for Collection could not be
+ * resolved "+operation); }
+ *
+ * }
+ */
+
+
+
+
+
+
+
+ private static List _getClassList(String type)
+ {
+ List customClassList = new ArrayList();
+ PropertiesLoader propLoader = new PropertiesLoader();
+ Properties props = propLoader.getProperties();
+ String exprList = props.getProperty(type);
+ StringTokenizer st = new StringTokenizer(exprList,",");
+ while(st.hasMoreTokens())
+ {
+ String customClass = st.nextToken();
+ customClassList.add(customClass);
+ }
+
+
+ return customClassList;
+
+ }
+
+ public static List getListOfCustomExpressionTypes()
+ {
+ List customExprList = null;
+ customExprList = _getClassList("SPL_CUSTOM_EXPRESSIONS");
+ return customExprList;
+ }
+
+ public static List getListOfCustomActionTypes()
+ {
+ List customActionList = new ArrayList();
+
+ customActionList = _getClassList("SPL_CUSTOM_ACTIONS");
+ return customActionList;
+
+ }
+
+ /**
+ * Returns 0 if the given <code>Object</code>s have equal values from the
+ * view-point of ACPL data types, and a nonzero integer otherwise. If the
+ * two given <code>Object</code>s cannot be compared to each other, then
+ * a <code>ClassCastException</code> is thrown.
+ * <p>
+ *
+ * Furthermore, if the values of given <code>Object</code>s can be
+ * ordered, then a positive integer (or a negative integer, respectively) is
+ * returned if the value of first <code>Object</code> is greater than (or
+ * less than, respectively) than the value of the second <code>Object</code>.
+ * This code is intended to follow IEEE 754 guidelines if the given objects
+ * are non-arbitrary precision instances of <code>Number</code>.
+ *
+ * @param o1
+ * the first <code>Object</code> to be compared
+ * @param o2
+ * the second <code>Object</code> to be compared
+ * @return an integer indicating the equality and possibly relative order of
+ * specified arguments
+ * @throws ClassCastException
+ * if the specified <code>Object</code>s cannot be compared
+ * to each other.
+ */
+ /*public static int compare(Object o1, Object o2) throws SPLException
+ {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "compare");
+
+
+
+ // first take care of the case where either o1 or o2 is null.
+ if (o1 == null || o2 == null)
+ {
+ logger.severe(Thread.currentThread().getName()+" "+"null operand.");
+ throw new SPLException("null operand.");
+ }
+
+ // take care of a simple datatypes that implement
+ // <code>Comparable</code>
+ if (o1 instanceof String)
+ {
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "compare");
+ return ((Comparable) o1).compareTo(o2);
+ }
+
+ // Calendar has to use After/Before
+ if (o1 instanceof Calendar)
+ {
+ Calendar o1cal = (Calendar) o1;
+ Calendar o2cal = (Calendar) o2;
+ if (o1cal.after(o2cal))
+ {
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "compare");
+ return 1;
+ }
+ else if (o2cal.after(o1cal))
+ {
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "compare");
+ return -1;
+ }
+ else
+ {
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "compare");
+ return 0;
+ }
+
+ }
+
+ // take care of two datatypes that are not ordered
+ if (o1 instanceof Boolean || o1 instanceof Element)
+ {
+ if (o1.equals(o2))
+ {
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "compare");
+ return 0;
+ }
+
+ else
+ {
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "compare");
+ return -1;
+ }
+ }
+
+ // take care of Numeric dataypes
+ boolean isFirstObjectInteger = false;
+ boolean isSecondObjectInteger = false;
+ // check for byte class also just in case, it is included in Numeric
+ // datatypes in future
+ if (o1 instanceof Byte || o1 instanceof Short || o1 instanceof Integer
+ || o1 instanceof Long)
+ {
+ isFirstObjectInteger = true;
+ }
+ if (o2 instanceof Byte || o2 instanceof Short || o2 instanceof Integer
+ || o2 instanceof Long)
+ {
+ isSecondObjectInteger = true;
+ }
+
+ if (isFirstObjectInteger)
+ {
+ if (isSecondObjectInteger)
+ {
+ // since both objects have integer values, we can perform
+ // integer arithmetic.
+ long firstValue = ((Number) o1).longValue();
+ long secondValue = ((Number) o2).longValue();
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "compare");
+ return (new Long(firstValue)).compareTo(new Long(secondValue));
+ }
+ else
+ {
+ /*
+ * first is integer and second is floating point, the best bet
+ * is to use comparison operators.
+
+ long firstValue = ((Number) o1).longValue();
+ double secondValue = ((Number) o2).doubleValue();
+ if (firstValue > secondValue)
+ {
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "compare");
+
+ return 1;
+ }
+
+ else if (firstValue < secondValue)
+ {
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "compare");
+ return -1;
+ }
+
+ else
+ {
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "compare");
+ return 0;
+ }
+
+ }
+ }
+ else
+ {
+ if (isSecondObjectInteger)
+ {
+ /*
+ * first is floating point and second is integer, the best bet
+ * is to use comparison operators.
+
+ double firstValue = ((Number) o1).doubleValue();
+ long secondValue = ((Number) o2).longValue();
+ if (firstValue > secondValue)
+ {
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "compare");
+ return 1;
+
+ }
+
+ else if (firstValue < secondValue)
+ {
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "compare");
+
+ return -1;
+ }
+ else
+ {
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "compare");
+
+ return 0;
+ }
+
+ }
+ else
+ {
+ // both are floating point and we can use Double class to
+ // compare
+ double firstValue = ((Number) o1).doubleValue();
+ double secondValue = ((Number) o2).doubleValue();
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "compare");
+
+ return (new Double(firstValue)
+ .compareTo(new Double(secondValue)));
+ }
+ }
+ }*/
+
+ /**
+ *
+ * This function converts a <code>DateTime</code> to a
+ * <code>Calendar</code> expression using the time zone specified by
+ * <code>timeZoneID</code>, which can be any of the defined Java TimeZone
+ * ID's, "utc", or "local". If <code>timeZoneID</code> is
+ * <code>null</code>, then "utc" is assumed. If isLenient is true, then
+ * the xsd:dateTime will be converted using the Calendar isLenient feature.
+ * Otherewise, an exception will be thrown if the time is not a valid time.
+ * If preferStandardTime is true, standard time will be chosen when there is
+ * an ambiguity (as in the "fall back" hour).
+ * <p>
+ *
+ * If any of year, month, or day are 0 in the DateTime, then the current
+ * year, month, or day are substituted.
+ * <p>
+ *
+ * The timeZone information contained in the DateTime is ignored.
+ *
+ * @param isLenientValue
+ * @param preferStandardTimeValue
+ * @param spldate
+ * iso8601 formatted date
+ * @param timeZoneID
+ * @return
+ */
+ public static Calendar computeCalendarValue(boolean isLenientValue,
+ boolean preferStandardTimeValue, DateTime spldate)
+ {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "computeCalendarValue");
+
+ String timeZoneID = spldate.getTimeZoneString();
+
+ TimeZone tz = null;
+
+ if (timeZoneID == null || timeZoneID.equalsIgnoreCase("utc"))
+ {
+ tz = TimeZone.getTimeZone("UTC");
+ }
+ else if (timeZoneID.equalsIgnoreCase("local"))
+ {
+ tz = TimeZone.getDefault();
+ }
+ else
+ {
+ tz = TimeZone.getTimeZone(timeZoneID);
+ }
+
+ Calendar now = new GregorianCalendar(tz);
+ now.getTime();
+
+ Calendar calendar = new GregorianCalendar(tz);
+
+ calendar.setLenient(isLenientValue);
+
+ if (spldate.isEraAD())
+ {
+ calendar.set(Calendar.ERA, GregorianCalendar.AD);
+ }
+ else
+ {
+ calendar.set(Calendar.ERA, GregorianCalendar.BC);
+ }
+ if (spldate.getYear() == -1)
+ {
+ calendar.set(Calendar.YEAR, now.get(Calendar.YEAR));
+ }
+ else
+ {
+ calendar.set(Calendar.YEAR, spldate.getYear());
+ }
+ if (spldate.getMonth() == -1)
+ {
+ calendar.set(Calendar.MONTH, now.get(Calendar.MONTH));
+ }
+ else
+ {
+ calendar.set(Calendar.MONTH, spldate.getMonth());
+ }
+ if (spldate.getDay() == -1)
+ {
+ calendar.set(Calendar.DATE, now.get(Calendar.DATE));
+ }
+ else
+ {
+ calendar.set(Calendar.DATE, spldate.getDay());
+ }
+ if (spldate.getHour() == -1)
+ {
+ calendar.set(Calendar.HOUR_OF_DAY, now.get(Calendar.HOUR_OF_DAY));
+ }
+ else
+ {
+ calendar.set(Calendar.HOUR_OF_DAY, spldate.getHour());
+ }
+ if (spldate.getMinute() == -1)
+ {
+ calendar.set(Calendar.MINUTE, now.get(Calendar.MINUTE));
+ //System.out.println("spldate.getMinute()"+spldate.getMinute());
+ }
+ else
+ {
+ calendar.set(Calendar.MINUTE, spldate.getMinute());
+ //System.out.println("spldate.getMinute()"+spldate.getMinute());
+ }
+ if (spldate.getSecond() == -1)
+ {
+ calendar.set(Calendar.SECOND, now.get(Calendar.SECOND));
+ }
+ else
+ {
+ calendar.set(Calendar.SECOND, spldate.getSecond());
+ }
+ if (spldate.getMillis() == -1)
+ {
+ calendar.set(Calendar.MILLISECOND, now.get(Calendar.MILLISECOND));
+ }
+ else
+ {
+ calendar.set(Calendar.MILLISECOND, spldate.getMillis());
+ }
+ //System.out.println(" calendar "+calendar.getTime().toString());
+
+ /*
+ * If we are on the cusp of daylight /standard savings time, there can
+ * be ambiguity in the xsd:dateTime ("fall back period" We use the
+ * preferStandardTime to determine if we should use the first instance
+ * of a wall clock time or the second instance of a wall clock time
+ * during this period (for example, in some areas at 2:00am wallclock
+ * during daylight savings time, the time becomes 1:00am wallclock in
+ * standard time -- 1:30am wallclock appears twice in that day).
+ *
+ * By default, Java takes the any time that has ambiguities as standard
+ * time, so we only need to check for the case when we don't prefer
+ * standard time.
+ */
+ if (!preferStandardTimeValue && tz.useDaylightTime())
+ {
+ // only relevant if we prefer daylight savings on
+ // ambiguities and if the time zone supports daylight savings
+
+ int dstoffsetMillis = calendar
+ .getActualMaximum(Calendar.DST_OFFSET);
+
+ java.util.Date calendarDate = calendar.getTime();
+ // case we are concerned about is "Fall back" where we are in
+ // daylight savings time, but then fall back for standard savings --
+ // this
+ // causes the same wall clock time to appear twice
+
+ /*
+ * To determine this, if we are in STD time, we need to substract
+ * DST_OFFSET from the current calendar and see if the time is in
+ * DST time -- if so we use that version
+ */
+ if (!tz.inDaylightTime(calendarDate))
+ {
+ // see if substracting the offset puts us in Daylight savings
+
+ Date dateMinusDSTOffset = new Date(calendarDate.getTime()
+ - dstoffsetMillis);
+
+ if (tz.inDaylightTime(dateMinusDSTOffset))
+ {
+ // subtracting the offset put us in daylight savings,
+ // and we prefer the daylight savings instant of the date
+ // so we will use this date
+ calendar.setTime(dateMinusDSTOffset);
+ }
+ }
+
+ }
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "computeCalendarValue");
+ //System.out.println(" calendar "+calendar.getTimeInMillis());
+ return calendar;
+ }
+
+ public static void main(String [] args)
+ {
+ List stList = getListOfCustomExpressionTypes();
+
+ }
+
+}