1 23 package com.sun.appserv.management.util.jmx; 24 25 import javax.management.*; 26 import java.io.IOException ; 27 import java.util.Set ; 28 29 import com.sun.appserv.management.util.misc.GSetUtil; 30 31 32 42 public class MBeanServerConnection_Pattern extends MBeanServerConnection_Hook 43 { 44 final MBeanServerConnection_Hook.Hook mHook; 45 46 public 47 MBeanServerConnection_Pattern( MBeanServerConnection impl ) 48 { 49 super( impl ); 50 51 mHook = new NameResolverHook(); 52 } 53 54 Hook 55 getHook() 56 { 57 return( mHook ); 58 } 59 60 63 class NameResolverHook extends MBeanServerConnection_Hook.HookImpl 64 { 65 public 66 NameResolverHook( ) 67 { 68 } 69 70 public ObjectName 71 nameHook( long id, ObjectName name ) 72 throws java.io.IOException 73 { 74 try 75 { 76 ObjectName newName = resolve( name ); 77 78 return( newName ); 79 } 80 catch( InstanceNotFoundException e ) 81 { 82 throw new IllegalArgumentException (); 86 } 87 } 88 } 89 90 91 public ObjectName 92 resolve( ObjectName input ) 93 throws java.io.IOException , InstanceNotFoundException 94 { 95 ObjectName resolvedName = input; 96 97 if ( input.isPattern() ) 98 { 99 final Set <ObjectName> resolvedNames = JMXUtil.queryNames( getConn(), input, null ); 100 final int numNames = resolvedNames.size(); 101 102 if ( numNames == 1 ) 103 { 104 resolvedName = GSetUtil.getSingleton( resolvedNames ); 105 } 106 else if ( numNames > 1 ) 107 { 108 throw new InstanceNotFoundException( input.toString() ); 109 } 110 else 111 { 112 throw new InstanceNotFoundException( input.toString() ); 113 } 114 } 115 return( resolvedName ); 116 } 117 118 119 120 }; 121 122 | Popular Tags |