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

📄 jmpipropertyprovider.java

📁 Pegasus is an open-source implementationof the DMTF CIM and WBEM standards. It is designed to be por
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
//%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:////%/////////////////////////////////////////////////////////////////////////////package Properties;import java.util.Vector;import java.util.HashMap;import java.util.Iterator;import org.pegasus.jmpi.CIMClass;import org.pegasus.jmpi.CIMDataType;import org.pegasus.jmpi.CIMException;import org.pegasus.jmpi.CIMInstance;import org.pegasus.jmpi.CIMObjectPath;import org.pegasus.jmpi.CIMOMHandle;import org.pegasus.jmpi.CIMProperty;import org.pegasus.jmpi.CIMValue;import org.pegasus.jmpi.InstanceProvider;import org.pegasus.jmpi.PropertyProvider;import org.pegasus.jmpi.UnsignedInt8;import org.pegasus.jmpi.UnsignedInt16;import org.pegasus.jmpi.UnsignedInt32;import org.pegasus.jmpi.UnsignedInt64;public class JMPIPropertyProvider             implements InstanceProvider,                        PropertyProvider{   private CIMOMHandle         ch                      = null;   private SortableVector      paths                   = new SortableVector (new CIMObjectPathComparer ());   private SortableVector      instances               = new SortableVector (new CIMInstanceComparer ());   private boolean             fEnableModifications    = true;   private final boolean       DEBUG                   = true;   public class ConvertibleVector extends Vector   {      public Object buildArray (Class type)      {         Object copy = java.lang.reflect.Array.newInstance (type, elementCount);         System.arraycopy (elementData, 0, copy, 0, elementCount);         return copy;      }      // Assumes there's at least one element and it's not null!      public Object buildArray ()      {         if (elementCount > 0 && elementData[0] != null)         {            return buildArray (elementData[0].getClass ());         }         else         {            throw new IllegalArgumentException ("cannot convert to array");         }      }   }   private interface Compare   {      abstract boolean lessThan        (Object lhs, Object rhs);      abstract boolean lessThanOrEqual (Object lhs, Object rhs);   }   private class SortableVector                 extends Vector   {      private Compare compare;      public SortableVector (Compare compare)      {         this.compare = compare;      }      public void sort ()      {         quickSort (0, size() - 1);      }      private void quickSort (int left, int right)      {         if (right > left)         {            Object o1 = elementAt (right);            int    i  = left - 1;            int    j  = right;            while (true)            {               while (compare.lessThan (elementAt (++i), o1))                  ;               while (j > 0)                  if(compare.lessThanOrEqual (elementAt (--j), o1))                     break;               if (i >= j)                  break;               swap (i, j);            }            swap (i , right);            quickSort (left, i - 1);            quickSort (i + 1, right);         }      }      private void swap (int loc1, int loc2)      {         Object tmp = elementAt(loc1);         setElementAt (elementAt (loc2), loc1);         setElementAt (tmp, loc2);      }   }   private class CIMInstanceComparer                 implements Compare   {      private int getInstanceId (Object o)      {         try         {            CIMInstance       ci = (CIMInstance)o;            CIMProperty       cp = ci.getProperty ("InstanceId");            UnsignedInt64     id = (UnsignedInt64)cp.getValue ().getValue ();            return id.intValue ();         }         catch (Exception e)         {            return 0;         }      }      public boolean lessThan (Object lhs, Object rhs)      {         return getInstanceId (lhs) < getInstanceId (rhs);      }      public boolean lessThanOrEqual (Object lhs, Object rhs)      {         return getInstanceId (lhs) <= getInstanceId (rhs);      }   }   private class CIMObjectPathComparer                 implements Compare   {      private int getInstanceId (Object o)      {         try         {            CIMObjectPath     cop   = (CIMObjectPath)o;            String            value = cop.getKeyValue ("InstanceId");            UnsignedInt64     id    = new UnsignedInt64 (value);            return id.intValue ();         }         catch (Exception e)         {            return 0;         }      }      public boolean lessThan (Object lhs, Object rhs)      {         return getInstanceId (lhs) < getInstanceId (rhs);      }      public boolean lessThanOrEqual (Object lhs, Object rhs)      {         return getInstanceId (lhs) <= getInstanceId (rhs);      }   }   public void initialize (CIMOMHandle ch)      throws CIMException   {      if (DEBUG)      {         System.err.println ("JMPIPropertyProvider::initialize: ch = " + ch);      }      this.ch = ch;      CIMInstance instance1 = new CIMInstance (CLASS_PROPERTYTYPES);      instance1.setProperty ("CreationClassName", new CIMValue (new String (CLASS_PROPERTYTYPES)));      instance1.setProperty ("InstanceId",        new CIMValue (new UnsignedInt64 ("1")));      instance1.setProperty ("PropertyString",    new CIMValue (new String ("A first property string.")));      instances.addElement (instance1);      CIMInstance instance2 = new CIMInstance (CLASS_PROPERTYTYPES);      instance2.setProperty ("CreationClassName", new CIMValue (new String (CLASS_PROPERTYTYPES)));      instance2.setProperty ("InstanceId",        new CIMValue (new UnsignedInt64 ("2")));      instance2.setProperty ("PropertyString",    new CIMValue (new String ("The second property string.")));      instances.addElement (instance2);      CIMObjectPath cop1 = new CIMObjectPath (CLASS_PROPERTYTYPES, NAMESPACE);      cop1.addKey ("CreationClassName", new CIMValue (new String (CLASS_PROPERTYTYPES)));      cop1.addKey ("InstanceId",        new CIMValue (new UnsignedInt64 ("1")));      cop1.addKey ("PropertyString",    new CIMValue (new String ("A first property string.")));      paths.addElement (cop1);      CIMObjectPath cop2 = new CIMObjectPath (CLASS_PROPERTYTYPES, NAMESPACE);      cop2.addKey ("CreationClassName", new CIMValue (new String (CLASS_PROPERTYTYPES)));      cop2.addKey ("InstanceId",        new CIMValue (new UnsignedInt64 ("2")));      cop2.addKey ("PropertyString",    new CIMValue (new String ("The second property string.")));      paths.addElement (cop2);   }   public void cleanup ()      throws CIMException   {      if (DEBUG)      {         System.err.println ("JMPIPropertyProvider::cleanup");      }   }   public CIMObjectPath createInstance (CIMObjectPath cop,                                        CIMInstance   cimInstance)      throws CIMException   {      if (DEBUG)      {         System.err.println ("JMPIPropertyProvider::createInstance: cop          = " + cop);         System.err.println ("JMPIPropertyProvider::createInstance: cimInstance  = " + cimInstance);      }      // ensure the Namespace is valid      if (!cop.getNameSpace ().equalsIgnoreCase (NAMESPACE))         throw new CIMException (CIMException.CIM_ERR_INVALID_NAMESPACE);      // ensure the class existing in the specified namespace      if (!cop.getObjectName ().equalsIgnoreCase (CLASS_PROPERTYTYPES))         throw new CIMException (CIMException.CIM_ERR_INVALID_CLASS);      // Ensure that the instance contains the required keys      cop = validateInstance (cimInstance, false);      if (cop == null)         throw new CIMException (CIMException.CIM_ERR_INVALID_PARAMETER);      // ensure the property values are valid      testPropertyTypesValue (cimInstance);      // ensure the requested object does not exist      if (findObjectPath (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);      }   }   public CIMInstance getInstance (CIMObjectPath cop,                                   CIMClass      cimClass,                                   boolean       localOnly)      throws CIMException   {      if (DEBUG)      {         System.err.println ("JMPIPropertyProvider::getInstance: cop       = " + cop);         System.err.println ("JMPIPropertyProvider::getInstance: cimClass  = " + cimClass);         System.err.println ("JMPIPropertyProvider::getInstance: localOnly = " + localOnly);      }      // ensure the Namespace is valid      if (!cop.getNameSpace ().equalsIgnoreCase (NAMESPACE))         throw new CIMException (CIMException.CIM_ERR_INVALID_NAMESPACE);      // ensure the class existing in the specified namespace      if (!cop.getObjectName ().equalsIgnoreCase (CLASS_PROPERTYTYPES))         throw new CIMException (CIMException.CIM_ERR_INVALID_CLASS);      // ensure the InstanceId key is valid      Vector keys = cop.getKeys ();      int    i;      for (i = 0;               i < keys.size ()           && !((CIMProperty)keys.elementAt (i)).getName ().equalsIgnoreCase ("InstanceId");           i++)      {      }      if (i == keys.size ())         throw new CIMException (CIMException.CIM_ERR_INVALID_PARAMETER);      // ensure the request object exists      int index = findObjectPath (cop);      if (index < 0)         throw new CIMException (CIMException.CIM_ERR_NOT_FOUND);      return (CIMInstance)instances.elementAt (index);   }   public void setInstance (CIMObjectPath cop,                            CIMInstance   cimInstance)      throws CIMException   {      if (DEBUG)      {         System.err.println ("JMPIPropertyProvider::setInstance: cop         = " + cop);         System.err.println ("JMPIPropertyProvider::setInstance: cimInstance = " + cimInstance);      }      // ensure the Namespace is valid      if (!cop.getNameSpace ().equalsIgnoreCase (NAMESPACE))         throw new CIMException (CIMException.CIM_ERR_INVALID_NAMESPACE);      // ensure the class existing in the specified namespace      if (!cop.getObjectName ().equalsIgnoreCase (CLASS_PROPERTYTYPES))         throw new CIMException (CIMException.CIM_ERR_INVALID_CLASS);      // ensure the property values are valid      testPropertyTypesValue (cimInstance);      // ensure the request object exists      int index = findObjectPath (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 ();

⌨️ 快捷键说明

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