/*
* 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 <prabalig@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.core.Argument;
import org.apache.imperius.spl.core.DataCollector;
import org.apache.imperius.spl.core.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;
}
}