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_ActiveUser.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_ActiveUser class. This class represents
     44  * a ActiveUser that is actively running on an OperatingSystem.
     45  * @author Sun Microsystems
     46  */
     47 public class Solaris_ActiveUser extends SRMProvider
     48 	implements Authorizable, Solaris_ActiveUserProperties {
     49 
     50     /**
     51      * The name of the provider implemented by this class.
     52      */
     53     protected String providerName = SOLARIS_ACTIVEUSER;
     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 	String userID = null;
     92 	CIMProperty cp;
     93 	CIMInstance ci;
     94 	DataModel   dm = null;
     95 	ActiveUserModel aum;
     96 
     97 	SRMDebug.trace(SRMDebug.METHOD_CALL, op.toString());
     98 	try {
     99 	    Enumeration e = op.getKeys().elements();
    100 	    while (e.hasMoreElements()) {
    101 		cp = (CIMProperty) e.nextElement();
    102 		if (cp.getName().equalsIgnoreCase(USERID)) {
    103 		    userID = (String) (((CIMValue) (cp.getValue())).getValue());
    104 		}
    105 	    }
    106 
    107 	    dm = resourceMonitor.getDataModel(false);
    108 	    if ((aum = dm.getUser(userID)) == null) {
    109 	    	resourceMonitor.releaseDataModel(dm);
    110 	    	throw notFoundEx;
    111 	    }
    112 	    ci = aum.getCIMInstance(cc);
    113 	    dm = resourceMonitor.releaseDataModel(dm);
    114 	} catch (Exception e) {
    115 	    dm = resourceMonitor.releaseDataModel(dm);
    116 	    String msg = writeLog(LOGERROR, "SRM_1001");
    117 	    writeLog(LOGERROR, e);
    118 	    SRMDebug.trace1(providerName, e);
    119     	    throw new CIMException(CIMException.CIM_ERR_FAILED, msg);
    120     	}
    121     	SRMDebug.trace(SRMDebug.METHOD_RETV, ci.toString());
    122 	return ci;
    123 
    124     } // end getInstance
    125 
    126 
    127     /**
    128      * Returns all instances of Solaris_ActiveUser.
    129      * @param op - the object path specifies the class to be enumerated
    130      * localOnly - if true, only the local properties of the class are returned,
    131      * otherwise all properties are required
    132      * @param includeQualifiers - if true, the qualifiers are returned as part
    133      * of of the returned instancei, otherwise no qualifiers will be returned
    134      * @param includeClassOrigin - if true, the class origin of each property
    135      * will be returned
    136      * @param String[] - if null, all properties are returned, otherwise only
    137      * the properties specified will be
    138      * returned. Any duplicate properties will be ignored.
    139      * @param cc - the class reference
    140      * @return An array of CIMInstance
    141      * @exception CIMException - if the CIMObjectPath is incorrect or does not
    142      * exist.
    143      */
    144     public synchronized CIMInstance[] enumerateInstances(CIMObjectPath op,
    145 					    boolean localOnly,
    146 					    boolean includeQualifiers,
    147 					    boolean includeClassOrigin,
    148 					    String[] propList,
    149 					    CIMClass cc)
    150 	throws CIMException {
    151     	DataModel   dm = null;
    152 	CIMInstance ci;
    153 
    154 	SRMDebug.trace(SRMDebug.METHOD_CALL, op.toString());
    155 	try {
    156 	    Vector  userInstances = new Vector();
    157 	    dm = resourceMonitor.getDataModel(false);
    158 	    Iterator i = dm.getUserIterator();
    159 	    while (i.hasNext()) {
    160 		ci = ((ActiveUserModel) i.next()).getCIMInstance(cc);
    161 		userInstances.addElement(ci);
    162 	    }
    163     	    dm = resourceMonitor.releaseDataModel(dm);
    164 	    CIMInstance[] ciArray = new CIMInstance[userInstances.size()];
    165 	    userInstances.toArray(ciArray);
    166 	    SRMDebug.trace(SRMDebug.METHOD_RETV, "instance[0]: " +
    167 	    	    	ciArray[0].toString());
    168             return ciArray;
    169 	} catch (Exception e) {
    170     	    dm = resourceMonitor.releaseDataModel(dm);
    171 	    String msg = writeLog(LOGERROR, "SRM_1002");
    172 	    msg += " (" + e.getClass().toString() + ")";
    173 	    writeLog(LOGERROR, e);
    174 	    SRMDebug.trace1(providerName, e);
    175 	    throw new CIMException(CIMException.CIM_ERR_FAILED, msg);
    176     	}
    177 
    178     } // end enumerateInstances
    179 
    180 
    181     /**
    182      * Returns the names of all Solaris_ActiveUser instances.
    183      *
    184      * @param op - the class name to enumerate the instances
    185      * @param cc - the class reference passed to the provider
    186      * @return an array of CIMObjectPath containing names of the enumerated
    187      * instances.
    188      * @exception CIMException - if the classname is null or does not exist.
    189      */
    190     public synchronized CIMObjectPath[] enumerateInstanceNames(CIMObjectPath op,
    191 						  CIMClass cc)
    192 	throws CIMException {
    193     	DataModel dm = null;
    194 
    195 	SRMDebug.trace(SRMDebug.METHOD_CALL, op.toString());
    196 	try {
    197 	    ActiveUserModel aum;
    198 	    Vector userInstances = new Vector();
    199 	    CIMObjectPath cop;
    200 
    201     	    dm = resourceMonitor.getDataModel(false);
    202 	    Iterator i = dm.getUserIterator();
    203 	    while (i.hasNext()) {
    204 		aum = (ActiveUserModel) i.next();
    205 		cop = new CIMObjectPath(op.getObjectName(), op.getNameSpace());
    206 		cop.addKey(USERID, new CIMValue(aum.name));
    207 		userInstances.addElement(cop);
    208 	    }
    209 	    dm = resourceMonitor.releaseDataModel(dm);
    210 	    CIMObjectPath[] copArray = new CIMObjectPath[userInstances.size()];
    211 	    userInstances.toArray(copArray);
    212 	    SRMDebug.trace(SRMDebug.METHOD_RETV, "instanceName[0]: "
    213 	    	    + copArray[0].toString());
    214             return copArray;
    215 	} catch (Exception e) {
    216 	    dm = resourceMonitor.releaseDataModel(dm);
    217 	    String msg = writeLog(LOGERROR, "SRM_1003");
    218 	    writeLog(LOGERROR, e);
    219 	    SRMDebug.trace1(providerName, e);
    220 	    throw new CIMException(CIMException.CIM_ERR_FAILED, msg);
    221     	}
    222 
    223     } // end enumerateInstanceNames
    224 
    225     protected CIMValue getBulkData(Vector outParams) throws CIMException {
    226 	DataModel   dm = null;
    227 
    228 	try {
    229     	    dm = resourceMonitor.getDataModel(false);
    230 	    Iterator i = dm.getUserIterator();
    231             // Fill the array; each obj takes the bulk data for one user.
    232             Vector  vOutParam = new Vector();
    233 	    while (i.hasNext()) {
    234     	    	vOutParam.addElement(((ActiveUserModel) i.next()).toBulkData());
    235 	    }
    236             // rem:  we can only return CIMValues in our outParams
    237             CIMDataType dtype = new CIMDataType(CIMDataType.STRING_ARRAY);
    238             CIMValue outVal = new CIMValue(vOutParam, dtype);
    239 	    outParams.addElement(outVal);
    240 
    241 	    dm = resourceMonitor.releaseDataModel(dm);
    242 
    243 	} catch (Exception e) {
    244 	    dm = resourceMonitor.releaseDataModel(dm);
    245 	    String msg = writeLog(LOGERROR, "SRM_1002");
    246 	    writeLog(LOGERROR, e);
    247 	    msg += " (" + e.getClass().toString() + ")";
    248 	    SRMDebug.trace1(providerName, e);
    249 	    throw new CIMException(CIMException.CIM_ERR_FAILED, msg);
    250     	}
    251 
    252         CIMValue rv = new CIMValue(new Integer(0));
    253 	return (rv);
    254     } // end getBulkData
    255 
    256 } // end class Solaris_ActiveUser
    257