1 23 24 29 package com.sun.cli.jmx.util; 30 31 import javax.management.*; 32 import java.io.IOException ; 33 import java.util.Set ; 34 35 36 37 47 public class MBeanServerConnection_Pattern extends MBeanServerConnection_Hook 48 { 49 final MBeanServerConnection_Hook.Hook mHook; 50 51 public 52 MBeanServerConnection_Pattern( MBeanServerConnection impl ) 53 { 54 super( impl ); 55 56 mHook = new NameResolverHook(); 57 } 58 59 Hook 60 getHook() 61 { 62 return( mHook ); 63 } 64 65 68 class NameResolverHook extends MBeanServerConnection_Hook.HookImpl 69 { 70 public 71 NameResolverHook( ) 72 { 73 } 74 75 public ObjectName 76 nameHook( long id, ObjectName name ) 77 throws java.io.IOException 78 { 79 try 80 { 81 ObjectName newName = resolve( name ); 82 83 return( newName ); 84 } 85 catch( InstanceNotFoundException e ) 86 { 87 throw new IllegalArgumentException (); 91 } 92 } 93 } 94 95 96 public ObjectName 97 resolve( ObjectName input ) 98 throws java.io.IOException , InstanceNotFoundException 99 { 100 ObjectName resolvedName = input; 101 102 if ( input.isPattern() ) 103 { 104 final Set resolvedNames = getConn().queryNames( input, null ); 105 final int numNames = resolvedNames.size(); 106 107 if ( numNames == 1 ) 108 { 109 resolvedName = (ObjectName)resolvedNames.iterator().next(); 110 } 111 else if ( numNames == 2 ) 112 { 113 throw new InstanceNotFoundException( input.toString() ); 114 } 115 else 116 { 117 throw new InstanceNotFoundException( input.toString() ); 118 } 119 } 120 return( resolvedName ); 121 } 122 123 124 125 }; 126 127 | Popular Tags |