1 23 package com.sun.enterprise.management.offline; 24 25 import java.util.Map ; 26 import java.util.HashMap ; 27 import java.util.Set ; 28 import java.util.HashSet ; 29 import java.util.Collections ; 30 31 import javax.management.ObjectName ; 32 33 import static com.sun.appserv.management.base.XTypes.*; 34 import static com.sun.appserv.management.base.AMX.*; 35 36 37 39 public final class OfflineDottedNamePrefixes 40 { 41 private final Map <String ,String []> mTemplates; 42 43 private 44 OfflineDottedNamePrefixes( ) 45 { 46 mTemplates = initTemplates(); 47 } 48 49 private static OfflineDottedNamePrefixes INSTANCE = null; 50 51 public static synchronized OfflineDottedNamePrefixes 52 getInstance() 53 { 54 if ( INSTANCE == null ) 55 { 56 INSTANCE = new OfflineDottedNamePrefixes(); 57 } 58 return INSTANCE; 59 } 60 61 static private final String VAR = "$"; 62 static private final String PAR = "^"; 63 static private final String PART_DELIM = "."; 64 65 private static String 66 PAR( final String s ) 67 { 68 return PAR + s; 69 } 70 71 private static String 72 VAR( final String s ) 73 { 74 return VAR + s; 75 } 76 77 private static String 78 varName( final String s ) 79 { 80 if ( ! s.startsWith( VAR ) ) 81 { 82 throw new IllegalArgumentException ( s ); 83 } 84 85 return s.substring( VAR.length(), s.length() ); 86 } 87 88 private static final String NAME_VAR = VAR( NAME_KEY ); 89 90 static private final Object [] TEMPLATES = new Object [] 91 { 92 DOMAIN_CONFIG, new String [] { "domain" }, 93 CONFIG_CONFIG, new String [] { NAME_VAR }, 94 STANDALONE_SERVER_CONFIG, new String [] { NAME_VAR }, 95 HTTP_SERVICE_CONFIG, new String [] { VAR( CONFIG_CONFIG ), "http-service" }, 96 IIOP_SERVICE_CONFIG, new String [] { VAR( CONFIG_CONFIG ), "iiop-service" }, 97 ADMIN_SERVICE_CONFIG, new String [] { VAR( CONFIG_CONFIG ), "admin-service" }, 98 JAVA_CONFIG, new String [] { VAR( CONFIG_CONFIG ), "java" }, 99 AVAILABILITY_SERVICE_CONFIG, new String [] { VAR( CONFIG_CONFIG ), "availability" }, 100 EJB_CONTAINER_CONFIG, new String [] { VAR( CONFIG_CONFIG ), "ejb-container" }, 101 102 HTTP_LISTENER_CONFIG, new String [] { PAR( HTTP_SERVICE_CONFIG ), "listeners", NAME_VAR }, 103 ACCESS_LOG_CONFIG, new String [] { PAR( HTTP_SERVICE_CONFIG ), "access-log"}, 104 KEEP_ALIVE_CONFIG, new String [] { PAR( HTTP_SERVICE_CONFIG ), "keep-alive"}, 105 REQUEST_PROCESSING_CONFIG, new String [] { PAR( HTTP_SERVICE_CONFIG ), "request-processing" }, 106 CONNECTION_POOL_CONFIG, new String [] { PAR( HTTP_SERVICE_CONFIG ), "connection-pool" }, 107 HTTP_PROTOCOL_CONFIG, new String [] { PAR( HTTP_SERVICE_CONFIG ), "http-protocol" }, 108 HTTP_FILE_CACHE_CONFIG, new String [] { PAR( HTTP_SERVICE_CONFIG ), "file-cache" }, 109 VIRTUAL_SERVER_CONFIG, new String [] { PAR( HTTP_SERVICE_CONFIG ), "virtual-servers", NAME_VAR }, 110 }; 111 112 113 private Map <String ,String []> 114 initTemplates() 115 { 116 final Map <String ,String []> templates = new HashMap <String ,String []>(); 117 118 for( int i = 0; i < TEMPLATES.length; i += 2 ) 119 { 120 final String j2eeType = (String )TEMPLATES[ i ]; 121 final String [] template = (String [])TEMPLATES[ i + 1 ]; 122 123 templates.put( j2eeType, template ); 124 } 125 126 return templates; 127 } 128 129 private String 130 concat( 131 final String prefix, 132 final String part ) 133 { 134 String result = null; 135 136 if ( prefix == null || prefix.length() == 0 ) 137 { 138 result = part; 139 } 140 else 141 { 142 result = prefix + PART_DELIM + part; 143 } 144 return( result ); 145 } 146 147 private String [] 148 getTemplate( final String j2eeType ) 149 { 150 return mTemplates.get( j2eeType ); 151 } 152 153 public String 154 getPrefix( final ObjectName objectName ) 155 { 156 final String j2eeType = objectName.getKeyProperty( J2EE_TYPE_KEY ); 157 if ( j2eeType == null ) 158 { 159 throw new IllegalArgumentException ( "" + objectName ); 160 } 161 162 String prefix = null; 163 164 final String [] template = getTemplate( j2eeType ); 165 if ( template != null ) 166 { 167 for( final String part : template ) 168 { 169 String value = null; 170 171 if ( part.startsWith( VAR ) ) 172 { 173 final String prop = varName( part ); 174 value = objectName.getKeyProperty( prop ); 175 if ( value == null ) 176 { 177 throw new IllegalArgumentException ( 178 "No property " + prop + " in " + objectName ); 179 } 180 } 181 else 182 { 183 value = part; 184 } 185 186 prefix = concat( prefix, value ); 187 } 188 } 189 190 return prefix; 191 } 192 } 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 | Popular Tags |