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 2008/02/20 20:40:15 UTC
svn commit: r629608 [2/3] - in /incubator/imperius/trunk: ./ cimspl-samples/
cimspl-samples/resources/ cimspl-samples/resources/samples/
cimspl-samples/resources/samples/mofs/
cimspl-samples/resources/samples/policies/ cimspl-samples/src/
cimspl-sample...
Added: incubator/imperius/trunk/imperius-cimsplprovider/src/main/java/org/apache/imperius/cimspl/CIMActuatorImpl.java
URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/imperius-cimsplprovider/src/main/java/org/apache/imperius/cimspl/CIMActuatorImpl.java?rev=629608&view=auto
==============================================================================
--- incubator/imperius/trunk/imperius-cimsplprovider/src/main/java/org/apache/imperius/cimspl/CIMActuatorImpl.java (added)
+++ incubator/imperius/trunk/imperius-cimsplprovider/src/main/java/org/apache/imperius/cimspl/CIMActuatorImpl.java Wed Feb 20 12:40:03 2008
@@ -0,0 +1,623 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.cimspl;
+
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Vector;
+import java.util.Set;
+import java.util.Iterator;
+import java.math.BigInteger;
+import org.pegasus.jmpi.CIMClass;
+import org.pegasus.jmpi.CIMDataType;
+import org.pegasus.jmpi.CIMDateTime;
+import org.pegasus.jmpi.CIMException;
+import org.pegasus.jmpi.CIMInstance;
+import org.pegasus.jmpi.CIMMethod;
+import org.pegasus.jmpi.CIMOMHandle;
+import org.pegasus.jmpi.CIMObjectPath;
+import org.pegasus.jmpi.CIMParameter;
+import org.pegasus.jmpi.CIMProperty;
+import org.pegasus.jmpi.CIMValue;
+import org.pegasus.jmpi.UnsignedInt16;
+import org.pegasus.jmpi.UnsignedInt32;
+import org.pegasus.jmpi.UnsignedInt64;
+import org.pegasus.jmpi.UnsignedInt8;
+//import org.sblim.wbem.cim.CIMArgument;
+
+
+import org.apache.imperius.spl.external.Actuator;
+import org.apache.imperius.spl.external.Argument;
+import org.apache.imperius.spl.parser.exceptions.*;
+import org.apache.imperius.util.SPLLogger;
+
+public class CIMActuatorImpl implements Actuator
+{
+
+ private static CIMOMHandle handle = null;
+ private static final String sourceClass="ActuatorImpl";
+ private static Logger logger = SPLLogger.getSPLLogger().getLogger();
+
+
+ CIMActuatorImpl(CIMOMHandle ch)
+ {
+ handle=ch;
+ }
+
+
+
+
+
+ //instanceKeys is a Map containing (name,value) pairs, inParameters and outParameters are maps that have (name,value) pairs which are the arguments for the method
+
+ public Object invokeMethod(String className, String namespace,
+ Object instance, String methodName,
+ List inParameterValues) throws SPLException
+ {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "invokeMethod");
+
+ Vector inParams=new Vector();
+ Vector outParams=new Vector();
+ CIMObjectPath cop=new CIMObjectPath(className,namespace);
+
+ if(className!=null && namespace!=null)
+ {
+ try
+ {
+
+ Iterator it=inParameterValues.iterator();
+ Map cimArgNameValuePairs= new HashMap();
+ while(it.hasNext())
+ {
+ Argument arg=(Argument)it.next();
+ cimArgNameValuePairs.put(arg.getName(), arg.getValue());
+ //System.out.println(" added to cimArgNameValuePairs : "+arg.getName()+ " "+arg.getValue().toString());
+ }
+
+ if(instance instanceof CIMObjectPath)
+ {
+ cop=(CIMObjectPath)instance;
+ CIMObjectPath classCop=new CIMObjectPath(className,namespace);
+ CIMClass cimclass=handle.getClass(classCop, true, true, true, null);
+
+ CIMMethod cimMethod= cimclass.getMethod(methodName);
+ inParams=getMethodInputParams(cimMethod, cimArgNameValuePairs);
+ if(logger.isLoggable(Level.FINE))
+ logger.fine(Thread.currentThread().getName()+" Actuator::invokeMethod:invoking method "+methodName);
+
+ CIMObjectPath instanceCop=new CIMObjectPath(className,namespace);
+ instanceCop.setKeys(cop.getKeys());
+
+ //System.out.println("cop, methodName :"+instanceCop+" "+ methodName);
+ CIMValue cv=handle.invokeMethod(instanceCop, methodName, inParams, outParams);
+ //System.out.println("invokeMethod complete : return value="+cv.getValue());
+ if(logger.isLoggable(Level.FINE))
+ logger.fine(Thread.currentThread().getName()+" Actuator::invokeMethod:done invoking method");
+ if(logger.isLoggable(Level.FINE))
+ logger.fine(outParams.toString());
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "invokeMethod");
+ //Integer returnVal=new Integer(1);
+ return cv.getValue();
+
+ }
+ else{
+ logger.severe(Thread.currentThread().getName()+" "+"instance for method invokation is not of type CIMObjectPath");
+ throw new SPLException("instance for method invokation is not of type CIMObjectPath");
+
+ }
+ }
+ catch(CIMException e){
+ e.printStackTrace();
+ //System.out.println(e.getMessage());
+ logger.severe(Thread.currentThread().getName()+" "+"invokeMethod Failed "+methodName+" "+ className+ " " + namespace+" "+e.getMessage());
+ throw new SPLException("invokeMethod Failed"+methodName+" "+ className+ " " + namespace +" "+ e.getMessage());
+ }
+ }
+ else {
+ logger.severe(Thread.currentThread().getName()+" "+"This CIM class is not handled by the Policy Provider");
+ throw new InvalidCIMParameterException("This CIM class is not handled by the Policy Provider");
+ }
+
+
+ }
+
+
+ //_className, qualifier, instance, modifiedProperties
+ public void modifyInstance(String className,String namespace,Object instance, Map properties) throws SPLException {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "modifyInstance");
+ if(className!=null && namespace!=null){
+ try{
+ if(instance instanceof CIMObjectPath)
+ {
+ CIMObjectPath copTemp=(CIMObjectPath)instance;
+ CIMObjectPath cop=new CIMObjectPath(className,namespace);
+ cop.setKeys(copTemp.getKeys());
+
+
+ if(logger.isLoggable(Level.FINE))
+ logger.fine(Thread.currentThread().getName()+" Actuator::Modify instance :cop"+cop);
+
+ CIMInstance cimInstance= null;
+ try{
+ cimInstance=handle.getInstance(cop, true, true, true, null);
+ }
+ catch(CIMException e){
+ logger.severe(Thread.currentThread().getName()+" "+"instance does not belong to Anchor Class, might be of an extension of Anchor class, no action will be taken on it. "+e.getMessage());
+ throw new SPLException("instance does not belong to Anchor Class, might be of an extension of Anchor class, no action will be taken on it. "+e.getMessage());
+
+ }
+ if(cimInstance != null){
+
+ if(logger.isLoggable(Level.FINE))
+ logger.fine(Thread.currentThread().getName()+" done setting all properties");
+ Vector instanceProperties=generateModifiedPropertiesVector(cimInstance, properties);
+ cimInstance.setProperty(instanceProperties);
+ handle.modifyInstance(cop, cimInstance, true, null);
+ if(logger.isLoggable(Level.FINE))
+ logger.fine(Thread.currentThread().getName()+" done modifying CIMInstance");
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "modifyInstance");
+ }
+ }
+ else
+ {
+
+ logger.severe(Thread.currentThread().getName()+" "+"instance for method invokation is not of type CIMObjectPath");
+ throw new SPLException("instance for method invokation is not of type CIMObjectPath");
+ }
+
+ }
+ catch(CIMException e){
+ e.printStackTrace();
+ logger.severe(Thread.currentThread().getName()+" "+"modify instance Failed :"+ className+ " " + namespace);
+ throw new SPLException("modify Instance Failed :"+ className+ " " + namespace);
+ }
+ }
+ else {
+ logger.severe(Thread.currentThread().getName()+" "+"This CIM class is not handled by the Policy Provider");
+ throw new InvalidCIMParameterException("This CIM class is not handled by the Policy Provider");
+ }
+
+ }
+
+
+ public void init(CIMOMHandle ch) throws SPLException {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "init");
+ handle=ch;
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "init");
+
+
+ }
+ /* (non-Javadoc)
+ * @see com.ibm.pegasus.cimspl.helper.DataCollector#shutDown()
+ */
+ public void shutDown() {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "init");
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "init");
+
+ }
+
+ private CIMValue getCIMObjectOfGivenType(int type, boolean isArray, Object CIMKeyValue) throws CIMException,SPLException
+ {
+ CIMValue cimval=null;
+ if(isArray){
+
+ if(type==CIMDataType.UINT8_ARRAY){
+ if(!(CIMKeyValue instanceof List)){
+ logger.severe(Thread.currentThread().getName()+" "+"expected a List");
+ throw new SPLException("expected a List");
+ }
+ List intArray=(List)CIMKeyValue;
+ Iterator arrayIt=intArray.iterator();
+ List uintArray=new ArrayList();
+ while(arrayIt.hasNext()){
+ Short sht=new Short(Short.parseShort((arrayIt.next()).toString()));
+ UnsignedInt8 uint8= new UnsignedInt8(sht.shortValue());
+ uintArray.add(uint8);
+ }
+ Object actualValue=(UnsignedInt8[])uintArray.toArray();
+ cimval=new CIMValue(actualValue);
+ }
+ if(type==CIMDataType.UINT16_ARRAY){
+ if(!(CIMKeyValue instanceof List)){
+ logger.severe(Thread.currentThread().getName()+" "+"expected a List");
+ throw new SPLException("expected a List");
+ }
+ List intArray=(List)CIMKeyValue;
+ Iterator arrayIt=intArray.iterator();
+ List uintArray=new ArrayList();
+ while(arrayIt.hasNext()){
+ Integer integ=new Integer(Integer.parseInt((arrayIt.next()).toString()));
+ UnsignedInt16 uint16= new UnsignedInt16(integ.intValue());
+ uintArray.add(uint16);
+ }
+ Object actualValue=(UnsignedInt16[])uintArray.toArray();
+ cimval=new CIMValue(actualValue);
+ }
+ if(type==CIMDataType.UINT32_ARRAY){
+ if(!(CIMKeyValue instanceof List)){
+ logger.severe(Thread.currentThread().getName()+" "+"expected a List");
+ throw new SPLException("expected a List");
+ }
+ List intArray=(List)CIMKeyValue;
+ Iterator arrayIt=intArray.iterator();
+ List uintArray=new ArrayList();
+ while(arrayIt.hasNext()){
+ Long lng=new Long(Long.parseLong((arrayIt.next()).toString()));
+ UnsignedInt32 uint32= new UnsignedInt32(lng.longValue());
+ uintArray.add(uint32);
+ }
+ Object actualValue=(UnsignedInt32[])uintArray.toArray();
+ cimval=new CIMValue(actualValue);
+ }
+ if(type==CIMDataType.UINT64_ARRAY){
+ if(!(CIMKeyValue instanceof List)){
+ logger.severe(Thread.currentThread().getName()+" "+"expected a List");
+ throw new SPLException("expected a List");
+ }
+ List intArray=(List)CIMKeyValue;
+ Iterator arrayIt=intArray.iterator();
+ List uintArray=new ArrayList();
+ while(arrayIt.hasNext()){
+ Long lng=new Long(Long.parseLong((arrayIt.next()).toString()));
+ BigInteger big=BigInteger.valueOf(lng.longValue());
+ UnsignedInt64 uint64= new UnsignedInt64(big.abs());
+ uintArray.add(uint64);
+ }
+ Object actualValue=(UnsignedInt64[])uintArray.toArray();
+ cimval=new CIMValue(actualValue);
+ }
+ if(type==CIMDataType.SINT8_ARRAY){
+ if(!(CIMKeyValue instanceof List)){
+ logger.severe(Thread.currentThread().getName()+" "+"expected a List");
+ throw new SPLException("expected a List");
+ }
+ List intArray=(List)CIMKeyValue;
+ Iterator arrayIt=intArray.iterator();
+ List sintArray=new ArrayList();
+ while(arrayIt.hasNext()){
+ Byte bt=new Byte(Byte.parseByte((arrayIt.next()).toString()));
+ sintArray.add(bt);
+ }
+ Object actualValue=(Byte[])sintArray.toArray();
+ cimval=new CIMValue(actualValue);
+ }
+
+ if(type==CIMDataType.SINT16_ARRAY){
+ if(!(CIMKeyValue instanceof List)){
+ logger.severe(Thread.currentThread().getName()+" "+"expected a List");
+ throw new SPLException("expected a List");
+ }
+ List intArray=(List)CIMKeyValue;
+ Iterator arrayIt=intArray.iterator();
+ List sintArray=new ArrayList();
+ while(arrayIt.hasNext()){
+ Short bt=new Short(Short.parseShort((arrayIt.next()).toString()));
+ sintArray.add(bt);
+ }
+ Object actualValue=(Short[])sintArray.toArray();
+ cimval=new CIMValue(actualValue);
+ }
+ if(type==CIMDataType.SINT32_ARRAY){
+ if(!(CIMKeyValue instanceof List)){
+ logger.severe(Thread.currentThread().getName()+" "+"expected a List");
+ throw new SPLException("expected a List");
+ }
+ List intArray=(List)CIMKeyValue;
+ Iterator arrayIt=intArray.iterator();
+ List sintArray=new ArrayList();
+ while(arrayIt.hasNext()){
+ Integer bt=new Integer(Integer.parseInt((arrayIt.next()).toString()));
+ sintArray.add(bt);
+ }
+ Object actualValue=(Integer[])sintArray.toArray();
+ cimval=new CIMValue(actualValue);
+ }
+
+ if(type==CIMDataType.SINT64_ARRAY){
+ if(!(CIMKeyValue instanceof List)){
+ logger.severe(Thread.currentThread().getName()+" "+"expected a List");
+ throw new SPLException("expected a List");
+ }
+ List intArray=(List)CIMKeyValue;
+ Iterator arrayIt=intArray.iterator();
+ List sintArray=new ArrayList();
+ while(arrayIt.hasNext()){
+ Long bt=new Long(Long.parseLong((arrayIt.next()).toString()));
+ sintArray.add(bt);
+ }
+ Object actualValue=(Long[])sintArray.toArray();
+ cimval=new CIMValue(actualValue);
+ }
+
+ if(type==CIMDataType.REAL32_ARRAY){
+ if(!(CIMKeyValue instanceof List)){
+ logger.severe(Thread.currentThread().getName()+" "+"expected a List");
+ throw new SPLException("expected a List");
+ }
+ List intArray=(List)CIMKeyValue;
+ Iterator arrayIt=intArray.iterator();
+ List sintArray=new ArrayList();
+ while(arrayIt.hasNext()){
+ Float bt=new Float(Float.parseFloat((arrayIt.next()).toString()));
+ sintArray.add(bt);
+ }
+ Object actualValue=(Float[])sintArray.toArray();
+ cimval=new CIMValue(actualValue);
+ }
+
+ if(type==CIMDataType.REAL64_ARRAY){
+ if(!(CIMKeyValue instanceof List)){
+ logger.severe(Thread.currentThread().getName()+" "+"expected a List");
+ throw new SPLException("expected a List");
+ }
+ List intArray=(List)CIMKeyValue;
+ Iterator arrayIt=intArray.iterator();
+ List sintArray=new ArrayList();
+ while(arrayIt.hasNext()){
+ Double bt=new Double(Double.parseDouble((arrayIt.next()).toString()));
+ sintArray.add(bt);
+ }
+ Object actualValue=(Double[])sintArray.toArray();
+ cimval=new CIMValue(actualValue);
+ }
+
+ if(type==CIMDataType.BOOLEAN_ARRAY){
+ if(!(CIMKeyValue instanceof List)){
+ logger.severe(Thread.currentThread().getName()+" "+"expected a List");
+ throw new SPLException("expected a List");
+ }
+ List intArray=(List)CIMKeyValue;
+ Iterator arrayIt=intArray.iterator();
+ List sintArray=new ArrayList();
+ while(arrayIt.hasNext()){
+ Boolean bt=Boolean.valueOf((arrayIt.next()).toString());
+ sintArray.add(bt);
+ }
+ Object actualValue=(Boolean[])sintArray.toArray();
+ cimval=new CIMValue(actualValue);
+ }
+ if(type==CIMDataType.CHAR16_ARRAY){
+ if(!(CIMKeyValue instanceof List)){
+ logger.severe(Thread.currentThread().getName()+" "+"expected a List");
+ throw new SPLException("expected a List");
+ }
+ List intArray=(List)CIMKeyValue;
+ Iterator arrayIt=intArray.iterator();
+ List sintArray=new ArrayList();
+ while(arrayIt.hasNext()){
+ Character bt=new Character(((arrayIt.next()).toString()).charAt(0));
+ sintArray.add(bt);
+ }
+ Object actualValue=(Character[])sintArray.toArray();
+ cimval=new CIMValue(actualValue);
+ }
+
+ if(type==CIMDataType.STRING_ARRAY){
+ if(!(CIMKeyValue instanceof List)){
+ logger.severe(Thread.currentThread().getName()+" "+"expected a List");
+ throw new SPLException("expected a List");
+ }
+ List intArray=(List)CIMKeyValue;
+ Iterator arrayIt=intArray.iterator();
+ List sintArray=new ArrayList();
+ while(arrayIt.hasNext()){
+ String bt=(arrayIt.next()).toString();
+ sintArray.add(bt);
+ }
+ Object actualValue=(String[])sintArray.toArray();
+ cimval=new CIMValue(actualValue);
+ }
+
+ if(type==CIMDataType.DATETIME_ARRAY){
+ if(!(CIMKeyValue instanceof List)){
+ logger.severe(Thread.currentThread().getName()+" "+"expected a List");
+ throw new SPLException("expected a List");
+ }
+ List intArray=(List)CIMKeyValue;
+ Iterator arrayIt=intArray.iterator();
+ List cimDateTimeArray=new ArrayList();
+ while(arrayIt.hasNext()){
+ Object ob=arrayIt.next();
+ if(!(ob instanceof Calendar)){
+ throw new SPLException("Value should be of type Calendar");
+ }
+ Calendar cal=(Calendar)ob;
+ CIMDateTime calCIM=new CIMDateTime(cal.getTime());
+ cimDateTimeArray.add(calCIM);
+ }
+ Object actualValue=(CIMDateTime[])cimDateTimeArray.toArray();
+ cimval=new CIMValue(actualValue);
+ }
+
+
+
+ }else{
+ if(type==CIMDataType.UINT8){
+ Short sht=new Short(Short.parseShort(CIMKeyValue.toString()));
+ UnsignedInt8 uint8= new UnsignedInt8(sht.shortValue());
+ cimval=new CIMValue(uint8);
+ }
+ if(type==CIMDataType.UINT16){
+ Integer integ=new Integer(Integer.parseInt(CIMKeyValue.toString()));
+ UnsignedInt16 uint16= new UnsignedInt16(integ.intValue());
+ cimval=new CIMValue(uint16);
+ }
+ if(type==CIMDataType.UINT32){
+ Long lng=new Long(Long.parseLong(CIMKeyValue.toString()));
+ UnsignedInt32 uint32= new UnsignedInt32(lng.longValue());
+ cimval=new CIMValue(uint32);
+ }
+ if(type==CIMDataType.UINT64){
+ Long shrt=new Long(Long.parseLong(CIMKeyValue.toString()));
+ BigInteger big=BigInteger.valueOf(shrt.longValue());
+ UnsignedInt64 uint64= new UnsignedInt64(big.abs());
+ cimval=new CIMValue(uint64);
+ }
+ if(type==CIMDataType.SINT8){
+ Byte byt=new Byte(Byte.parseByte(CIMKeyValue.toString()));
+ cimval=new CIMValue(byt);
+ }
+ if(type==CIMDataType.SINT16){
+ Short sht=new Short(Short.parseShort(CIMKeyValue.toString()));
+ cimval=new CIMValue(sht);
+ }
+ if(type==CIMDataType.SINT32){
+ Integer integ=new Integer(Integer.parseInt(CIMKeyValue.toString()));
+ cimval=new CIMValue(integ);
+ }
+ if(type==CIMDataType.SINT64){
+ Long lng=new Long(Long.parseLong(CIMKeyValue.toString()));
+ cimval=new CIMValue(lng);
+ }
+ if(type==CIMDataType.REAL32){
+ Float flt=new Float(Float.parseFloat(CIMKeyValue.toString()));
+ cimval=new CIMValue(flt);
+ }
+ if(type==CIMDataType.REAL64){
+ Double dbl=new Double(Double.parseDouble(CIMKeyValue.toString()));
+ cimval=new CIMValue(dbl);
+ }
+ if(type==CIMDataType.CHAR16){
+ Character cha=new Character((CIMKeyValue.toString()).charAt(0));
+ cimval=new CIMValue(cha);
+ }
+ if(type==CIMDataType.BOOLEAN){
+ Boolean booln=Boolean.valueOf(CIMKeyValue.toString());
+ cimval=new CIMValue(booln);
+ }
+ if(type==CIMDataType.STRING){
+ String str=CIMKeyValue.toString();
+ cimval=new CIMValue(str);
+ }
+ if(type==CIMDataType.DATETIME){
+ if(!(CIMKeyValue instanceof Calendar)){
+ throw new SPLException("Value should be of type Calendar");
+ }
+ Calendar cal=(Calendar)CIMKeyValue;
+ CIMDateTime calCIM=new CIMDateTime(cal.getTime());
+ cimval=new CIMValue(calCIM);
+ }
+
+ }
+ return cimval;
+ }
+
+
+ private Vector generateModifiedPropertiesVector(CIMInstance cimInstance,Map properties) throws SPLException {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "generateModifiedPropertiesList");
+
+ Vector instanceProperties=cimInstance.getProperties();
+ Set propertyNames=properties.keySet();
+ Iterator propertyIterator=propertyNames.iterator();
+ while(propertyIterator.hasNext()){
+ String keyName=(String)propertyIterator.next();
+ Object KeyValue=properties.get(keyName);
+ Iterator instancePropertyIterator=instanceProperties.iterator();
+
+ while(instancePropertyIterator.hasNext()){
+ CIMProperty cimprop=(CIMProperty)instancePropertyIterator.next();
+ String name=cimprop.getName();
+ int type=cimprop.getType().getType();
+ boolean isArray=cimprop.isArray();
+ CIMValue instValue=cimprop.getValue();
+ if(cimprop.getName().equalsIgnoreCase(keyName)){
+ Object CIMKeyValue=KeyValue;
+ if(logger.isLoggable(Level.FINE))
+ logger.fine(Thread.currentThread().getName()+" Instance property:: Name,Type,Value,CIMKeyValue :"+name+" "+type+" "+instValue+" "+CIMKeyValue.getClass());
+ try{
+
+
+ CIMValue cimval=getCIMObjectOfGivenType(type, isArray, CIMKeyValue);
+
+
+ cimprop.setValue(cimval);
+ if(logger.isLoggable(Level.FINE))
+ logger.fine(Thread.currentThread().getName()+" cimprop set to cimValue "+cimval.getValue());
+
+ }
+ catch(CIMException e){
+ e.printStackTrace();
+ //System.out.println(e.getMessage());
+ logger.severe(Thread.currentThread().getName()+" "+"generateModifiedPropertiesVector Failed ");
+ throw new SPLException("generateModifiedPropertiesVector Failed");
+
+ }
+ }
+
+ }
+
+ }
+
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "generateModifiedPropertiesList");
+
+ return instanceProperties;
+ }
+
+ private Vector getMethodInputParams(CIMMethod cimMethod, Map cimArgNameValuePairs) throws SPLException {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "generateModifiedPropertiesList");
+ Vector inParams=new Vector();
+ for( int j=0; j<cimMethod.getParameterCount(); j++)
+ {
+ try{
+ CIMParameter cimparameter=cimMethod.getParameter(j);
+ String parameterName=cimparameter.getName();
+ int type=cimparameter.getType().getType();
+ boolean isArray=cimparameter.isArray();
+ //System.out.println("parameter name = "+parameterName);
+ Object paramValue=cimArgNameValuePairs.get(parameterName);
+
+ if(paramValue!=null)
+ {
+ CIMValue cv=getCIMObjectOfGivenType(type, isArray, paramValue);
+ //System.out.println("parameter value = "+paramValue+ " "+cv.toString());
+ inParams.add(new CIMProperty(parameterName,cv));
+ }
+ else
+ {
+ //System.out.println("value = null");
+ }
+ }
+ catch(CIMException e){
+ e.printStackTrace();
+ //System.out.println(e.getMessage());
+ logger.severe(Thread.currentThread().getName()+" "+"getMethodInputParams Failed ");
+ throw new SPLException("getMethodInputParams Failed");
+
+ }
+
+ }
+
+ return inParams;
+ }
+
+}
Propchange: incubator/imperius/trunk/imperius-cimsplprovider/src/main/java/org/apache/imperius/cimspl/CIMActuatorImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/imperius/trunk/imperius-cimsplprovider/src/main/java/org/apache/imperius/cimspl/CIMDataCollectorImpl.java
URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/imperius-cimsplprovider/src/main/java/org/apache/imperius/cimspl/CIMDataCollectorImpl.java?rev=629608&view=auto
==============================================================================
--- incubator/imperius/trunk/imperius-cimsplprovider/src/main/java/org/apache/imperius/cimspl/CIMDataCollectorImpl.java (added)
+++ incubator/imperius/trunk/imperius-cimsplprovider/src/main/java/org/apache/imperius/cimspl/CIMDataCollectorImpl.java Wed Feb 20 12:40:03 2008
@@ -0,0 +1,831 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.cimspl;
+
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Vector;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.apache.imperius.spl.external.Argument;
+import org.apache.imperius.spl.external.DataCollector;
+import org.apache.imperius.spl.external.InstanceInfo;
+import org.apache.imperius.spl.external.TypeConstants;
+import org.apache.imperius.spl.parser.compiler.symboltable.MethodSymbol;
+import org.apache.imperius.spl.parser.compiler.symboltable.PropertySymbol;
+import org.apache.imperius.spl.parser.compiler.symboltable.SPLSymbolTable;
+import org.apache.imperius.spl.parser.compiler.symboltable.Symbol;
+import org.apache.imperius.spl.parser.exceptions.ClassDoesNotExistException;
+import org.apache.imperius.spl.parser.exceptions.InstanceDoesNotExistException;
+import org.apache.imperius.spl.parser.exceptions.InvalidCIMParameterException;
+import org.apache.imperius.spl.parser.exceptions.SPLException;
+import org.apache.imperius.spl.parser.statements.impl.ArgumentImpl;
+import org.apache.imperius.util.SPLLogger;
+import org.pegasus.jmpi.CIMClass;
+import org.pegasus.jmpi.CIMException;
+import org.pegasus.jmpi.CIMInstance;
+import org.pegasus.jmpi.CIMMethod;
+import org.pegasus.jmpi.CIMOMHandle;
+import org.pegasus.jmpi.CIMObjectPath;
+import org.pegasus.jmpi.CIMParameter;
+import org.pegasus.jmpi.CIMProperty;
+import org.pegasus.jmpi.CIMValue;
+
+
+
+public class CIMDataCollectorImpl implements DataCollector
+{
+ private static CIMOMHandle _handle;
+ private static Logger logger = SPLLogger.getSPLLogger().getLogger();
+ private static String sourceClass = "CIM_SPLPolicyRuleProvider";
+
+
+ CIMDataCollectorImpl(CIMOMHandle ch)
+ {
+ _handle=ch;
+ }
+
+
+ private void _populateClassMembers(String className,String classPath, Map symbolMap)
+ throws SPLException
+ {
+ if(className!=null && classPath!=null)
+ {
+ CIMObjectPath cop=new CIMObjectPath(className,classPath);
+ if(logger.isLoggable(Level.FINE))
+ logger.fine(Thread.currentThread().getName()+" cop "+cop);
+ Map symbols=symbolMap;
+ //get class
+ try
+ {
+ //System.out.println("_handle.getClass");
+
+ CIMClass cimclass=_handle.getClass(cop, true, true, true, null);
+ if(logger.isLoggable(Level.FINE))
+ logger.fine(Thread.currentThread().getName()+" got class "+cimclass.getName());
+ if(cimclass!=null)
+ {
+ if(logger.isLoggable(Level.FINE))
+ logger.fine(Thread.currentThread().getName()+" get all the properties of the class and iterate over them");
+ //System.out.println("get all the properties of the class and iterate over them");
+ //get all the properties of the class and iterate over them
+
+ Vector properties=getPropertiesOfClass(cimclass ,classPath );
+
+ for(int i=0;i<properties.size();i++)
+ {
+ CIMProperty cimproperty=(CIMProperty) properties.get(i);
+ String qualifiedPropertyName= cimproperty.getName();
+ if(logger.isLoggable(Level.FINE))
+ logger.fine(Thread.currentThread().getName()+" PropertyName "+cimproperty.getName().toLowerCase());
+ if(logger.isLoggable(Level.FINE))
+ logger.fine(Thread.currentThread().getName()+" qualifiedPropertyName "+qualifiedPropertyName);
+// //add the property to the HashMap as(class.propertyName, PropertySymbol)
+ if( ! symbols.containsKey(qualifiedPropertyName))
+ {
+
+ int type=CIMSPLTypeConstants.convertCIMTypeToInternalType(cimproperty.getType().getType());
+ String referenceTypeName="";
+ if(type == TypeConstants.referenceType)
+ {
+ String path=(String)cimproperty.getValue().getValue();
+ //the property is a CIMObjectPath
+ referenceTypeName=CIMSPLTypeConstants.getReferenceTypeName(path);
+ }
+
+ if(logger.isLoggable(Level.FINE))
+ logger.fine(Thread.currentThread().getName()+" symboltable does not currently contain the given property, so creating property symbol");
+ Symbol symbol =new PropertySymbol(qualifiedPropertyName,type,referenceTypeName,cimproperty.isArray(),_isKey(cimproperty),true);
+ //add property to properties list
+ if(logger.isLoggable(Level.FINE))
+ logger.fine(Thread.currentThread().getName()+" adding property to Map in datacollector : "+qualifiedPropertyName);
+ symbols.put(qualifiedPropertyName, symbol);
+
+ }
+ else
+ {
+ if(logger.isLoggable(Level.FINE))
+ logger.fine(Thread.currentThread().getName()+" symboltable already contains the given symbol "+cimproperty.getName().toLowerCase());
+ logger.severe(qualifiedPropertyName+" symbol Already exists in SymbolTable");
+ throw new SPLException("symbol Already exists in SymbolTable");
+ }
+
+ }
+ if(logger.isLoggable(Level.FINE))
+ logger.fine(Thread.currentThread().getName()+" done adding all the properties");
+ if(logger.isLoggable(Level.FINE))
+ logger.fine(Thread.currentThread().getName()+" get all methods of the class and iterate over them");
+
+
+
+
+
+
+ //get all methods of the class and iterate over them
+ for(int i=0;i<cimclass.getMethodCount();i++)
+ {
+ CIMMethod cimMethod= cimclass.getMethod(i);
+
+ if(logger.isLoggable(Level.FINE))
+ logger.fine(Thread.currentThread().getName()+" method : "+cimMethod.getName()+ " Parameter count "+cimMethod.getParameterCount()+" is of type "+cimMethod.getType());
+// //ArrayList argTypeList=new ArrayList ();
+ List methodArgs=new ArrayList();
+ SPLSymbolTable methodArgsSymbolTable=new SPLSymbolTable();
+
+ for(int j=0;j<cimMethod.getParameterCount();j++)
+ {
+ CIMParameter cimparameter=cimMethod.getParameter(j);
+ String parameterName=cimparameter.getName();
+ boolean isArr=cimparameter.isArray();
+ int type=CIMSPLTypeConstants.convertCIMTypeToInternalType(cimparameter.getType().getType());
+
+ String referenceTypeName="";
+
+ if(type == TypeConstants.referenceType)
+ {
+ referenceTypeName = CIMSPLTypeConstants.getReferenceTypeName(cimparameter.getReferenceClassName());
+ }
+ Argument arg=new ArgumentImpl(type, parameterName, isArr, referenceTypeName);
+
+ methodArgsSymbolTable.insertVariableSymbol(parameterName, type, referenceTypeName, isArr, false, false);
+ //System.out.println(" inserted variable symbol into methodArgsSymbolTable "+parameterName);
+ methodArgs.add(arg);
+ }
+ String methodName=cimMethod.getName();
+ if( ! symbols.containsKey(methodName))
+ {
+ int localReturnType=CIMSPLTypeConstants.convertCIMTypeToInternalType(cimMethod.getType());
+
+ Symbol methodSymbol=new MethodSymbol(methodName,localReturnType,CIMSPLTypeConstants.getIsArray(localReturnType),cimclass.getName(),methodArgs,methodArgsSymbolTable);
+ //add property to properties list
+ if(logger.isLoggable(Level.FINE))
+ logger.fine(Thread.currentThread().getName()+" adding method to symbol table" + methodName);
+ symbols.put(methodName, methodSymbol);
+ }
+ else
+ {
+ if(logger.isLoggable(Level.FINE))
+ logger.fine(Thread.currentThread().getName()+" SymbolTable already contains the given method "+methodName);
+ logger.severe(Thread.currentThread().getName()+" "+"SymbolTable already contains the given method "+methodName);
+ throw new CIMException("SymbolTable already contains the given method "+methodName);
+ }
+
+ }
+ if(logger.isLoggable(Level.FINE))
+ logger.fine(Thread.currentThread().getName()+" done adding methods to the symboltable");
+
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "getSymbolsForClass");
+ //return symbols;
+ }
+ else
+ {
+ if(logger.isLoggable(Level.FINE))
+ logger.fine(Thread.currentThread().getName()+" handle : the cimclass is null");
+ logger.severe(Thread.currentThread().getName()+" "+"This CIM class does not exist");
+ throw new ClassDoesNotExistException("This CIM class does not exist");
+ }
+
+ }
+ catch (CIMException e){
+ logger.severe(Thread.currentThread().getName()+" "+"Failed to get class "+e.getMessage());
+ throw new SPLException("Failed to get class");
+ }
+
+ }
+ else {
+
+ logger.severe(Thread.currentThread().getName()+" "+"This CIM class is not handled by the Policy Provider");
+ throw new InvalidCIMParameterException("This CIM class is not handled by the Policy Provider");
+ }
+
+
+
+
+
+ }
+
+ public Map getSymbolsForClass(String className, String qualifier)
+ throws SPLException
+ {
+ String formattedClass = null;
+ if(className.startsWith("\"")) // string of form ""lkasdlk""
+ {
+ formattedClass = className.substring(1, className.length() -1 );
+ }
+ else
+ {
+ formattedClass = className;
+ }
+ //System.out.println("formatted class" + formattedClass);
+ Map symbolMap = new Hashtable();
+ _populateClassMembers(formattedClass,qualifier,symbolMap);
+
+ return symbolMap;
+
+ }
+
+ public Map getSymbolsForInstance(String className, String namespc, Object cop)
+ throws SPLException
+ {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "getInstanceMap");
+ if(cop instanceof CIMObjectPath)
+ {
+ CIMObjectPath cimObjectPath= new CIMObjectPath(className,namespc);
+ CIMObjectPath cop1=(CIMObjectPath)cop;
+ cimObjectPath.setKeys(cop1.getKeys());
+ try{
+ CIMInstance ci=_handle.getInstance(cimObjectPath, true, true, true, null);
+ Map instanceProperties=new HashMap();
+ //get all properties of the current instance
+ Vector properties=ci.getProperties();
+ for(int i=0;i<properties.size();i++)
+ {
+ //add property to HashMap as (class.name,value) pair
+ CIMProperty cimproperty=(CIMProperty) properties.get(i);
+ String qualifiedPropertyName= cimproperty.getName();
+ instanceProperties.put(qualifiedPropertyName, cimproperty.getValue().getValue());
+ }
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "getInstanceMap");
+
+ return instanceProperties;
+ }
+ catch(CIMException e)
+ {
+ logger.severe(e.getMessage());
+ throw new SPLException(e.getMessage());
+ }
+
+ }
+ else
+ {
+ throw new SPLException("Reference is not of Type CIMObjectPath");
+ }
+
+
+ }
+
+
+
+
+
+
+
+ public List getAssociatedInstanceNames(
+ Object srcInstanceName,
+ String nameSpace,
+ String resultClass,
+ String assocClass,
+ String role,
+ String resultRole) throws SPLException
+ {
+ return null;
+ }
+// public List getAssociatedInstances(Object refExpressionResult, String nameSpace, String targetClassName, String associationName, String sourceRole, String targetRole) {
+// // TODO Auto-generated method stub
+// return null;
+// }
+
+ private static Vector getPropertiesOfClass(CIMClass cimClass ,String classPath ) throws CIMException{
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "getPropertiesOfClass");
+ CIMClass cimclass=cimClass;
+ Vector propertyNames=new Vector();
+ Vector properties=cimclass.getProperties();
+ Iterator it=properties.iterator();
+ String superClass=cimclass.getSuperClass();
+
+ while(it.hasNext()){
+ CIMProperty cimProp=(CIMProperty)it.next();
+ //System.out.println("cimProp "+cimProp.toString());
+ String propName=cimProp.getName();
+ //System.out.println("propName "+propName);
+
+ propertyNames.add(propName);
+
+ }
+ superClass=cimclass.getSuperClass();
+
+ while((superClass!= null)&&(superClass!= "")&&(superClass.length()!=0)){
+ CIMObjectPath cop=new CIMObjectPath(superClass,classPath);
+ cimclass=_handle.getClass(cop, true, true, true, null);
+
+ Vector propertiesSuper=cimclass.getAllProperties();
+ Iterator proppertiesSuperIt=propertiesSuper.iterator();
+ while(proppertiesSuperIt.hasNext()){
+ CIMProperty cimProp=(CIMProperty)proppertiesSuperIt.next();
+ if (!propertyNames.contains(cimProp.getName()))
+ {
+ properties.add(cimProp);
+ String propName=cimProp.getName();
+ propertyNames.add(propName);
+ if(logger.isLoggable(Level.FINE))
+ logger.fine(cimProp.getName()+"new superclass property found "+cimProp.getName());
+
+
+ }
+ else
+ {
+ if(logger.isLoggable(Level.FINE))
+ logger.fine(cimProp.getName()+"already exists ,Super class variable ignored");
+
+ }
+
+ }
+ superClass=cimclass.getSuperClass();
+ }
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "getPropertiesOfClass");
+
+ return properties;
+ }
+
+
+ private boolean _isKey(CIMProperty cimproperty){
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "_isKey");
+ //find the location of the qualifier "Key"
+ int location=cimproperty.findQualifier("Key");
+ //get the qualifier at that location and compare it to "Key"
+ if(location>=0){
+ if(cimproperty.getQualifier(location).getName().equalsIgnoreCase("Key")){
+ if(logger.isLoggable(Level.FINE))
+ logger.fine(Thread.currentThread().getName()+" property is a key");
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "_isKey");
+ return true;
+ }
+ }
+
+ if(logger.isLoggable(Level.FINE))
+ logger.fine(Thread.currentThread().getName()+" property is not a key");
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "_isKey");
+ return false;
+
+ }
+
+
+ public List enumerateInstanceNames(String className, String namespace)
+ throws SPLException
+ {
+ String formattedClass = null;
+ if(className.startsWith("\"")) // string of form ""lkasdlk""
+ {
+ formattedClass = className.substring(1, className.length() -1 );
+ }
+ else
+ {
+ formattedClass = className;
+ }
+ //System.out.println("formatted class" + formattedClass);
+ CIMObjectPath classCop=new CIMObjectPath(formattedClass,namespace);
+ List instanceList=new ArrayList();
+ try{
+ Enumeration instanceEnumeration=_handle.enumerateInstanceNames(classCop);
+ while(instanceEnumeration.hasMoreElements())
+ {
+ instanceList.add(instanceEnumeration.nextElement());
+ }
+ return instanceList;
+ }
+ catch (CIMException e){
+ throw new SPLException(e.getMessage());
+ }
+
+ }
+
+
+ public boolean associationExists(String className ,String classPath, String resultClass, String assocClass, String role, String resultRole) throws SPLException {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "associationExists");
+ CIMObjectPath cop=new CIMObjectPath(assocClass,classPath);
+ if(logger.isLoggable(Level.FINE))
+ logger.fine(Thread.currentThread().getName()+" associationExists::cop ::"+cop);
+ try{
+ CIMClass associationClass=_handle.getClass(cop, true, true, true, null);
+ if(logger.isLoggable(Level.FINE))
+ logger.fine(Thread.currentThread().getName()+" got class "+associationClass.getName());
+ if(logger.isLoggable(Level.FINE))
+ logger.fine(Thread.currentThread().getName()+" check to see if the class is an association");
+ //check to see if the class is an association
+
+ boolean isAssoc=associationClass.isAssociation();
+ if(logger.isLoggable(Level.FINE))
+ logger.fine(Thread.currentThread().getName()+" CIMClass, isAssociation()= "+isAssoc+" "+associationClass.getAllProperties().toString());
+ if(isAssoc){
+ boolean result=validateAssociation(associationClass,className ,classPath,resultClass, role, resultRole);
+ return result;
+ }
+ else
+ {
+ if(logger.isLoggable(Level.FINE))
+ logger.fine(Thread.currentThread().getName()+" associationExists returning false because CIMClass.isAssociation()= "+isAssoc);
+
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "associationExists");
+ return false;
+ }
+ }
+ catch (CIMException e){
+ logger.severe(Thread.currentThread().getName()+" "+"Failed to get class");
+ throw new SPLException("Failed to get class");
+ }
+
+
+ }
+
+
+ private static boolean _classNameMatchesString(String str,String namespace,String className ) throws CIMException{
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "classNameMatchesString");
+ //CIMClass cimclass=cimClass;
+ //Vector propertyNames=new Vector();
+ CIMObjectPath copOriginal=new CIMObjectPath(className,namespace);
+ CIMClass cimclass=_handle.getClass(copOriginal, true, true, true, null);
+ String classnm=cimclass.getName();
+ String superClass=cimclass.getSuperClass();
+ if(classnm.equalsIgnoreCase(str))
+ {
+ if(logger.isLoggable(Level.FINE))
+ logger.fine(Thread.currentThread().getName()+" classNameMatchesString "+classnm+ " "+str);
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "classNameMatchesString");
+ return true;
+ }
+
+ else if(superClass!= null)
+ {
+ while((superClass!= "")&&(superClass.length()!=0)){
+ //System.out.println("superclass "+superClass);
+ if(superClass.equalsIgnoreCase(str))
+ {
+ if(logger.isLoggable(Level.FINE))
+ logger.fine(Thread.currentThread().getName()+" classNameMatchesString "+superClass+ " "+str);
+
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "classNameMatchesString");
+ return true;
+ }
+
+ else
+ {
+ if(logger.isLoggable(Level.FINE))
+ logger.fine(superClass+" did not Match "+str+" ,trying superclass");
+
+ CIMObjectPath cop=new CIMObjectPath(superClass,namespace);
+ cimclass=_handle.getClass(cop, true, true, true, null);
+ superClass=cimclass.getSuperClass();
+ if(logger.isLoggable(Level.FINE))
+ logger.fine(Thread.currentThread().getName()+" new superclass= "+superClass);
+
+ }
+
+ }
+
+ }
+ if(logger.isLoggable(Level.FINE))
+ logger.fine(Thread.currentThread().getName()+" string did not match classname or superclass names "+str);
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "classNameMatchesString");
+ return false;
+
+ }
+
+ public List getAssociatedInstanceReferences(Object srcReference, String classPath, String resultInstancesClassFilter, String assocClass, String role, String resultRole) throws SPLException {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "getAssociatedInstanceReferences");
+ if(logger.isLoggable(Level.FINE))
+ logger.fine(Thread.currentThread().getName()+" String className, String classPath, String resultInstancesClassFilter, String assocClass, String role, String resultRole,Map keys");
+ CIMObjectPath srcRef=(CIMObjectPath)srcReference;
+ String className=srcRef.getObjectName();
+
+ if(logger.isLoggable(Level.FINE))
+ logger.fine(className+" "+classPath+" "+resultInstancesClassFilter+" "+ assocClass+" "+role+" "+ resultRole+" "+ srcReference.toString());
+
+
+ if(className!=null && classPath!=null)
+ {
+ try{
+
+
+ List instanceREFList=new ArrayList();
+ //check to see if the association exists
+ if(logger.isLoggable(Level.FINE))
+ logger.fine(Thread.currentThread().getName()+" check to see if the association exists");
+ if(associationExists(className ,classPath,resultInstancesClassFilter,assocClass,role,resultRole)){
+ //System.out.println("association exists");
+ //create cop of anchor object
+ CIMObjectPath cop=new CIMObjectPath(className,classPath);
+ cop.setKeys(srcRef.getKeys());
+ //add keys of the source instance to the cop
+
+ if(logger.isLoggable(Level.FINE))
+ logger.fine(Thread.currentThread().getName()+" Anchor Object cop "+cop);
+
+
+
+ CIMObjectPath copAssociationClass=new CIMObjectPath(assocClass,classPath);
+
+ //enumerating all instances of associaation class
+ Enumeration instancesOfAssociation=_handle.enumerateInstances(copAssociationClass, true, true, true, true, null);
+ //iterating over all instances of association class
+ while(instancesOfAssociation.hasMoreElements()){
+ CIMInstance inst=(CIMInstance)instancesOfAssociation.nextElement();
+ //check to see if the source instance is same as current Anchor Object
+
+ CIMProperty srcinstcop=inst.getProperty(role);//this will return partial cop of src instance
+ CIMObjectPath copSrcInstFull=CIMObjectPath.toCop(srcinstcop.getValue().getValue().toString());
+ if(logger.isLoggable(Level.FINE))
+ logger.fine(Thread.currentThread().getName()+" Anchor cop "+cop);
+ if(equalCOP(copSrcInstFull,cop)){
+ //get and add associated result instance to vector
+ CIMProperty cimprop=inst.getProperty(resultRole);
+ CIMObjectPath coop= CIMObjectPath.toCop(cimprop.getValue().getValue().toString());
+ CIMObjectPath copAssociatedInstance=new CIMObjectPath(resultInstancesClassFilter,classPath);
+ copAssociatedInstance.setKeys(coop.getKeys());
+ //Reference ref=new Reference(copAssociatedInstance.toString());
+ instanceREFList.add(copAssociatedInstance);
+
+ }
+ else{
+ if(logger.isLoggable(Level.FINE))
+ logger.fine(Thread.currentThread().getName()+" property did not match");
+ }
+
+ }
+ return instanceREFList;
+ }
+
+ else
+ {
+ logger.severe(Thread.currentThread().getName()+" "+"The instance does not exist");
+ throw new InstanceDoesNotExistException("The instance does not exist");
+ }
+ }catch(CIMException e)
+ {
+ e.printStackTrace();
+ logger.severe(Thread.currentThread().getName()+" "+e.getMessage());
+ throw new SPLException(e.getMessage());
+
+ }
+
+ }
+ else {
+ logger.severe(Thread.currentThread().getName()+" "+"This CIM class is not handled by the Policy Provider");
+ throw new InvalidCIMParameterException("This CIM class is not handled by the Policy Provider");
+ }
+ }
+
+
+ private static boolean equalCOP(CIMObjectPath cop1,CIMObjectPath cop2)
+ {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "equalCOP");
+ //CIMObjectPath cimCOP1=new CIMObjectPath(cop1);
+ //CIMObjectPath cimCOP2=new CIMObjectPath(cop2);
+ boolean result=false;
+ if(logger.isLoggable(Level.FINE))
+ logger.fine(Thread.currentThread().getName()+" comparing::"+cop1.toString()+" == "+ cop2.toString());
+
+
+
+ Vector keys1=cop1.getKeys();
+ Vector keys2=cop2.getKeys();
+ Iterator it=keys1.iterator();
+ Iterator it2=keys2.iterator();
+ while(it.hasNext() && it2.hasNext())
+ {
+ CIMProperty prop=(CIMProperty)it.next();
+ CIMProperty prop2=(CIMProperty)it2.next();
+ String propertyname=prop.getName();
+ String propertyname2=prop2.getName();
+ CIMValue cimv1=prop.getValue();
+ CIMValue cimv2=prop2.getValue();
+ try
+ {
+ //System.out.println(" "+propertyname+" "+propertyname2+" "+cimv1.getValue()+" "+cimv2.getValue());
+ if(!propertyname.equalsIgnoreCase(propertyname2))
+ {
+ if(logger.isLoggable(Level.FINE))
+ logger.fine(Thread.currentThread().getName()+" propertyname did not match");
+
+ return false;
+ }
+
+ if(!cimv1.getValue().toString().equalsIgnoreCase(cimv2.getValue().toString()))
+ {
+ if(logger.isLoggable(Level.FINE))
+ logger.fine(Thread.currentThread().getName()+" getValue did not match");
+
+ return false;
+ }
+ }
+ catch(CIMException e)
+ {
+ e.printStackTrace();
+ }
+
+ }
+ result=true;
+
+ //boolean result=cop1.toLowerCase().trim().equalsIgnoreCase(cop2.toLowerCase().trim());
+ if(result)
+ {
+ if(logger.isLoggable(Level.FINE))
+ logger.fine(Thread.currentThread().getName()+" equalCOP::"+cop1+" = "+ cop2);
+
+
+ }
+ else
+ {
+ if(logger.isLoggable(Level.FINE))
+ logger.fine(Thread.currentThread().getName()+" equalCOP::"+cop1+" != "+ cop2);
+
+ }
+
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "equalCOP");
+ return result;
+
+ }
+
+// public String getReferenceTypeName(String reference)
+// {
+
+// //extract class name and return
+// String referenceType = CIMSPLTypeConstants.getReferenceTypeName(reference);
+
+// return referenceType;
+// }
+
+
+ private boolean validateAssociation(CIMClass associationClass,String className ,String classPath, String resultClass
+ , String role, String resultRole) throws SPLException{
+ if(logger.isLoggable(Level.FINE))
+ logger.fine(Thread.currentThread().getName()+" class is an association");
+ CIMProperty srcProperty=associationClass.getProperty(role);
+ if(logger.isLoggable(Level.FINE))
+ logger.fine(Thread.currentThread().getName()+" check to see if the role played by src class is correct");
+ if(logger.isLoggable(Level.FINE))
+ logger.fine(Thread.currentThread().getName()+" src RefClassName(),className::"+srcProperty.getRefClassName()+" "+className);
+ //check to see if the role played by src class is correct
+ try{
+ if(_classNameMatchesString(srcProperty.getRefClassName().toString().trim(), classPath, className))
+ {
+ CIMProperty resultProperty=associationClass.getProperty(resultRole);
+ if(logger.isLoggable(Level.FINE))
+ logger.fine(Thread.currentThread().getName()+" check to see if role played by result class is corrrect");
+ if(logger.isLoggable(Level.FINE))
+ logger.fine(Thread.currentThread().getName()+" result RefClassName(),className::"+resultProperty.getRefClassName()+" "+resultClass);
+
+ //check to see if role played by result class is corrrect
+ if(_classNameMatchesString(resultProperty.getRefClassName().toString().trim(), classPath, resultClass))
+ {
+ if(logger.isLoggable(Level.FINE))
+ logger.fine(Thread.currentThread().getName()+" associationExists returning true");
+
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "associationExists");
+ return true;
+ }
+ else
+ {
+ if(logger.isLoggable(Level.FINE))
+ logger.fine(Thread.currentThread().getName()+" associationExists returning false because of resultClass "+resultClass+ " "+resultProperty.getRefClassName());
+
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "associationExists");
+ return false;
+ }
+ }
+ else
+ {
+ if(logger.isLoggable(Level.FINE))
+ logger.fine(Thread.currentThread().getName()+" associationExists returning false because of className "+className+ " != "+srcProperty.getRefClassName());
+
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "associationExists");
+ return false;
+ }
+ }
+ catch(CIMException e){
+ e.printStackTrace();
+ //System.out.println(e.getMessage());
+ logger.severe(Thread.currentThread().getName()+" "+"validateAssociation Failed ");
+ throw new SPLException("validateAssociation Failed");
+
+ }
+
+ }
+
+
+// public boolean isInstance(String className, Object instance)
+// throws SPLException
+// {
+// System.out.println("className :"+className);
+// System.out.println("instance :"+instance);
+// System.out.println("instance :"+instance.getClass());
+
+//// 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);
+
+// if(instance instanceof org.apache.imperius.spl.external.InstanceInfo ){
+// InstanceInfo instinf=(InstanceInfo)instance;
+// Object obj=instinf.getInstance();
+// String name=instinf.getInstanceName();
+// System.out.println("name, obj :"+name+" "+obj+" "+obj.getClass());
+// if(obj instanceof org.pegasus.jmpi.CIMObjectPath){
+// CIMObjectPath cop = (CIMObjectPath)obj;
+// String instClassName = cop.getObjectName();
+// if(!className.equals(instClassName)){
+// return false;
+// }
+
+// }
+// else{
+// return false;
+// }
+
+
+// }
+// else if(instance instanceof java.util.ArrayList ){
+// System.out.println("instance is an arraylist :"+instance.getClass());
+
+// ArrayList IIList=(ArrayList)instance;
+// Iterator it=IIList.iterator();
+// while( it.hasNext()){
+// InstanceInfo instinf=(InstanceInfo)it.next();
+// Object obj=instinf.getInstance();
+// String name=instinf.getInstanceName();
+// System.out.println("name, obj :"+name+" "+obj+" "+obj.getClass());
+// if(obj instanceof org.pegasus.jmpi.CIMObjectPath){
+// CIMObjectPath cop = (CIMObjectPath)obj;
+// String instClassName = cop.getObjectName();
+// if(!className.equals(instClassName)){
+// return false;
+// }
+
+// }
+// else{
+// return false;
+// }
+// }
+
+
+
+// }
+// else if(instance instanceof org.pegasus.jmpi.CIMObjectPath){
+// System.out.println("instance is not an instance info or arraylist");
+// System.out.println("instance class :"+instance.getClass());
+
+// CIMObjectPath cop = (CIMObjectPath)instance;
+// String instClassName = cop.getObjectName();
+// if(!className.equals(instClassName)){
+// return false;
+// }
+
+// }
+
+
+
+
+// return true;
+
+
+// }
+
+
+ public boolean isInstance(String className, Object instance)
+ throws SPLException
+ {
+ if(instance instanceof CIMObjectPath){
+ CIMObjectPath cop = (CIMObjectPath)instance;
+ String instClassName = cop.getObjectName();
+ if(className.equals(instClassName))
+ return true;
+ }
+
+ return false;
+ }
+
+
+}
\ No newline at end of file
Propchange: incubator/imperius/trunk/imperius-cimsplprovider/src/main/java/org/apache/imperius/cimspl/CIMDataCollectorImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/imperius/trunk/imperius-cimsplprovider/src/main/java/org/apache/imperius/cimspl/CIMSPLTypeConstants.java
URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/imperius-cimsplprovider/src/main/java/org/apache/imperius/cimspl/CIMSPLTypeConstants.java?rev=629608&view=auto
==============================================================================
--- incubator/imperius/trunk/imperius-cimsplprovider/src/main/java/org/apache/imperius/cimspl/CIMSPLTypeConstants.java (added)
+++ incubator/imperius/trunk/imperius-cimsplprovider/src/main/java/org/apache/imperius/cimspl/CIMSPLTypeConstants.java Wed Feb 20 12:40:03 2008
@@ -0,0 +1,408 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.cimspl;
+
+
+import java.util.logging.Logger;
+import org.pegasus.jmpi.CIMObjectPath;
+
+
+import org.apache.imperius.spl.external.TypeConstants;
+import org.apache.imperius.util.SPLLogger;
+//import com.ibm.pegasus.cimspl.parser.exceptions.TypeMismatchException;
+
+public class CIMSPLTypeConstants
+{
+
+ private static Logger logger = SPLLogger.getSPLLogger().getLogger();
+ private static final String sourceClass="CIMSPLTypeConstants";
+
+ public static final int SIZE_SINGLE = 0;
+
+ public static final int SIZE_UNLIMITED = 1;
+
+ public static final int SIZE_LIMITED = 2;
+
+ private final static int ARRAY = 0x10;
+
+ private final static int OTHER = 0x20;
+
+ public static final int INVALID = 0;
+
+ public static final int UINT8 = 1;
+
+ public static final int SINT8 = 2;
+
+ public static final int UINT16 = 3;
+
+ public static final int SINT16 = 4;
+
+ public static final int UINT32 = 5;
+
+ public static final int SINT32 = 6;
+
+ public static final int UINT64 = 7;
+
+ public static final int SINT64 = 8;
+
+ public static final int STRING = 9;
+
+ public static final int BOOLEAN = 10;
+
+ public static final int REAL32 = 11;
+
+ public static final int REAL64 = 12;
+
+ public static final int DATETIME = 13;
+
+ public static final int CHAR16 = 14;
+
+ public static final int OBJECT = 15;
+
+ public static final int UINT8_ARRAY = ARRAY + UINT8;
+
+ public static final int SINT8_ARRAY = ARRAY + SINT8;
+
+ public static final int UINT16_ARRAY = ARRAY + UINT16;
+
+ public static final int SINT16_ARRAY = ARRAY + SINT16;
+
+ public static final int UINT32_ARRAY = ARRAY + UINT32;
+
+ public static final int SINT32_ARRAY = ARRAY + SINT32;
+
+ public static final int UINT64_ARRAY = ARRAY + UINT64;
+
+ public static final int SINT64_ARRAY = ARRAY + SINT64;
+
+ public static final int STRING_ARRAY = ARRAY + STRING;
+
+ public static final int BOOLEAN_ARRAY = ARRAY + BOOLEAN;
+
+ public static final int REAL32_ARRAY = ARRAY + REAL32;
+
+ public static final int REAL64_ARRAY = ARRAY + REAL64;
+
+ public static final int DATETIME_ARRAY = ARRAY + DATETIME;
+
+ public static final int CHAR16_ARRAY = ARRAY + CHAR16;
+
+ public static final int OBJECT_ARRAY = ARRAY + OBJECT;
+
+ public static final int REFERENCE = OTHER + 1;
+
+
+ public static boolean getIsArray(int type)
+ {
+ if(type> 10)
+ {
+ return true;
+ }
+ return false;
+
+ }
+ public static int convertInternalTypeToCIMType(int type, boolean isArray, Object obj)
+ {
+ int cimType = -1;
+ if(type == TypeConstants.byteType)
+ {
+ if(isArray)
+ {
+ cimType = CIMSPLTypeConstants.UINT8_ARRAY;
+ }
+ else
+ {
+ cimType = CIMSPLTypeConstants.UINT8;
+ }
+ }
+ else if(type == TypeConstants.shortType)
+ {
+ if(isArray)
+ {
+ cimType = CIMSPLTypeConstants.UINT16_ARRAY;
+ }
+ else
+ {
+ cimType = CIMSPLTypeConstants.UINT16;
+ }
+ }
+ else if(type == TypeConstants.intType)
+ {
+ if(isArray)
+ {
+ cimType = CIMSPLTypeConstants.UINT32_ARRAY;
+ }
+ else
+ {
+ cimType = CIMSPLTypeConstants.UINT32;
+ }
+ }
+ else if(type == TypeConstants.longType)
+ {
+ if(isArray)
+ {
+ cimType = CIMSPLTypeConstants.UINT64_ARRAY;
+ }
+ else
+ {
+ cimType = CIMSPLTypeConstants.UINT64;
+ }
+ }
+ else if(type == TypeConstants.floatType)
+ {
+ if(isArray)
+ {
+ cimType = CIMSPLTypeConstants.REAL32_ARRAY;
+ }
+ else
+ {
+ cimType = CIMSPLTypeConstants.REAL32_ARRAY;
+ }
+ }
+ else if(type == TypeConstants.doubleType)
+ {
+ if(isArray)
+ {
+ cimType = CIMSPLTypeConstants.REAL64_ARRAY;
+ }
+ else
+ {
+ cimType = CIMSPLTypeConstants.REAL64;
+ }
+ }
+ else if(type == TypeConstants.booleanType)
+ {
+ if(isArray)
+ {
+ cimType = CIMSPLTypeConstants.BOOLEAN_ARRAY;
+ }
+ else
+ {
+ cimType = CIMSPLTypeConstants.BOOLEAN;
+ }
+ }
+ else if(type == TypeConstants.charType)
+ {
+ if(isArray)
+ {
+ cimType = CIMSPLTypeConstants.CHAR16_ARRAY;
+ }
+ else
+ {
+ cimType = CIMSPLTypeConstants.CHAR16;
+ }
+ }
+ else if(type == TypeConstants.stringType)
+ {
+ if(isArray)
+ {
+ cimType = CIMSPLTypeConstants.STRING_ARRAY;
+ }
+ else
+ {
+ cimType = CIMSPLTypeConstants.STRING;
+ }
+ }
+ else if(type == TypeConstants.dateTime)
+ {
+ if(isArray)
+ {
+ cimType = CIMSPLTypeConstants.DATETIME_ARRAY;
+ }
+ else
+ {
+ cimType = CIMSPLTypeConstants.DATETIME;
+ }
+ }
+ else if(type == TypeConstants.referenceType)
+ {
+ if(isArray)
+ {
+ cimType = CIMSPLTypeConstants.REFERENCE;
+ //System.out.println("encountered reference array, no equivalent CIM type");
+ }
+ else
+ {
+ cimType = CIMSPLTypeConstants.REFERENCE;
+ }
+ }
+
+
+ return cimType;
+
+ }
+
+ public static int convertCIMTypeToInternalType(int type)
+ {
+
+
+ int retTp = -1;
+
+ if ((type == CIMSPLTypeConstants.UINT8)
+ || (type == CIMSPLTypeConstants.SINT8)
+ || (type == CIMSPLTypeConstants.UINT8_ARRAY)
+ || (type == CIMSPLTypeConstants.SINT8_ARRAY))
+ {
+ retTp = TypeConstants.byteType;
+ }
+ else if ((type == CIMSPLTypeConstants.UINT16)
+ || (type == CIMSPLTypeConstants.SINT16)
+ || (type == CIMSPLTypeConstants.UINT16_ARRAY)
+ || (type == CIMSPLTypeConstants.SINT16_ARRAY))
+ {
+ retTp = TypeConstants.shortType;
+ }
+ else if ((type == CIMSPLTypeConstants.UINT32)
+ || (type == CIMSPLTypeConstants.SINT32)
+ || (type == CIMSPLTypeConstants.UINT32_ARRAY)
+ || (type == CIMSPLTypeConstants.SINT32_ARRAY))
+ {
+ retTp = TypeConstants.intType;
+ }
+ else if ((type == CIMSPLTypeConstants.UINT64)
+ || (type == CIMSPLTypeConstants.SINT64)
+ || (type == CIMSPLTypeConstants.UINT64_ARRAY)
+ || (type == CIMSPLTypeConstants.SINT64_ARRAY))
+ {
+ retTp = TypeConstants.longType;
+ }
+ else if ((type == CIMSPLTypeConstants.REAL32)
+ || (type == CIMSPLTypeConstants.REAL32_ARRAY))
+ {
+ retTp = TypeConstants.floatType;
+ }
+ else if ((type == CIMSPLTypeConstants.REAL64)
+ || (type == CIMSPLTypeConstants.REAL64_ARRAY))
+ {
+ retTp = TypeConstants.doubleType;
+ }
+ else if ((type == CIMSPLTypeConstants.BOOLEAN)
+ || (type == CIMSPLTypeConstants.BOOLEAN_ARRAY))
+ {
+ retTp = TypeConstants.booleanType;
+ }
+ else if ((type == CIMSPLTypeConstants.CHAR16)
+ || (type == CIMSPLTypeConstants.CHAR16_ARRAY))
+ {
+ retTp = TypeConstants.charType;
+ }
+ else if ((type == CIMSPLTypeConstants.STRING)
+ || (type == CIMSPLTypeConstants.STRING_ARRAY))
+ {
+ retTp = TypeConstants.stringType;
+ }
+ else if ((type == CIMSPLTypeConstants.DATETIME)
+ || (type == CIMSPLTypeConstants.DATETIME_ARRAY))
+ {
+ retTp = TypeConstants.dateTime;
+ }
+ else if (type == CIMSPLTypeConstants.REFERENCE)
+ {
+ retTp = TypeConstants.referenceType;
+ }
+
+
+ //logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "cimToLocalTypeConversion");
+
+ return retTp;
+
+ }
+
+
+
+ public static int getTypeOfObject(Object ob)
+ {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "getTypeOfObject");
+
+ int currentLocaltype = -1;
+ if (ob instanceof java.lang.Boolean)
+ {
+ currentLocaltype = TypeConstants.booleanType;
+ }
+ else if (ob instanceof java.lang.String)
+ {
+ currentLocaltype = TypeConstants.stringType;
+ }
+ else if (ob instanceof java.util.Calendar)
+ {
+ currentLocaltype = TypeConstants.dateTime;
+ }
+ else if (ob instanceof java.lang.Byte)
+ {
+ currentLocaltype = TypeConstants.byteType;
+ }
+ else if (ob instanceof java.lang.Character)
+ {
+ currentLocaltype = TypeConstants.charType;
+ }
+ else if (ob instanceof java.lang.Short)
+ {
+ currentLocaltype = TypeConstants.shortType;
+ }
+ else if (ob instanceof java.lang.Integer)
+ {
+ currentLocaltype = TypeConstants.intType;
+ }
+ else if (ob instanceof java.lang.Long)
+ {
+ currentLocaltype = TypeConstants.longType;
+ }
+ else if (ob instanceof java.lang.Float)
+ {
+ currentLocaltype = TypeConstants.floatType;
+ }
+ else if (ob instanceof java.lang.Double)
+ {
+ currentLocaltype = TypeConstants.doubleType;
+ }
+ else if (ob instanceof java.util.Date)
+ {
+ currentLocaltype = TypeConstants.dateTime;
+ }
+ else
+ {
+ currentLocaltype = TypeConstants.referenceType;
+ }
+ // if (ob instanceof com.ibm.ac.spl.parser.expressions.Reference)
+ // currentLocaltype = 13;
+
+ // public static final int referenceType = 13;
+ // PB:what do we do about references
+
+
+ return currentLocaltype;
+ }
+ public static String getReferenceTypeName(String reference)
+ {
+
+ //extract class name and return
+ String referenceType = null;
+ CIMObjectPath cop=CIMObjectPath.toCop(reference);
+ referenceType=cop.getObjectName();
+
+ return referenceType;
+ }
+
+}
Propchange: incubator/imperius/trunk/imperius-cimsplprovider/src/main/java/org/apache/imperius/cimspl/CIMSPLTypeConstants.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/imperius/trunk/imperius-cimsplprovider/src/main/java/org/apache/imperius/cimspl/CIM_SPLPolicyRuleProvider.java
URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/imperius-cimsplprovider/src/main/java/org/apache/imperius/cimspl/CIM_SPLPolicyRuleProvider.java?rev=629608&view=auto
==============================================================================
--- incubator/imperius/trunk/imperius-cimsplprovider/src/main/java/org/apache/imperius/cimspl/CIM_SPLPolicyRuleProvider.java (added)
+++ incubator/imperius/trunk/imperius-cimsplprovider/src/main/java/org/apache/imperius/cimspl/CIM_SPLPolicyRuleProvider.java Wed Feb 20 12:40:03 2008
@@ -0,0 +1,574 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.cimspl;
+
+
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.Vector;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.pegasus.jmpi.CIMArgument;
+import org.pegasus.jmpi.CIMClass;
+import org.pegasus.jmpi.CIMException;
+import org.pegasus.jmpi.CIMInstance;
+import org.pegasus.jmpi.CIMMethodProvider2;
+import org.pegasus.jmpi.CIMOMHandle;
+import org.pegasus.jmpi.CIMObjectPath;
+import org.pegasus.jmpi.CIMProperty;
+import org.pegasus.jmpi.CIMValue;
+import org.pegasus.jmpi.InstanceProvider2;
+import org.pegasus.jmpi.OperationContext;
+
+
+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.external.InternalClient;
+import org.apache.imperius.spl.manager.PolicyManager;
+import org.apache.imperius.spl.manager.impl.PolicyManagerImpl;
+import org.apache.imperius.spl.parser.exceptions.SPLException;
+import org.apache.imperius.spl.parser.statements.impl.PolicyInfo;
+import org.apache.imperius.spl.parser.util.InternalClientFactory;
+import org.apache.imperius.util.SPLLogger;
+
+
+
+public class CIM_SPLPolicyRuleProvider implements InstanceProvider2,CIMMethodProvider2
+{
+
+ public static final String POLICY_CLASS_NAME = "CIM_SPLPolicyRule";
+ public static final String NAMESPACE = "root/cimv2";
+
+ private static Logger logger = null;
+ private InternalClient _internalClient=null;
+ private PolicyManager _policyManager= null;
+ private static String sourceClass = "CIM_SPLPolicyRuleProvider";
+ private static CIMOMHandle _handle;
+// private static Logger auditLogger = null;
+ public static boolean ENABLE_SPL_LOGGING = false;
+
+ public void cleanup() throws CIMException { }
+
+ public void initialize(CIMOMHandle ch) throws CIMException
+ {
+ _handle=ch;
+
+ String home = System.getProperty("user.dir");
+ System.out.println("SPL Home Set to" + home);
+ SPLLogger.SPL_HOME = home;
+ logger = SPLLogger.getSPLLogger().getLogger();
+// auditLogger = SPLLogger.getSPLLogger().getAuditLogger();
+//
+// if(auditLogger.isLoggable(Level.FINE))
+// logger.fine(Thread.currentThread().getName()+" Initializing Policy Provider" );
+ DataCollector dc = new CIMDataCollectorImpl(ch);
+
+ Actuator ac = new CIMActuatorImpl(ch);
+
+ _policyManager= new PolicyManagerImpl(dc,ac);
+
+ _internalClient=new InternalClient(_policyManager);
+ InternalClientFactory.registerInternalClient(_internalClient);
+
+ }
+
+
+ public CIMObjectPath createInstance(OperationContext oc,
+ CIMObjectPath cop, CIMInstance cimInstance)
+ throws CIMException
+ {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+"createInstance");
+ if(logger.isLoggable(Level.FINE))
+ logger.fine(Thread.currentThread().getName()+" Creating Policy instance :"+cop);
+
+
+ PolicyInstance pi = _createPolicyInstance(cop, cimInstance);
+ try
+ {
+ boolean instcreated = _policyManager.createPolicy(pi.getPolicyRuleName(),pi.getPolicyString());
+ if(instcreated)
+ {
+ CIMObjectPath cimop=_createPolicyObjectPath(pi.getPolicyRuleName());
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+"createInstance");
+ return cimop;
+ }
+ else
+ {
+ logger.severe("instance not created");
+ throw new CIMException("instance not created");
+ }
+ }
+ catch(SPLException e)
+ {
+ logger.severe("instance not created");
+ throw new CIMException("instance not created" +e.getMessage());
+ }
+
+
+ }
+
+
+
+ public void deleteInstance(OperationContext oc, CIMObjectPath cop) throws CIMException
+ {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+"deleteInstance");
+ if(logger.isLoggable(Level.FINE))
+ logger.fine(Thread.currentThread().getName()+" Deleting Policy instance :"+cop);
+
+ String policyRuleName=cop.getKeyValue("PolicyRuleName");
+ try
+ {
+ _policyManager.deletePolicy(policyRuleName);
+ }
+ catch (SPLException e)
+ {
+ logger.severe(Thread.currentThread().getName()+" "+"deleteInstance failed :"
+ + e.getMessage());
+ throw new CIMException("deleteInstance failed :"+e.getMessage());
+ }
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+"deleteInstance");
+ return;
+ }
+
+
+ public Vector enumerateInstanceNames(OperationContext oc, CIMObjectPath cop,
+ CIMClass cimClass) throws CIMException
+ {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+"enumerateInstanceNames");
+ if(logger.isLoggable(Level.FINE))
+ logger.fine(Thread.currentThread().getName()+" Enumerating Policy instance names :"+cop);
+
+ String nameSpace = cop.getNameSpace();
+ String className = cimClass.getName();
+ // retrieving policy Names from Repository
+ if (logger.isLoggable(Level.FINE))
+ logger.fine(Thread.currentThread().getName() + " retrieving Policies Names from policyRepository");
+
+ if ((className.equals(POLICY_CLASS_NAME))&& (nameSpace.equals(NAMESPACE)))
+ {
+ try
+ {
+
+ List policyNames=_policyManager.getAllPolicyNames();
+ Iterator it=policyNames.iterator();
+ Vector instances=new Vector();
+ while(it.hasNext())
+ {
+ String pi=(String)it.next();
+ CIMObjectPath cimInst=_createPolicyObjectPath(pi);
+ instances.add(cimInst);
+ }
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+"enumerateInstanceNames");
+ return instances;
+ }
+ catch (SPLException e)
+ {
+ logger.severe(Thread.currentThread().getName()+" "+"enumerateInstances failed :"+e.getMessage());
+ throw new CIMException("enumerateInstances failed :"+e.getMessage());
+ }
+ }
+
+ else
+ {
+ logger
+ .severe(Thread.currentThread().getName()+" "+"This CIM class is not handled by the Policy Provider");
+ throw new CIMException(
+ "This CIM class is not handled by the Policy Provider");
+ }
+ }
+
+ public Vector enumerateInstances(OperationContext oc, CIMObjectPath cop, CIMClass cimClass,
+ boolean includeQualifiers, boolean includeClassOrigin, String[] propertyList)
+ throws CIMException
+ {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+"enumerateInstances");
+ if(logger.isLoggable(Level.FINE))
+ logger.fine(Thread.currentThread().getName()+" Enumerating Policy instances :"+cop);
+
+ String nameSpace = cop.getNameSpace();
+ String className = cimClass.getName();
+ // enumerating Policies from policyRepository
+ if (logger.isLoggable(Level.FINE))
+ logger.fine(Thread.currentThread().getName()+" enumerating Policies from policyRepository");
+ // USE equalscase instead
+ if (className.equals(POLICY_CLASS_NAME) && nameSpace.equals(NAMESPACE))
+ {
+ try
+ {
+ Map policyInstances=_policyManager.getAllPolicies();
+ Set polNames=policyInstances.keySet();
+ Iterator it=polNames.iterator();
+ Vector instances=new Vector();
+ while(it.hasNext())
+ {
+ String pi=(String)it.next();
+ CIMInstance cimInst=_createPolicyCIMInstance(pi, (String)policyInstances.get(pi));
+ instances.add(cimInst);
+ }
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+"enumerateInstances");
+
+ return instances;
+ }
+ catch (SPLException e)
+ {
+ logger.severe(Thread.currentThread().getName()+" "+"enumerateInstances failed :"+e.getMessage());
+ throw new CIMException("enumerateInstances failed :"+e.getMessage());
+ }
+ }
+
+ else
+ {
+ logger
+ .severe(Thread.currentThread().getName()+" "+"This CIM class is not handled by the Policy Provider");
+ throw new CIMException("This CIM class is not handled by the Policy Provider");
+ }
+
+
+ }
+
+
+ public CIMInstance getInstance(OperationContext oc, CIMObjectPath cop, CIMClass cimClass,
+ boolean includeQualifiers, boolean includeClassOrigin, String[] propertyList)
+ throws CIMException
+ {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+"getInstance");
+ if(logger.isLoggable(Level.FINE))
+ logger.fine(Thread.currentThread().getName()+" Getting Policy instance :"+cop);
+
+ String nameSpace = cop.getNameSpace();
+ String PolicyRuleName = cop.getKeyValue("PolicyRuleName");
+ String className = cimClass.getName();
+ if ((className.equals(POLICY_CLASS_NAME))
+ && (nameSpace.equals(NAMESPACE)))
+ {
+ try
+ {
+ String pi=_policyManager.getPolicy(PolicyRuleName);
+ CIMInstance cimInst=_createPolicyCIMInstance(PolicyRuleName, pi);
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+"getInstance");
+ return cimInst;
+ }
+ catch (SPLException e)
+ {
+ logger.severe(Thread.currentThread().getName()+" "+"getInstance failed :"+e.getMessage());
+ throw new CIMException("getInstance failed :"+e.getMessage());
+ }
+ }
+ else
+ {
+ logger
+ .severe(Thread.currentThread().getName()+" "+"This CIM class is not handled by the Policy Provider");
+ throw new CIMException("This CIM class is not handled by the Policy Provider");
+ }
+
+ }
+
+ public Vector execQuery(OperationContext oc, CIMObjectPath cop, CIMClass cimClass,
+ String queryStatement, String queryLanguage) throws CIMException
+ {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+"execQuery");
+ if(logger.isLoggable(Level.FINE))
+ logger.fine(Thread.currentThread().getName()+" not implemented");
+
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+"execQuery");
+ return null;
+ }
+
+ public void setInstance(OperationContext oc, CIMObjectPath cop, CIMInstance ci) throws CIMException
+ {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+"setInstance");
+ if(logger.isLoggable(Level.FINE))
+ logger.fine(Thread.currentThread().getName()+" Setting Policy instance :"+cop);
+
+ if ((ci.getClassName().equals(POLICY_CLASS_NAME))
+ && (cop.getNameSpace().equals(NAMESPACE)))
+ {
+ String policyRuleName = ci.getProperty("PolicyRuleName").getValue()
+ .getValue().toString();
+ String policyString = ((((CIMProperty) ci
+ .getProperty("PolicyString")).getValue()).getValue())
+ .toString();
+ try
+ {
+ _policyManager.updatePolicy(policyRuleName,policyString);
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+"setInstance");
+ }
+ catch (SPLException e)
+ {
+ logger.severe(Thread.currentThread().getName()+" "+"setInstance failed :"+e.getMessage());
+ throw new CIMException("setInstance failed :"+e.getMessage());
+ }
+
+ }
+ else
+ {
+ logger
+ .severe(Thread.currentThread().getName()+" "+"This CIM class is not handled by the Policy Provider");
+ throw new CIMException(
+ "This CIM class is not handled by the Policy Provider");
+ }
+ }
+
+
+
+
+ public CIMValue invokeMethod(OperationContext oc, CIMObjectPath cop, String name,
+ CIMArgument[] in, CIMArgument[] out) throws CIMException
+ {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+"invokeMethod");
+ if(logger.isLoggable(Level.FINE))
+ logger.fine(Thread.currentThread().getName()+" Invoking Policy method :"+name +" on :"+ cop);
+// if(auditLogger.isLoggable(Level.FINE))
+// auditLogger.fine(Thread.currentThread().getName()+" Invoking Policy method :"+name +" on :"+ cop);
+ //System.out.println(" Invoking Policy method :"+name +" on :"+ cop);
+
+
+ boolean inparamsIsNotNull=false;
+ boolean inparamsLengthGreaterThanZero=false;
+ boolean arrayOfInstancesParamFound=false;
+ boolean arrayOfInstancesParamSizeGreaterThanZero=false;
+ Integer returnValue = new Integer(-1);
+ try
+ {
+ Map objMap = new Hashtable();
+ String policyRuleName=cop.getKeyValue("PolicyRuleName");
+
+ if (in != null)
+ {
+ logger.fine(Thread.currentThread().getName() + "params passed");
+ inparamsIsNotNull=true;
+ if(in.length > 0)
+ {
+ inparamsLengthGreaterThanZero=true;
+ for(int i=0;i<in.length;i++)
+ {
+ CIMArgument cimarg=in[i];
+ if(cimarg.getName().equalsIgnoreCase("arrayOfInstances"))
+ {
+ arrayOfInstancesParamFound=true;
+ CIMValue cv=cimarg.getValue();
+
+ List arrayCop=(List)cv.getValue();
+
+ Iterator it=arrayCop.iterator();
+ while(it.hasNext())
+ {
+ arrayOfInstancesParamSizeGreaterThanZero=true;
+ CIMObjectPath copI=(CIMObjectPath)it.next();
+ String objectName=copI.getObjectName();
+
+ //InstanceInfo iI=new InstanceInfo(objectName,copI);
+
+ //List instanceInfoList = new ArrayList();
+ //instanceInfoList.add(iI);
+
+ objMap.put(objectName, copI);
+
+ Integer retVal=(Integer)_policyManager.evaluatePolicy(policyRuleName,objMap);
+ if (logger.isLoggable(Level.FINE))
+ logger.fine(Thread.currentThread().getName()+" return value is = "+retVal);
+
+ objMap.remove(objectName);
+
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+"invokeMethod");
+ }
+
+ }
+
+ break;
+
+ }
+
+ }
+
+ }
+ if( !inparamsIsNotNull || !inparamsLengthGreaterThanZero || !arrayOfInstancesParamFound ||
+ !arrayOfInstancesParamSizeGreaterThanZero)
+ {
+
+ logger.fine(Thread.currentThread().getName() + "no instances passed evaluating against all");
+
+ PolicyInfo policyInfo=this._policyManager.getPolicyInfo(policyRuleName);
+
+ Map classQuaifierMap=policyInfo.getClassQualifierMap();
+ Iterator classit=classQuaifierMap.keySet().iterator();
+
+ if(classQuaifierMap.size()==0 || classQuaifierMap.size()>1)
+ {
+ logger.severe(Thread.currentThread().getName() + "Multiple Import classes not supported in CIM-SPL");
+ }
+ while(classit.hasNext())
+ {
+ String className=(String)classit.next();
+ String nameSpace=(String)classQuaifierMap.get(className);
+ CIMObjectPath classCop=new CIMObjectPath(className,nameSpace);
+ Enumeration copEnum=_handle.enumerateInstanceNames(classCop);
+ while(copEnum.hasMoreElements())
+ {
+
+ CIMObjectPath copI=(CIMObjectPath)copEnum.nextElement();
+ logger.fine(Thread.currentThread().getName() + "instance objectpath= "+copI.toString());
+
+ String objectName=copI.getObjectName();
+
+ if(objectName.equalsIgnoreCase(className))
+ {
+// InstanceInfo iI=new InstanceInfo(objectName,copI);
+//
+// List instanceInfoList = new ArrayList();
+// instanceInfoList.add(iI);
+
+ objMap.put(objectName, copI);
+
+ logger.fine(Thread.currentThread().getName() + "about to invoke evaluate policy");
+
+ returnValue=(Integer)_policyManager.evaluatePolicy(policyRuleName,objMap);
+ if (logger.isLoggable(Level.FINE))
+ logger.fine(Thread.currentThread().getName()+" return value is = "+returnValue);
+
+ objMap.remove(objectName);
+
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+"invokeMethod");
+
+ }
+ else{
+
+ }
+
+ }
+
+ break;
+
+ }
+
+ }
+
+ return new CIMValue(returnValue);
+ }
+ catch (SPLException e)
+ {
+ logger.severe(Thread.currentThread().getName()+" "+"getInstance failed :"+e.getMessage());
+ throw new CIMException("getInstance failed :"+e.getMessage());
+ }
+
+ }
+
+ private PolicyInstance _createPolicyInstance(CIMObjectPath op, CIMInstance ci) throws CIMException
+ {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+"createPolicyInstance");
+
+ if ((ci.getClassName().equals(POLICY_CLASS_NAME))
+ && (op.getNameSpace().equals(NAMESPACE)))
+ {
+
+ String PolicyRuleName = ci.getProperty("PolicyRuleName").getValue().getValue().toString();
+ String PolicyString = ((((CIMProperty) ci
+ .getProperty("PolicyString")).getValue()).getValue())
+ .toString();
+ // check to see if PolicyRuleName and PolicyString are valid
+ if (logger.isLoggable(Level.FINE))
+ logger.fine(Thread.currentThread().getName()+" PolicyRuleName and PolicyString " + PolicyRuleName
+ + " " + PolicyString);
+ PolicyInstance pi= new PolicyInstance(PolicyRuleName,PolicyString);
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+"createPolicyInstance");
+
+ return pi;
+
+
+ }
+ else
+ {
+ logger
+ .severe(Thread.currentThread().getName()+" "+"This CIM class is not handled by the Policy Provider");
+ throw new CIMException(
+ "This CIM class is not handled by the Policy Provider");
+ }
+
+ }
+
+ private static CIMInstance _createPolicyCIMInstance(String policyRuleName,
+ String PolicyString) throws CIMException
+ {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "_createPolicyCIMInstance");
+ if ((policyRuleName != null) && (PolicyString != null))
+ {
+ if (logger.isLoggable(Level.FINE))
+ logger.fine(Thread.currentThread().getName()+" create a CIMPolicy Object out of the PolicyString and PolicyRuleName");
+ // create a CIMPolicy Object out of the PolicyString and
+ // PolicyRuleName
+ CIMInstance policyInstance = new CIMInstance(POLICY_CLASS_NAME);
+
+ policyInstance.setProperty("SystemCreationClassName",
+ new CIMValue("cim_splpolicyrule"));
+ policyInstance.setProperty("SystemName", new CIMValue("localhost.localdomain"));
+ policyInstance.setProperty("CreationClassName", new CIMValue(POLICY_CLASS_NAME));
+ policyInstance.setProperty("PolicyRuleName", new CIMValue(policyRuleName));
+ policyInstance.setProperty("PolicyString", new CIMValue(PolicyString));
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "_createPolicyCIMInstance");
+ return policyInstance;
+ }
+ else
+ {
+ logger.severe(Thread.currentThread().getName()+" "+"The Policy cannot be found due to Invalid Policy Parameters");
+ throw new CIMException("The Policy cannot be found due to Invalid Policy Parameters");
+ }
+ }
+
+ private static CIMObjectPath _createPolicyObjectPath(String policyRuleName)
+ throws CIMException
+ {
+ logger.entering(sourceClass,Thread.currentThread().getName()+" "+ "_createPolicyObjectPath");
+ if (policyRuleName != null)
+ {
+ if (logger.isLoggable(Level.FINE))
+ logger.fine(Thread.currentThread().getName()+" create a CIMObjectPath using the PolicyRuleName");
+ // create a CIMObjectPath using the PolicyRuleName
+ CIMObjectPath cop = new CIMObjectPath(POLICY_CLASS_NAME, NAMESPACE);
+ cop.addKey("SystemName", new CIMValue("localhost.localdomain"));
+ cop.addKey("CreationClassName", new CIMValue(POLICY_CLASS_NAME));
+ cop.addKey("PolicyRuleName", new CIMValue(policyRuleName));
+ logger.exiting(sourceClass,Thread.currentThread().getName()+" "+ "_createPolicyObjectPath");
+ return cop;
+
+ }
+ else
+ {
+ logger
+ .severe(Thread.currentThread().getName()+" "+"The Policy cannot be found due to Invalid Policy Parameters");
+ throw new CIMException(
+ "The Policy cannot be found due to Invalid Policy Parameters");
+ }
+ }
+
+}
Propchange: incubator/imperius/trunk/imperius-cimsplprovider/src/main/java/org/apache/imperius/cimspl/CIM_SPLPolicyRuleProvider.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/imperius/trunk/imperius-cimsplprovider/src/main/java/org/apache/imperius/cimspl/PolicyInstance.java
URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/imperius-cimsplprovider/src/main/java/org/apache/imperius/cimspl/PolicyInstance.java?rev=629608&view=auto
==============================================================================
--- incubator/imperius/trunk/imperius-cimsplprovider/src/main/java/org/apache/imperius/cimspl/PolicyInstance.java (added)
+++ incubator/imperius/trunk/imperius-cimsplprovider/src/main/java/org/apache/imperius/cimspl/PolicyInstance.java Wed Feb 20 12:40:03 2008
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.cimspl;
+
+public class PolicyInstance
+{
+ String policyRuleName=null;
+ String policyString=null;
+ public PolicyInstance (String PolRuleName, String PolString)
+ {
+ this.policyRuleName=PolRuleName;
+ this.policyString=PolString;
+ }
+ public String getPolicyRuleName()
+ {
+ return policyRuleName;
+ }
+ public void setPolicyRuleName(String policyRuleName)
+ {
+ this.policyRuleName = policyRuleName;
+ }
+ public String getPolicyString()
+ {
+ return policyString;
+ }
+ public void setPolicyString(String policyString)
+ {
+ this.policyString = policyString;
+ }
+
+}
Propchange: incubator/imperius/trunk/imperius-cimsplprovider/src/main/java/org/apache/imperius/cimspl/PolicyInstance.java
------------------------------------------------------------------------------
svn:eol-style = native