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, Version 1.0 only 6 * (the "License"). You may not use this file except in compliance 7 * with the License. 8 * 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 * or http://www.opensolaris.org/os/licensing. 11 * See the License for the specific language governing permissions 12 * and limitations under the License. 13 * 14 * When distributing Covered Code, include this CDDL HEADER in each 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 * If applicable, add the following below this CDDL HEADER, with the 17 * fields enclosed by brackets "[]" replaced with your own identifying 18 * information: Portions Copyright [yyyy] [name of copyright owner] 19 * 20 * CDDL HEADER END 21 */ 22 /* 23 * Copyright 2003 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 * 26 *ident "%Z%%M% %I% %E% SMI" 27 * 28 */ 29 30 package com.sun.solaris.service.pools; 31 32 /** 33 * The <code>Component</code> class represents a configuration 34 * resource component. 35 */ 36 public class Component extends Element 37 { 38 /** 39 * The type of the component. 40 */ 41 private final String type; 42 43 /** 44 * The system id of the component. 45 */ 46 private final long sys_id; 47 48 /** 49 * The key of the component. 50 */ 51 private final String key; 52 53 /** 54 * Constructor 55 * 56 * @param conf The configuration to which this component belongs 57 * @param comp The pointer to the native component 58 * @throws PoolsException If accessing the proxy fails. 59 */ Component(Configuration conf, long comp)60 Component(Configuration conf, long comp) throws PoolsException 61 { 62 _conf = conf; 63 Value val = getProperty("type", comp); 64 type = val.getString(); 65 val.close(); 66 val = getProperty(type + ".sys_id", comp); 67 sys_id = val.getLong(); 68 val.close(); 69 key = type + "." + sys_id; 70 } 71 72 /** 73 * Return the pointer to the component represented by this object. 74 * 75 * @return conf the pointer to the component represented by this object 76 * @throws PoolsException If the component cannot be located. 77 */ getComponent()78 long getComponent() throws PoolsException 79 { 80 return (_conf.checkComponent(type, sys_id)); 81 } 82 83 /** 84 * Returns a descriptive string which describes the component. 85 * 86 * @param deep Whether the information should contain information about 87 * all contained elements. 88 * @throws PoolsException If the component cannot be located. 89 * @return a descriptive string which describes the component. 90 */ getInformation(int deep)91 public String getInformation(int deep) throws PoolsException 92 { 93 return (PoolInternal.pool_component_info(_conf.getConf(), 94 getComponent(), deep)); 95 } 96 97 /** 98 * Returns a string representation of this component. 99 * 100 * @return a string representation of this component. 101 */ toString()102 public String toString() 103 { 104 StringBuffer buf = new StringBuffer(); 105 106 buf.append(type); 107 buf.append(" "); 108 buf.append(sys_id); 109 return (buf.toString()); 110 } 111 112 /** 113 * Indicates whether some other Component is "equal to this one. 114 * @param o the reference object with which to compare. 115 * @return <code>true</code> if this object is the same as the 116 * o argument; <code>false</code> otherwise. 117 * @see #hashCode() 118 */ equals(Object o)119 public boolean equals(Object o) 120 { 121 if (o == this) 122 return (true); 123 if (!(o instanceof Component)) 124 return (false); 125 Component other = (Component) o; 126 if (type.compareTo(other.getType()) != 0 || 127 sys_id != other.getSysId()) 128 return (false); 129 return (true); 130 } 131 132 /** 133 * Returns a hash code value for the object. This method is 134 * supported for the benefit of hashtables such as those provided by 135 * <code>java.util.Hashtable</code>. 136 * 137 * @return a hash code value for this object. 138 * @see #equals(java.lang.Object) 139 * @see java.util.Hashtable 140 */ hashCode()141 public int hashCode() 142 { 143 return (type.hashCode() + (int) sys_id); 144 } 145 146 /** 147 * Return the pointer to this component as an element. 148 * 149 * @return The pointer to the native component which this object wraps. 150 * @throws PoolsExecption If there is an error converting the native 151 * component pointer to a native elem pointer. 152 */ getElem()153 protected long getElem() throws PoolsException 154 { 155 long elem; 156 157 if ((elem = PoolInternal.pool_component_to_elem(_conf.getConf(), 158 getComponent())) == 0) 159 throw new PoolsException(); 160 return (elem); 161 } 162 163 /** 164 * Return the type of the component 165 */ getType()166 String getType() 167 { 168 return (type); 169 } 170 171 /** 172 * Return the system id of the component. 173 */ getSysId()174 long getSysId() 175 { 176 return (sys_id); 177 } 178 179 /** 180 * Return the key of the component. 181 */ getKey()182 String getKey() 183 { 184 return (key); 185 } 186 } 187