📄 commoninstanceprovider.java
字号:
//%2006//////////////////////////////////////////////////////////////////////////// Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development// Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.// Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;// IBM Corp.; EMC Corporation, The Open Group.// Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;// IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.// Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;// EMC Corporation; VERITAS Software Corporation; The Open Group.// Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;// EMC Corporation; Symantec Corporation; The Open Group.//// Permission is hereby granted, free of charge, to any person obtaining a copy// of this software and associated documentation files (the "Software"), to// deal in the Software without restriction, including without limitation the// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or// sell copies of the Software, and to permit persons to whom the Software is// furnished to do so, subject to the following conditions://// THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN// ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED// "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT// LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.////==============================================================================//// Author: Mark Hamzy, hamzy@us.ibm.com//// Modified By: Mark Hamzy, hamzy@us.ibm.com////// This code is based on TestPropertyTypes.cpp//// Original Author: Yi Zhou (yi_zhou@hp.com)//// Original Modified By: Roger Kumpf, Hewlett-Packard Company (roger_kumpf@hp.com)// Sushma Fernandes, Hewlett-Packard Company// (sushma_fernandes@hp.com)// Carol Ann Krug Graves, Hewlett-Packard Company// (carolann_graves@hp.com)////%/////////////////////////////////////////////////////////////////////////////package Indications;import java.util.Vector;import java.util.HashMap;import java.util.Iterator;import org.pegasus.jmpi.CIMArgument;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.CIMOMHandle;import org.pegasus.jmpi.CIMObjectPath;import org.pegasus.jmpi.CIMProperty;import org.pegasus.jmpi.CIMQualifier;import org.pegasus.jmpi.CIMValue;import org.pegasus.jmpi.InstanceProvider;import org.pegasus.jmpi.MethodProvider;import org.pegasus.jmpi.OperationContext;import org.pegasus.jmpi.SelectExp;import org.pegasus.jmpi.SelectList;import org.pegasus.jmpi.NonJoinExp;import org.pegasus.jmpi.QueryExp;import org.pegasus.jmpi.UnsignedInt16;import org.pegasus.jmpi.UnsignedInt32;import org.pegasus.jmpi.UnsignedInt64;import org.pegasus.jmpi.UnsignedInt8;public class CommonInstanceProvider{ protected CommonInstanceProvider (String providerName, String namespace, String instanceClassname) { this.providerName = providerName; this.namespace = namespace; this.instanceClassname = instanceClassname; } public void initialize (CIMOMHandle ch) throws CIMException { if (DEBUG) { System.err.println (providerName + "::initialize: ch = " + ch); } this.ch = ch; } public void cleanup () throws CIMException { if (DEBUG) { System.err.println (providerName + "::cleanup"); } } public CIMObjectPath createInstance (OperationContext oc, CIMObjectPath cop, CIMInstance cimInstance) throws CIMException { if (DEBUG) { System.err.println (providerName + "::createInstance: oc = " + oc); System.err.println (providerName + "::createInstance: cop = " + cop); System.err.println (providerName + "::createInstance: cimInstance = " + cimInstance); } // Esure that the namespace is valid if (!cop.getNameSpace ().equalsIgnoreCase (namespace)) { throw new CIMException (CIMException.CIM_ERR_INVALID_NAMESPACE); }//////if (DEBUG)//////{////// System.err.println (providerName + "::createInstance: cop2 = " + cimInstance.getObjectPath ());////// Vector vectorKeyValuePairs = cimInstance.getKeyValuePairs ();////// CIMObjectPath cop3 = new CIMObjectPath (cimInstance.getClassName (),////// vectorKeyValuePairs);////// System.err.println (providerName + "::createInstance: cop3 = " + cop3);////// System.err.println (providerName + "::createInstance: vectorKeyValuePairs = " + vectorKeyValuePairs);////// CIMClass cc = ch.getClass (cop, true);////// Vector ccQualifiers = cc.getQualifiers ();////// System.err.print (providerName + "::createInstance: cc.getQualifiers = ");////// for (int i = 0; i < ccQualifiers.size (); i++)////// {////// System.err.print (((CIMQualifier)ccQualifiers.elementAt (i)).getName () + ", " + ((CIMQualifier)ccQualifiers.elementAt (i)).getValue ());////// if (i < ccQualifiers.size () - 1)////// {////// System.err.print (", ");////// }////// }////// System.err.println ("}");//////////// CIMObjectPath cop4 = validatePropertyTypeInstance (cimInstance, false);////// System.err.println (providerName + "::createInstance: cop4 = " + cop4);//////} // Ensure that the class exists in the specified namespace if (cop.getObjectName ().equalsIgnoreCase (instanceClassname)) { // Ensure that the instance contains the required keys cop = validatePropertyTypeInstance (cimInstance, false); if (cop == null) { throw new CIMException (CIMException.CIM_ERR_INVALID_PARAMETER); } // Ensure that the property values are valid testPropertyTypeInstance (cimInstance); // Ensure that the requested object does not exist if (findCOPInPropertyTypes (cop) >= 0) { throw new CIMException (CIMException.CIM_ERR_ALREADY_EXISTS); } if (fEnableModifications) { paths.addElement (cop); instances.addElement (cimInstance); paths.sort (); instances.sort (); return cop; } else { throw new CIMException (CIMException.CIM_ERR_INVALID_PARAMETER); } } else { throw new CIMException (CIMException.CIM_ERR_INVALID_CLASS); } } public CIMInstance getInstance (OperationContext oc, CIMObjectPath cop, CIMClass cimClass, boolean includeQualifiers, boolean includeClassOrigin, boolean localOnly, String propertyList[]) throws CIMException { if (DEBUG) { System.err.println (providerName + "::getInstance: oc = " + oc); System.err.println (providerName + "::getInstance: cop = " + cop); System.err.println (providerName + "::getInstance: cimClass = " + cimClass); System.err.println (providerName + "::getInstance: includeQualifiers = " + includeQualifiers); System.err.println (providerName + "::getInstance: includeClassOrigin = " + includeClassOrigin); System.err.println (providerName + "::getInstance: localOnly = " + localOnly); System.err.println (providerName + "::getInstance: propertyList = " + propertyList); } // Esure that the namespace is valid if (!cop.getNameSpace ().equalsIgnoreCase (namespace)) { throw new CIMException (CIMException.CIM_ERR_INVALID_NAMESPACE); } // Ensure that the class exists in the specified namespace if (cop.getObjectName ().equalsIgnoreCase (instanceClassname)) { // Ensure that the keys are valid if (!validatePropertyTypePath (cop)) { throw new CIMException (CIMException.CIM_ERR_INVALID_PARAMETER); } // Ensure that the request object exists int index = findCOPInPropertyTypes (cop); if (index < 0) { throw new CIMException (CIMException.CIM_ERR_NOT_FOUND); } return (CIMInstance)instances.elementAt (index); } else { throw new CIMException (CIMException.CIM_ERR_INVALID_CLASS); } } public void setInstance (OperationContext oc, CIMObjectPath cop, CIMInstance cimInstance, boolean includeQualifiers, String[] propertyList) throws CIMException { if (DEBUG) { System.err.println (providerName + "::setInstance: oc = " + oc); System.err.println (providerName + "::setInstance: cop = " + cop); System.err.println (providerName + "::setInstance: cimInstance = " + cimInstance); System.err.println (providerName + "::setInstance: includeQualifiers = " + includeQualifiers); System.err.println (providerName + "::setInstance: propertyList = " + propertyList); } // Esure that the namespace is valid if (!cop.getNameSpace ().equalsIgnoreCase (namespace)) { throw new CIMException (CIMException.CIM_ERR_INVALID_NAMESPACE); } // Ensure that the class exists in the specified namespace if (cop.getObjectName ().equalsIgnoreCase (instanceClassname)) { // Ensure that the property values are valid testPropertyTypeInstance (cimInstance); // Ensure that the keys are valid if (!validatePropertyTypePath (cop)) { throw new CIMException (CIMException.CIM_ERR_INVALID_PARAMETER); } // Ensure that the request object exists int index = findCOPInPropertyTypes (cop); if (index < 0) { throw new CIMException (CIMException.CIM_ERR_NOT_FOUND); } if (fEnableModifications) { paths.removeElementAt (index); instances.removeElementAt (index); paths.addElement (cop); instances.addElement (cimInstance); paths.sort (); instances.sort (); } else { throw new CIMException (CIMException.CIM_ERR_INVALID_PARAMETER); } } else { throw new CIMException (CIMException.CIM_ERR_INVALID_NAMESPACE); } } public void deleteInstance (OperationContext oc, CIMObjectPath cop) throws CIMException { if (DEBUG) { System.err.println (providerName + "::deleteInstance: oc = " + oc); System.err.println (providerName + "::deleteInstance: cop = " + cop); } // Esure that the namespace is valid if (!cop.getNameSpace ().equalsIgnoreCase (namespace)) { throw new CIMException (CIMException.CIM_ERR_INVALID_NAMESPACE); } // Ensure that the class exists in the specified namespace if (cop.getObjectName ().equalsIgnoreCase (instanceClassname)) { // Ensure that the keys are valid if (!validatePropertyTypePath (cop)) { throw new CIMException (CIMException.CIM_ERR_INVALID_PARAMETER); } // Ensure that the request object exists int index = findCOPInPropertyTypes (cop); if (index < 0) { throw new CIMException (CIMException.CIM_ERR_NOT_FOUND); } if (fEnableModifications) { paths.removeElementAt (index); instances.removeElementAt (index); paths.sort (); instances.sort (); } else { throw new CIMException (CIMException.CIM_ERR_INVALID_PARAMETER); } } else { throw new CIMException (CIMException.CIM_ERR_INVALID_CLASS); } } public Vector enumerateInstanceNames (OperationContext oc, CIMObjectPath cop, boolean deepInheritance, CIMClass cimClass) throws CIMException { if (DEBUG) { System.err.println (providerName + "::enumerateInstanceNames: oc = " + oc); System.err.println (providerName + "::enumerateInstanceNames: cop = " + cop); System.err.println (providerName + "::enumerateInstanceNames: deepInheritance = " + deepInheritance); System.err.println (providerName + "::enumerateInstanceNames: cimClass = " + cimClass); } // Esure that the namespace is valid if (!cop.getNameSpace ().equalsIgnoreCase (namespace)) { throw new CIMException (CIMException.CIM_ERR_INVALID_NAMESPACE); } // Ensure that the class exists in the specified namespace if (cop.getObjectName ().equalsIgnoreCase (instanceClassname)) { return paths; } else {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -