1 23 24 29 package com.sun.appserv.management.helper; 30 31 import java.util.Set ; 32 import java.util.HashSet ; 33 import java.util.Collections ; 34 35 import javax.management.ObjectName ; 36 37 import com.sun.appserv.management.base.AMX; 38 import com.sun.appserv.management.base.AMXDebug; 39 import com.sun.appserv.management.base.XTypes; 40 import com.sun.appserv.management.base.QueryMgr; 41 import com.sun.appserv.management.base.Util; 42 43 import com.sun.appserv.management.util.misc.CollectionUtil; 44 import com.sun.appserv.management.util.misc.GSetUtil; 45 import com.sun.appserv.management.util.misc.Output; 46 47 import com.sun.appserv.management.config.RefConfigReferent; 48 import com.sun.appserv.management.config.DeployedItemRefConfigReferent; 49 import com.sun.appserv.management.config.ResourceRefConfigReferent; 50 import com.sun.appserv.management.config.ServerRefConfigReferent; 51 import com.sun.appserv.management.config.ClusterRefConfigReferent; 52 import com.sun.appserv.management.config.ClusterRefConfig; 53 import com.sun.appserv.management.config.ServerRefConfig; 54 import com.sun.appserv.management.config.ConfigRemover; 55 56 import com.sun.appserv.management.config.RefConfig; 57 import com.sun.appserv.management.config.ServerRefConfig; 58 import com.sun.appserv.management.config.ClusterRefConfig; 59 import com.sun.appserv.management.config.ResourceConfig; 60 import com.sun.appserv.management.config.ResourceRefConfig; 61 import com.sun.appserv.management.config.ResourceRefConfigCR; 62 import com.sun.appserv.management.config.ModuleConfig; 63 import com.sun.appserv.management.config.DeployedItemRefConfig; 64 import com.sun.appserv.management.config.DeployedItemRefConfigCR; 65 import com.sun.appserv.management.config.LifecycleModuleConfig; 66 import com.sun.appserv.management.config.CustomMBeanConfig; 67 68 74 public class RefHelper 75 { 76 private RefHelper() {} 77 78 79 private static Output 80 getDebug() 81 { 82 return AMXDebug.getInstance().getOutput( "com.sun.appserv.management.helper.RefHelper" ); 83 } 84 85 89 public static <T extends RefConfig> Set <T> 90 findAllRefConfigs( final QueryMgr queryMgr ) 91 { 92 final Set <T> refs = 93 queryMgr.queryInterfaceSet( RefConfig.class.getName(), null); 94 95 return refs; 96 } 97 98 102 public static <T extends RefConfig> Set <T> 103 findAllRefConfigsByJ2EEType( 104 final QueryMgr queryMgr, 105 final String refJ2EEType ) 106 { 107 final Set <T> refs = 108 queryMgr.queryJ2EETypeSet( refJ2EEType ); 109 110 return refs; 111 } 112 113 117 public static Set <ResourceRefConfig> 118 findAllResourceRefConfigs( final QueryMgr queryMgr ) 119 { 120 return 121 findAllRefConfigsByJ2EEType( queryMgr, XTypes.RESOURCE_REF_CONFIG ); 122 } 123 124 128 public static Set <DeployedItemRefConfig> 129 findAllDeployedItemRefConfigs( final QueryMgr queryMgr ) 130 { 131 return 132 findAllRefConfigsByJ2EEType( queryMgr, XTypes.DEPLOYED_ITEM_REF_CONFIG ); 133 } 134 135 139 public static Set <ServerRefConfig> 140 findAllServerRefConfigs( final QueryMgr queryMgr ) 141 { 142 return 143 findAllRefConfigsByJ2EEType( queryMgr, XTypes.SERVER_REF_CONFIG ); 144 } 145 146 147 151 public static Set <ClusterRefConfig> 152 findAllClusterRefConfigs( final QueryMgr queryMgr ) 153 { 154 return 155 findAllRefConfigsByJ2EEType( queryMgr, XTypes.CLUSTER_REF_CONFIG ); 156 } 157 158 163 public static <T extends RefConfig> Set <T> 164 findAllRefConfigsWithName( 165 final QueryMgr queryMgr, 166 final String refJ2EEType, 167 final String name ) 168 { 169 final String props = Util.makeRequiredProps( refJ2EEType, name ); 170 171 final Set <T> refs = queryMgr.queryPatternSet( null, props ); 172 173 return refs; 174 } 175 176 179 public static String 180 getReferentRefJ2EEType( final RefConfigReferent referent ) 181 { 182 String j2eeType = null; 183 184 if ( referent instanceof ResourceRefConfigReferent ) 185 { 186 j2eeType = XTypes.RESOURCE_REF_CONFIG; 187 } 188 else if ( referent instanceof DeployedItemRefConfigReferent ) 189 { 190 j2eeType = XTypes.DEPLOYED_ITEM_REF_CONFIG; 191 } 192 else if ( referent instanceof ServerRefConfigReferent ) 193 { 194 j2eeType = XTypes.SERVER_REF_CONFIG; 195 } 196 else if ( referent instanceof ClusterRefConfigReferent ) 197 { 198 j2eeType = XTypes.CLUSTER_REF_CONFIG; 199 } 200 else 201 { 202 throw new IllegalArgumentException ( 203 "Unknown referent class: " + Util.asAMX( referent ).getJ2EEType() ); 204 } 205 206 return j2eeType; 207 } 208 209 private static final Set <String > REFERENT_J2EE_TYPES = 210 Collections.unmodifiableSet( GSetUtil.newSet( new String [] 211 { 212 XTypes.RESOURCE_REF_CONFIG, 213 XTypes.DEPLOYED_ITEM_REF_CONFIG, 214 XTypes.SERVER_REF_CONFIG, 215 XTypes.CLUSTER_REF_CONFIG, 216 })); 217 218 public static Set <String > 219 getReferentJ2EETypes() 220 { 221 return REFERENT_J2EE_TYPES; 222 } 223 224 225 229 public static <T extends RefConfig> Set <T> 230 findAllRefConfigs( final RefConfigReferent referent ) 231 { 232 final AMX amx = Util.asAMX( referent ); 233 234 return findAllRefConfigsWithName( getQueryMgr( amx ), 235 getReferentRefJ2EEType( referent ), 236 amx.getName() ); 237 } 238 239 243 public static <T extends RefConfig> Set <T> 244 findAllRefConfigs( final RefConfigReferent referent, final String refJ2EEType ) 245 { 246 final AMX amx = Util.asAMX( referent ); 247 248 return findAllRefConfigsWithName( getQueryMgr( amx ), refJ2EEType, amx.getName() ); 249 } 250 251 255 public static Set <DeployedItemRefConfig> 256 findAllRefConfigs( final DeployedItemRefConfigReferent referent ) 257 { 258 final AMX amx = Util.asAMX( referent ); 259 260 return 261 findAllRefConfigsWithName( getQueryMgr( amx ), XTypes.DEPLOYED_ITEM_REF_CONFIG, amx.getName() ); 262 } 263 264 268 public static Set <ResourceRefConfig> 269 findAllRefConfigs( final ResourceRefConfigReferent referent ) 270 { 271 final AMX amx = Util.asAMX( referent ); 272 273 return 274 findAllRefConfigsWithName( getQueryMgr( amx ), XTypes.RESOURCE_REF_CONFIG, amx.getName() ); 275 } 276 277 281 public static Set <ServerRefConfig> 282 findAllRefConfigs( final ServerRefConfigReferent referent ) 283 { 284 final AMX amx = Util.asAMX( referent ); 285 286 return 287 findAllRefConfigsWithName( getQueryMgr( amx ), XTypes.SERVER_REF_CONFIG, amx.getName() ); 288 } 289 290 private static QueryMgr 291 getQueryMgr( final AMX amx ) 292 { 293 return amx.getDomainRoot().getQueryMgr(); 294 } 295 296 300 public static Set <ClusterRefConfig> 301 findAllRefConfigs( final ClusterRefConfigReferent referent ) 302 { 303 final AMX amx = Util.asAMX( referent ); 304 305 return 306 findAllRefConfigsWithName( getQueryMgr( amx ), XTypes.CLUSTER_REF_CONFIG, amx.getName() ); 307 } 308 309 public static <T extends RefConfig> Set <T> 310 removeAllRefsTo( 311 final RefConfigReferent item, 312 final boolean allowSingleFailure ) 313 { 314 final Set <T> refs = RefHelper.findAllRefConfigs( item ); 315 316 final Set <T> failures = RefHelper.removeRefConfigs( refs ); 317 318 if ( failures.size() > 1 || ! allowSingleFailure ) 319 { 320 final Set <ObjectName > objectNames = Util.toObjectNames( failures ); 321 322 throw new IllegalArgumentException ( "failure removing refererences:\n{" + 323 CollectionUtil.toString( objectNames, "\n" ) + "\n}" ); 324 } 325 326 return failures; 327 } 328 329 333 public static <T extends RefConfig> Set <T> 334 removeRefConfigs( final Set <T> refs ) 335 { 336 final Set <T> failures = new HashSet <T>(); 337 338 for( final T ref : refs ) 339 { 340 final ConfigRemover rrc = ConfigRemover.class.cast( ref.getContainer() ); 341 342 try 343 { 344 rrc.removeConfig( ref.getJ2EEType(), ref.getName() ); 346 } 347 catch( Exception e ) 348 { 349 failures.add( ref ); 350 } 351 } 352 353 return failures; 354 } 355 356 } 357 358 359 360 361 362 363 364 365 366 367 368 369 | Popular Tags |