001/* OpenMBeanOperationInfoSupport.java -- Open typed info about an operation. 002 Copyright (C) 2006, 2007 Free Software Foundation, Inc. 003 004This file is part of GNU Classpath. 005 006GNU Classpath is free software; you can redistribute it and/or modify 007it under the terms of the GNU General Public License as published by 008the Free Software Foundation; either version 2, or (at your option) 009any later version. 010 011GNU Classpath is distributed in the hope that it will be useful, but 012WITHOUT ANY WARRANTY; without even the implied warranty of 013MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 014General Public License for more details. 015 016You should have received a copy of the GNU General Public License 017along with GNU Classpath; see the file COPYING. If not, write to the 018Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 01902110-1301 USA. 020 021Linking this library statically or dynamically with other modules is 022making a combined work based on this library. Thus, the terms and 023conditions of the GNU General Public License cover the whole 024combination. 025 026As a special exception, the copyright holders of this library give you 027permission to link this library with independent modules to produce an 028executable, regardless of the license terms of these independent 029modules, and to copy and distribute the resulting executable under 030terms of your choice, provided that you also meet, for each linked 031independent module, the terms and conditions of the license of that 032module. An independent module is a module which is not derived from 033or based on this library. If you modify this library, you may extend 034this exception to your version of the library, but you are not 035obligated to do so. If you do not wish to do so, delete this 036exception statement from your version. */ 037 038package javax.management.openmbean; 039 040import java.util.Arrays; 041 042import javax.management.MBeanOperationInfo; 043import javax.management.MBeanParameterInfo; 044 045/** 046 * Describes a operation for an open management bean. 047 * 048 * @author Andrew John Hughes (gnu_andrew@member.fsf.org) 049 * @since 1.5 050 */ 051public class OpenMBeanOperationInfoSupport 052 extends MBeanOperationInfo 053 implements OpenMBeanOperationInfo 054{ 055 056 /** 057 * Compatible with JDK 1.5 058 */ 059 private static final long serialVersionUID = 4996859732565369366L; 060 061 /** 062 * The open type representing the return value. 063 */ 064 private OpenType<?> returnOpenType; 065 066 /** 067 * The hash code of this instance. 068 */ 069 private transient Integer hashCode; 070 071 /** 072 * The <code>toString()</code> result of this instance. 073 */ 074 private transient String string; 075 076 /** 077 * Constructs a @link{OpenMBeanOperationInfo} with the specified name, 078 * description, parameter information, open return type and impact. A 079 * <code>null</code> value for the parameter information is the same 080 * as passing in an empty array. A copy of the parameter array is 081 * taken, so later changes have no effect. The name and the 082 * description may not be equal to the empty string, and neither 083 * the name, description nor the open return type may be 084 * <code>null</code>. The value of <code>impact</code> must be 085 * one of the four valid values 086 * ({@link javax.management.MBeanOperationInfo#INFO}, 087 * {@link javax.management.MBeanOperationInfo#ACTION}, 088 * {@link javax.management.MBeanOperationInfo#ACTION_INFO} and 089 * {@link javax.management.MBeanOperationInfo#UNKNOWN}). 090 * 091 * 092 * @param name the name of the constructor. 093 * @param desc a description of the attribute. 094 * @param sig the signature of the method, as a series 095 * of {@link MBeanParameterInfo} objects, one for 096 * each parameter. 097 * @param type the open return type of the method. 098 * @param impact the impact of performing the operation. 099 * @throws IllegalArgumentException if the name, description or 100 * open return type is <code>null</code>, 101 * the name or description are equal to 102 * the empty string, or the impact factor 103 * is not one of the values enumerated 104 * above. 105 * @throws ArrayStoreException if the members of the signature array 106 * are not assignable to 107 * {@link javax.management.MBeanParameterInfo} 108 */ 109 public OpenMBeanOperationInfoSupport(String name, String desc, 110 OpenMBeanParameterInfo[] sig, 111 OpenType<?> type, int impact) 112 { 113 super(name, desc, (MBeanParameterInfo[]) sig, 114 type == null ? null : type.getClassName(), impact); 115 if (name == null) 116 throw new IllegalArgumentException("The name may not be null."); 117 if (desc == null) 118 throw new IllegalArgumentException("The description may not be null."); 119 if (type == null) 120 throw new IllegalArgumentException("The type may not be null."); 121 if (name.length() == 0) 122 throw new IllegalArgumentException("The name may not be the empty string."); 123 if (desc.length() == 0) 124 throw new IllegalArgumentException("The description may not be the " + 125 "empty string."); 126 if (impact != ACTION && impact != INFO && 127 impact != ACTION_INFO && impact != UNKNOWN) 128 throw new IllegalArgumentException("The impact factor is an invalid value."); 129 returnOpenType = type; 130 } 131 132 /** 133 * Compares this attribute with the supplied object. This returns 134 * true iff the object is an instance of {@link OpenMBeanOperationInfo} 135 * with an equal name, signature, open return type and impact. 136 * 137 * @param obj the object to compare. 138 * @return true if the object is a {@link OpenMBeanParameterInfo} 139 * instance, 140 * <code>name.equals(object.getName())</code>, 141 * <code>signature.equals(object.getSignature())</code>, 142 * <code>returnOpenType.equals(object.getReturnOpenType())</code>, 143 * and <code>impact == object.getImpact()</code>. 144 */ 145 public boolean equals(Object obj) 146 { 147 if (!(obj instanceof OpenMBeanOperationInfo)) 148 return false; 149 OpenMBeanOperationInfo o = (OpenMBeanOperationInfo) obj; 150 return getName().equals(o.getName()) && 151 getSignature().equals(o.getSignature()) && 152 returnOpenType.equals(o.getReturnOpenType()) && 153 getImpact() == o.getImpact(); 154 } 155 156 /** 157 * Returns the open type instance which represents the type of the 158 * return value. 159 * 160 * @return the open type of the return value. 161 */ 162 public OpenType<?> getReturnOpenType() 163 { 164 return returnOpenType; 165 } 166 167 /** 168 * <p> 169 * Returns the hashcode of the operation information as the sum of 170 * the hashcodes of the name, open return type, impact and signature 171 * (calculated by 172 * <code>java.util.Arrays.asList(signature).hashCode()</code>). 173 * </p> 174 * <p> 175 * As instances of this class are immutable, the return value 176 * is computed just once for each instance and reused 177 * throughout its life. 178 * </p> 179 * 180 * @return the hashcode of the operation information. 181 */ 182 public int hashCode() 183 { 184 if (hashCode == null) 185 hashCode = Integer.valueOf(getName().hashCode() + 186 returnOpenType.hashCode() + 187 Integer.valueOf(getImpact()).hashCode() + 188 Arrays.asList(getSignature()).hashCode()); 189 return hashCode.intValue(); 190 } 191 192 /** 193 * <p> 194 * Returns a textual representation of this instance. This 195 * is constructed using the class name 196 * (<code>javax.management.openmbean.OpenMBeanOperationInfo</code>) 197 * along with the name, signature, open return type and impact. 198 * </p> 199 * <p> 200 * As instances of this class are immutable, the return value 201 * is computed just once for each instance and reused 202 * throughout its life. 203 * </p> 204 * 205 * @return a @link{java.lang.String} instance representing 206 * the instance in textual form. 207 */ 208 public String toString() 209 { 210 if (string == null) 211 { 212 String impactString; 213 switch (getImpact()) 214 { 215 case INFO: 216 impactString = "INFO"; 217 break; 218 case ACTION: 219 impactString = "ACTION"; 220 break; 221 case ACTION_INFO: 222 impactString = "ACTION_INFO"; 223 break; 224 case UNKNOWN: 225 impactString = "UNKNOWN"; 226 break; 227 default: 228 impactString = "ERRONEOUS VALUE"; 229 } 230 string = getClass().getName() 231 + "[name=" + getName() 232 + ",signature=" + Arrays.toString(getSignature()) 233 + ",returnOpenType=" + returnOpenType 234 + ",impact=" + impactString 235 + "]"; 236 } 237 return string; 238 } 239 240}