⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 commoninstanceprovider.java

📁 Pegasus is an open-source implementationof the DMTF CIM and WBEM standards. It is designed to be por
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
//%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 Instances;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 testElementClassname,                                     String propertyTypesClassname)   {      this.providerName           = providerName;      this.namespace              = namespace;      this.testElementClassname   = testElementClassname;      this.propertyTypesClassname = propertyTypesClassname;   }   public void initialize (CIMOMHandle handle)      throws CIMException   {      if (DEBUG)      {         System.err.println (providerName + "::initialize: handle = " + handle);      }      this.handle = handle;      CIMInstance   instance1 = new CIMInstance (propertyTypesClassname);      CIMObjectPath cop1      = new CIMObjectPath (propertyTypesClassname,                                                   namespace);      instance1.setProperty ("CreationClassName",                             new CIMValue (new String (propertyTypesClassname)));      cop1.addKey ("CreationClassName",                   new CIMValue (new String (propertyTypesClassname)));      instance1.setProperty ("InstanceId",                             new CIMValue (new UnsignedInt64 ("1")));      cop1.addKey ("InstanceId",                   new CIMValue (new UnsignedInt64 ("1")));      instance1.setProperty ("PropertyString",                             new CIMValue (new String (providerName + "_Instance1")));      instance1.setProperty ("PropertyUint8",                             new CIMValue (new UnsignedInt8 ((short)120)));      instance1.setProperty ("PropertyUint16",                             new CIMValue (new UnsignedInt16 ((int)1600)));      instance1.setProperty ("PropertyUint32",                             new CIMValue (new UnsignedInt32 ((long)3200)));      instance1.setProperty ("PropertyUint64",                             new CIMValue (new UnsignedInt64 ("6400")));      instance1.setProperty ("PropertySint8",                             new CIMValue (new Byte ((byte)-119)));      instance1.setProperty ("PropertySint16",                             new CIMValue (new Short ((short)-1600)));      instance1.setProperty ("PropertySint32",                             new CIMValue (new Integer (-3200)));      instance1.setProperty ("PropertySint64",                             new CIMValue (new Long (-6400)));      instance1.setProperty ("PropertyBoolean",                             new CIMValue (new Boolean (true)));      instance1.setProperty ("PropertyReal32",                             new CIMValue (new Float (1.12345670123)));      instance1.setProperty ("PropertyReal64",                             new CIMValue (new Double (1.12345678906543210123)));      instance1.setProperty ("PropertyDatetime",                             new CIMValue (new CIMDateTime ("20010515104354.000000:000")));      instancesPropertyTypes.addElement (instance1);      pathsPropertyTypes.addElement (cop1);      CIMInstance   instance2 = new CIMInstance (propertyTypesClassname);      CIMObjectPath cop2      = new CIMObjectPath (propertyTypesClassname,                                                   namespace);      instance2.setProperty ("CreationClassName",                             new CIMValue (new String (propertyTypesClassname)));      cop2.addKey ("CreationClassName",                   new CIMValue (new String (propertyTypesClassname)));      instance2.setProperty ("InstanceId",                             new CIMValue (new UnsignedInt64 ("2")));      cop2.addKey ("InstanceId",                   new CIMValue (new UnsignedInt64 ("2")));      instance2.setProperty ("PropertyString",                             new CIMValue (new String (providerName + "_Instance2")));      instance2.setProperty ("PropertyUint8",                             new CIMValue (new UnsignedInt8 ((short)122)));      instance2.setProperty ("PropertyUint16",                             new CIMValue (new UnsignedInt16 ((int)1602)));      instance2.setProperty ("PropertyUint32",                             new CIMValue (new UnsignedInt32 ((long)3202)));      instance2.setProperty ("PropertyUint64",                             new CIMValue (new UnsignedInt64 ("6402")));      instance2.setProperty ("PropertySint8",                             new CIMValue (new Byte ((byte)-117)));      instance2.setProperty ("PropertySint16",                             new CIMValue (new Short ((short)-1602)));      instance2.setProperty ("PropertySint32",                             new CIMValue (new Integer (-3202)));      instance2.setProperty ("PropertySint64",                             new CIMValue (new Long (-6402)));      instance2.setProperty ("PropertyBoolean",                             new CIMValue (new Boolean (false)));      instance2.setProperty ("PropertyReal32",                             new CIMValue (new Float (2.12345670123)));      instance2.setProperty ("PropertyReal64",                             new CIMValue (new Double (2.12345678906543210123)));      instance2.setProperty ("PropertyDatetime",                             new CIMValue (new CIMDateTime ("20010515104354.000000:000")));      instancesPropertyTypes.addElement (instance2);      pathsPropertyTypes.addElement (cop2);      pathsPropertyTypes.sort ();      instancesPropertyTypes.sort ();   }   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);      }      // Ensure 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           = handle.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 (testElementClassname))      {         // Ensure that the instance contains the required keys         cop = validateTestElementInstance (cimInstance, false);         if (cop == null)         {            throw new CIMException (CIMException.CIM_ERR_INVALID_PARAMETER);         }         // Ensure that the property values are valid         testTestElementInstance (cimInstance);         // Determine if a property exists in the class         if (cimInstance.getProperty ("PropertyUint8") == null)         {            throw new CIMException (CIMException.CIM_ERR_INVALID_PARAMETER);         }         // Ensure that the requested object does not exist         if (findCOPInTestElements (cop) >= 0)         {            throw new CIMException (CIMException.CIM_ERR_ALREADY_EXISTS);         }         if (fEnableModifications)         {            pathsTestElements.addElement (cop);            instancesTestElements.addElement (cimInstance);            pathsTestElements.sort ();            instancesTestElements.sort ();            return cop;         }         else         {            throw new CIMException (CIMException.CIM_ERR_INVALID_PARAMETER);         }      }      else if (cop.getObjectName ().equalsIgnoreCase (propertyTypesClassname))      {         // 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);         // Determine if a property exists in the class         if (cimInstance.getProperty ("PropertyUint8") == null)         {            throw new CIMException (CIMException.CIM_ERR_INVALID_PARAMETER);         }         // Ensure that the requested object does not exist         if (findCOPInPropertyTypesNew (cop) >= 0)         {            throw new CIMException (CIMException.CIM_ERR_ALREADY_EXISTS);         }         if (fEnableModifications)         {            pathsPropertyTypes.addElement (cop);            instancesPropertyTypes.addElement (cimInstance);            pathsPropertyTypes.sort ();            instancesPropertyTypes.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);      }      // Ensure 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 (testElementClassname))      {         // Ensure that the keys are valid         if (!validateTestElementPath (cop))         {            throw new CIMException (CIMException.CIM_ERR_INVALID_PARAMETER);         }         // Ensure that the request object exists         int index = findCOPInTestElements (cop);         if (index < 0)         {            throw new CIMException (CIMException.CIM_ERR_NOT_FOUND);         }         return (CIMInstance)instancesTestElements.elementAt (index);      }      else if (cop.getObjectName ().equalsIgnoreCase (propertyTypesClassname))

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -