1 23 24 28 29 34 35 package com.sun.enterprise.management.support; 36 37 import java.util.Map ; 38 import java.util.HashMap ; 39 import java.util.Iterator ; 40 41 import javax.management.ObjectName ; 42 43 import com.sun.appserv.management.base.XTypes; 44 45 46 47 52 abstract class OldTypesBase implements OldTypeToJ2EETypeMapper 53 { 54 final Map <String ,String > mOldTypeToJ2EETypeMap; 55 final Map <String ,String > mJ2EETypeToOldTypeMap; 56 57 OldTypesBase() 58 { 59 mOldTypeToJ2EETypeMap = new HashMap <String ,String >(); 60 mJ2EETypeToOldTypeMap = new HashMap <String ,String >(); 61 initMap(); 62 } 63 64 void 65 add( 66 final String j2eeType, 67 final String oldType ) 68 { 69 mOldTypeToJ2EETypeMap.put( oldType, j2eeType ); 70 mJ2EETypeToOldTypeMap.put( j2eeType, oldType ); 71 } 72 73 77 abstract void initMap(); 78 79 85 public String 86 oldTypeToJ2EEType( 87 final String oldType, 88 final ObjectName oldObjectName ) 89 { 90 String j2eeType = null; 91 92 if ( oldType.equals( oldObjectName.getKeyProperty( OLD_TYPE_PROP ) ) ) 93 { 94 j2eeType = oldObjectNameToJ2EEType( oldObjectName ); 95 } 96 else 97 { 98 j2eeType = mOldTypeToJ2EETypeMap.get( oldType ); 99 } 100 return( j2eeType ); 101 } 102 103 109 public String 110 oldObjectNameToJ2EEType( final ObjectName oldObjectName ) 111 { 112 final String oldType = oldObjectName.getKeyProperty( OLD_TYPE_PROP ); 113 if ( oldType == null ) 114 { 115 System.err.println( "no j2eeType for: " + oldObjectName ); 116 throw new IllegalArgumentException ( oldObjectName.toString() ); 117 } 118 119 String j2eeType = null; 120 121 136 { 137 j2eeType = mOldTypeToJ2EETypeMap.get( oldType ); 138 if ( j2eeType == null ) 139 { 140 throw new IllegalArgumentException ( oldType ); 141 } 142 } 143 144 assert( j2eeType != null ); 145 return( j2eeType ); 146 } 147 148 public final static String OLD_TYPE_PROP = "type"; 149 150 153 public String 154 oldTypeToJ2EEType( final ObjectName objectName ) 155 { 156 return oldTypeToJ2EEType( objectName.getKeyProperty( OLD_TYPE_PROP ) ); 157 } 158 159 public String 160 oldTypeToJ2EEType( final String oldType ) 161 { 162 return mOldTypeToJ2EETypeMap.get(oldType); 163 } 164 165 public String 166 j2eeTypeToOldType( final String j2eeType ) 167 { 168 return mJ2EETypeToOldTypeMap.get( j2eeType ); 169 } 170 171 public Map <String ,String > 172 oldPropsToNewProps( final Map <String ,String > oldProps ) 173 { 174 final Map <String ,String > newProps = new HashMap <String ,String >(); 175 for( final String oldProp : oldProps.keySet() ) 176 { 177 final String newProp =mOldTypeToJ2EETypeMap.get( oldProp ); 178 if ( newProp != null ) 179 { 180 newProps.put( newProp, oldProps.get( oldProp ) ); 181 } 182 } 183 return newProps; 184 } 185 } 186 187 188 189 190 191 192 193 194 | Popular Tags |