Home | History | Annotate | Download | only in srm
      1 /*
      2  * CDDL HEADER START
      3  *
      4  * The contents of this file are subject to the terms of the
      5  * Common Development and Distribution License (the "License").
      6  * You may not use this file except in compliance with the License.
      7  *
      8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
      9  * or http://www.opensolaris.org/os/licensing.
     10  * See the License for the specific language governing permissions
     11  * and limitations under the License.
     12  *
     13  * When distributing Covered Code, include this CDDL HEADER in each
     14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
     15  * If applicable, add the following below this CDDL HEADER, with the
     16  * fields enclosed by brackets "[]" replaced with your own identifying
     17  * information: Portions Copyright [yyyy] [name of copyright owner]
     18  *
     19  * CDDL HEADER END
     20  */
     21 /*
     22  * Copyright (c) 2001 by Sun Microsystems, Inc.
     23  * All rights reserved.
     24  *
     25  * Solaris_ActiveProject.java
     26  */
     27 
     28 
     29 package com.sun.wbem.solarisprovider.srm;
     30 
     31 import javax.wbem.cim.*;
     32 import javax.wbem.client.*;
     33 import javax.wbem.provider.*;
     34 import javax.wbem.query.*;
     35 
     36 import com.sun.wbem.solarisprovider.common.ProviderUtility;
     37 import java.util.Enumeration;
     38 import java.util.Iterator;
     39 import java.util.Vector;
     40 
     41 
     42 /**
     43  * Provider of the Solaris_ActiveProject class. This class represents
     44  * a Project that is actively running on an OperatingSystem.
     45  * @author Sun Microsystems
     46  */
     47 public class Solaris_ActiveProject extends SRMProvider
     48 	implements Authorizable, Solaris_ActiveProjectProperties {
     49 
     50     /**
     51      * The name of the provider implemented by this class.
     52      */
     53     protected String providerName = SOLARIS_ACTIVEPROJECT;
     54 
     55     /**
     56      * Get the name of the provider implemented by this class.
     57      * @returns String provider name
     58      */
     59     protected String getProviderName() {
     60 	return providerName;
     61     }
     62 
     63 
     64     /**
     65      * Returns a specific CIMInstance.
     66      * @param op - the name of the instance to be retrieved. This must include
     67      * all of the keys and values for the instance.
     68      * @param localOnly - if true, only the local properties of the class are
     69      * returned, otherwise all properties are required
     70      * @param includeQualifiers - if true, the qualifiers are returned as part
     71      * of of the returned instancei, otherwise no qualifiers will be returned
     72      * @param includeClassOrigin - if true, the class origin of each property
     73      * will be returned
     74      * @param String[] - if null, all properties are returned, otherwise only
     75      * the properties specified will be returned. Any duplicate properties will
     76      * be ignored.
     77      * @param cc - the class reference
     78      *
     79      * @return	CIMInstance the retrieved instance.
     80      * @exception CIMException - the method getInstance throws a CIMException
     81      * if the CIMObjectPath is incorrect or does not exist.
     82      */
     83     public synchronized CIMInstance getInstance(CIMObjectPath op,
     84 				   boolean localOnly,
     85 				   boolean includeQualifiers,
     86 				   boolean includeClassOrigin,
     87 				   String[] propList,
     88 				   CIMClass cc)
     89 	    throws CIMException {
     90 
     91 
     92         String projName = null;
     93 	CIMProperty cp;
     94 	CIMInstance ci = null;
     95 	DataModel   dm = null;
     96 	ActiveProjectModel apm;
     97 
     98 	SRMDebug.trace(SRMDebug.METHOD_CALL, op.toString());
     99         try {
    100 	    Enumeration e = op.getKeys().elements();
    101             while (e.hasMoreElements()) {
    102                 cp = (CIMProperty) e.nextElement();
    103                 if (cp.getName().equalsIgnoreCase(PROJECTNAME)) {
    104 		    projName =
    105 		      (String) (((CIMValue)(cp.getValue())).getValue());
    106                 }
    107             }
    108 	    dm = resourceMonitor.getDataModel(false);
    109 	    if ((apm = dm.getProject(projName)) == null) {
    110 	    	resourceMonitor.releaseDataModel(dm);
    111 	    	throw notFoundEx;
    112 	    }
    113 	    ci = apm.getCIMInstance(cc);
    114 	    dm = resourceMonitor.releaseDataModel(dm);
    115         } catch (Exception e) {
    116 	    dm = resourceMonitor.releaseDataModel(dm);
    117 	    String msg = writeLog(LOGERROR, "SRM_1001");
    118 	    writeLog(LOGERROR, e);
    119 	    msg += " (" + e.getClass().toString() + ")";
    120 	    SRMDebug.trace1(providerName, e);
    121             throw new CIMException(CIMException.CIM_ERR_FAILED, msg);
    122 	}
    123     	SRMDebug.trace(SRMDebug.METHOD_RETV, ci.toString());
    124 	return ci;
    125 
    126     } // end getInstance
    127 
    128 
    129     /**
    130      * Returns all instances of Solaris_ActiveProject.
    131      * @param op - the object path specifies the class to be enumerated
    132      * localOnly - if true, only the local properties of the class are returned,
    133      * otherwise all properties are required
    134      * @param includeQualifiers - if true, the qualifiers are returned as part
    135      * of of the returned instancei, otherwise no qualifiers will be returned
    136      * @param includeClassOrigin - if true, the class origin of each property
    137      * will be returned
    138      * @param String[] - if null, all properties are returned, otherwise only
    139      * the properties specified will be
    140      * returned. Any duplicate properties will be ignored.
    141      * @param cc - the class reference
    142      * @return An array of CIMInstance
    143      * @exception CIMException - if the CIMObjectPath is incorrect or does not
    144      * exist.
    145      */
    146     public synchronized CIMInstance[] enumerateInstances(CIMObjectPath op,
    147 					    boolean localOnly,
    148 					    boolean includeQualifiers,
    149 					    boolean includeClassOrigin,
    150 					    String[] propList,
    151 					    CIMClass cc)
    152 	    throws CIMException {
    153     	DataModel   dm = null;
    154 
    155 	SRMDebug.trace(SRMDebug.METHOD_CALL, op.toString());
    156         try {
    157             Vector  projInstances = new Vector();
    158 	    CIMInstance ci;
    159     	    dm = resourceMonitor.getDataModel(false);
    160 	    Iterator i = dm.getProjectIterator();
    161 
    162 	    while (i.hasNext()) {
    163 		ci = ((ActiveProjectModel) i.next()).getCIMInstance(cc);
    164 		projInstances.addElement(ci);
    165             }
    166 	    dm = resourceMonitor.releaseDataModel(dm);
    167 	    CIMInstance[] ciArray = new CIMInstance[projInstances.size()];
    168 	    projInstances.toArray(ciArray);
    169 	    SRMDebug.trace(SRMDebug.METHOD_RETV, "instance[0]: " +
    170 	    	    	ciArray[0].toString());
    171             return ciArray;
    172         } catch (Exception e) {
    173 	    dm = resourceMonitor.releaseDataModel(dm);
    174 	    String msg = writeLog(LOGERROR, "SRM_1002");
    175 	    writeLog(LOGERROR, e);
    176 	    msg += " (" + e.getClass().toString() + ")";
    177 	    SRMDebug.trace1(providerName, e);
    178             throw new CIMException(CIMException.CIM_ERR_FAILED, msg);
    179 	}
    180 
    181     } // end enumerateInstances
    182 
    183 
    184     /**
    185      * Returns the names of all Solaris_ActiveProject instances,
    186      *
    187      * @param op - the class name to enumerate the instances
    188      * @param cc - the class reference passed to the provider
    189      * @return an array of CIMObjectPath containing names of the enumerated
    190      * instances.
    191      * @exception CIMException - if the classname is null or does not exist.
    192      */
    193     public synchronized CIMObjectPath[] enumerateInstanceNames(CIMObjectPath op,
    194 						  CIMClass cc)
    195 	    throws CIMException {
    196 
    197 	DataModel   dm = null;
    198 
    199 	SRMDebug.trace(SRMDebug.METHOD_CALL, op.toString());
    200         try {
    201             ActiveProjectModel apm;
    202             Vector projInstances = new Vector();
    203 	    CIMObjectPath cop;
    204     	    dm = resourceMonitor.getDataModel(false);
    205 	    Iterator i = dm.getProjectIterator();
    206 	    while (i.hasNext()) {
    207                 apm = (ActiveProjectModel) i.next();
    208                 cop = new CIMObjectPath(op.getObjectName(), op.getNameSpace());
    209                 cop.addKey(PROJECTNAME, new CIMValue(apm.name));
    210                 projInstances.addElement(cop);
    211             }
    212 	    dm = resourceMonitor.releaseDataModel(dm);
    213 	    CIMObjectPath[] copArray = new CIMObjectPath[projInstances.size()];
    214 	    projInstances.toArray(copArray);
    215 	    SRMDebug.trace(SRMDebug.METHOD_RETV, "instanceName[0]: "
    216 	    	    + copArray[0].toString());
    217             return copArray;
    218         } catch (Exception e) {
    219 	    dm = resourceMonitor.releaseDataModel(dm);
    220 	    String msg = writeLog(LOGERROR, "SRM_1002");
    221 	    writeLog(LOGERROR, e);
    222 	    msg += " (" + e.getClass().toString() + ")";
    223 	    SRMDebug.trace1(providerName, e);
    224             throw new CIMException(CIMException.CIM_ERR_FAILED, msg);
    225 	}
    226 
    227     } // end enumerateInstanceNames
    228 
    229     protected CIMValue getBulkData(Vector outParams) throws CIMException {
    230 	DataModel   dm = null;
    231 
    232 	try {
    233     	    dm = resourceMonitor.getDataModel(false);
    234 	    Iterator i = dm.getProjectIterator();
    235             // Fill the array; each obj takes the bulk data for one user.
    236             Vector  vOutParam = new Vector();
    237 	    while (i.hasNext()) {
    238     	    	vOutParam.addElement(((ActiveProjectModel) i.next()).
    239 		    	toBulkData());
    240 	    }
    241             // rem:  we can only return CIMValues in our outParams
    242             CIMDataType dtype = new CIMDataType(CIMDataType.STRING_ARRAY);
    243             CIMValue outVal = new CIMValue(vOutParam, dtype);
    244 	    outParams.addElement(outVal);
    245 
    246 	    dm = resourceMonitor.releaseDataModel(dm);
    247 
    248 	} catch (Exception e) {
    249 	    dm = resourceMonitor.releaseDataModel(dm);
    250 	    String msg = writeLog(LOGERROR, "SRM_1002");
    251 	    writeLog(LOGERROR, e);
    252 	    msg += " (" + e.getClass().toString() + ")";
    253 	    SRMDebug.trace1(providerName, e);
    254 	    throw new CIMException(CIMException.CIM_ERR_FAILED, msg);
    255     	}
    256 
    257         CIMValue rv = new CIMValue(new Integer(0));
    258 	return (rv);
    259     } // end getBulkData
    260 
    261 } // end class Solaris_ActiveProject
    262