1 23 package com.sun.enterprise.management.support.oldconfig; 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.List ; 30 import java.util.Collections ; 31 32 import javax.management.ObjectName ; 33 34 35 import com.sun.appserv.management.util.misc.ListUtil; 36 import com.sun.appserv.management.util.misc.TypeCast; 37 import com.sun.appserv.management.util.jmx.JMXUtil; 38 39 import com.sun.appserv.management.base.AMX; 40 import com.sun.appserv.management.base.AMXDebug; 41 import com.sun.appserv.management.base.XTypes; 42 import com.sun.enterprise.management.support.ObjectNames; 43 import com.sun.enterprise.management.support.TypeInfo; 44 import com.sun.enterprise.management.support.TypeInfos; 45 import com.sun.enterprise.management.support.OldTypeToJ2EETypeMapper; 46 47 import com.sun.appserv.management.util.stringifier.SmartStringifier; 48 49 52 public final class OldProps 53 { 54 private final ObjectName mObjectName; 55 private final Map <String ,String > mValues; 56 57 private static final String SERVER_CONFIG_KEY = "ServerConfig"; 58 59 private static void 60 debug( final Object o ) 61 { 62 AMXDebug.getInstance().getOutput( "OldProps" ).println( o ); 63 } 64 65 69 static private final List <String > POSSIBLE_NAME_KEYS = Collections.unmodifiableList( 70 ListUtil.newListFromArray( new String [] 71 { 72 "name", 73 "id", 74 "ref", 75 "thread-pool-id", 76 "jndi-name", 77 "resource-adapter-name", 78 "provider-id", 79 "connector-resource-jndi-name", 80 "auth-layer", 81 } )); 82 83 public static List <String > 84 getPossibleNameKeys() 85 { 86 return POSSIBLE_NAME_KEYS; 87 } 88 89 90 public ObjectName 91 getOldObjectName() 92 { 93 return( mObjectName ); 94 } 95 96 100 public String 101 getNewProps() 102 { 103 return( JMXUtil.mapToProps( mValues ) ); 104 } 105 106 109 private String 110 getOldName( final ObjectName oldObjectName ) 111 { 112 String oldName = null; 113 114 for( final String key : getPossibleNameKeys() ) 115 { 116 oldName = oldObjectName.getKeyProperty( key ); 117 if ( oldName != null ) 118 { 119 break; 120 } 121 } 122 123 if ( oldName == null && oldObjectName.getKeyProperty( "type" ).equals( "root" ) ) 125 { 126 oldName = oldObjectName.getKeyProperty( "server" ); 127 } 128 129 return( oldName ); 130 } 131 132 private static String 133 toString( final Object o ) 134 { 135 return( SmartStringifier.toString( o ) ); 136 } 137 138 143 public static Set 144 j2eeTypesToOldTypes( 145 final Set <String > j2eeTypes, 146 final OldTypeToJ2EETypeMapper mapper) 147 { 148 final Set <String > old = new HashSet <String >(); 149 150 String match = null; 151 for ( final String j2eeType : j2eeTypes ) 152 { 153 final String oldType = mapper.j2eeTypeToOldType( j2eeType ); 154 if ( oldType != null ) 155 { 156 old.add( oldType ); 157 } 158 } 159 160 return( old ); 161 } 162 163 164 165 public 166 OldProps( 167 final ObjectName oldObjectName, 168 final OldTypeToJ2EETypeMapper mapper) 169 { 170 mObjectName = oldObjectName; 171 mValues = new HashMap <String ,String >(); 172 173 final String j2eeType = mapper.oldObjectNameToJ2EEType( oldObjectName ); 175 if ( j2eeType == null ) 176 { 177 throw new IllegalArgumentException ( "" + oldObjectName ); 178 } 179 mValues.put( AMX.J2EE_TYPE_KEY, j2eeType ); 180 181 final String oldName = getOldName( oldObjectName ); 183 final String name = oldName != null ? 184 oldName : ObjectNames.getSingletonName( j2eeType ); 185 mValues.put( AMX.NAME_KEY, name ); 186 187 final Set <String > keys = TypeCast.asSet(oldObjectName.getKeyPropertyList().keySet()); 188 for( final String prop : keys ) 189 { 190 final String newType = mapper.oldTypeToJ2EEType( prop, oldObjectName ); 191 192 if ( newType != null ) 193 { 194 mValues.put( newType, oldObjectName.getKeyProperty( prop ) ); 195 } 196 } 197 198 200 if ( j2eeType.equals( XTypes.JMX_CONNECTOR_CONFIG ) ) 201 { 202 207 if ( mValues.containsKey( XTypes.CONFIG_CONFIG ) ) 208 { 209 mValues.put( XTypes.ADMIN_SERVICE_CONFIG, 210 ObjectNames.getSingletonName( XTypes.ADMIN_SERVICE_CONFIG ) ); 211 } 212 else if ( mValues.containsKey( XTypes.NODE_AGENT_CONFIG ) ) 213 { 214 } 216 else 217 { 218 throw new IllegalArgumentException ( "unrecognized ObjectName for jmx-connector" ); 219 } 220 } 221 else if ( j2eeType.equals( XTypes.SSL_CONFIG ) ) 222 { 223 if ( mValues.containsKey( XTypes.NODE_AGENT_CONFIG ) ) 224 { 225 229 mValues.put( XTypes.JMX_CONNECTOR_CONFIG, 230 ObjectNames.getSingletonName( XTypes.JMX_CONNECTOR_CONFIG ) ); 231 } 232 else if ( mValues.containsKey( XTypes.JMX_CONNECTOR_CONFIG ) ) 233 { 234 mValues.put( XTypes.ADMIN_SERVICE_CONFIG, 235 ObjectNames.getSingletonName( XTypes.ADMIN_SERVICE_CONFIG ) ); 236 } 237 else if ( mValues.containsKey( XTypes.CONFIG_CONFIG ) && 238 !mValues.containsKey( XTypes.HTTP_LISTENER_CONFIG ) && 239 !mValues.containsKey( XTypes.IIOP_LISTENER_CONFIG ) ) 240 { 241 mValues.put( XTypes.IIOP_SERVICE_CONFIG, 242 ObjectNames.getSingletonName( XTypes.IIOP_SERVICE_CONFIG ) ); 243 } 244 } 245 else if ( j2eeType.equals( XTypes.AUTH_REALM_CONFIG ) ) 246 { 247 252 if ( mValues.containsKey( XTypes.CONFIG_CONFIG ) ) 253 { 254 mValues.put( XTypes.SECURITY_SERVICE_CONFIG, 255 ObjectNames.getSingletonName( XTypes.SECURITY_SERVICE_CONFIG ) ); 256 } 257 else if ( mValues.containsKey( XTypes.NODE_AGENT_CONFIG ) ) 258 { 259 } 261 else 262 { 263 throw new IllegalArgumentException ( "unrecognized ObjectName for ssl or jmx-connector" ); 264 } 265 } 266 } 267 268 269 270 } 271 272 273 274 275 276 277 278 | Popular Tags |