1 23 package com.sun.appserv.management.base; 24 25 import java.util.Map ; 26 import java.util.Set ; 27 import java.util.HashSet ; 28 import java.util.Collections ; 29 import java.util.HashMap ; 30 import java.lang.reflect.Field ; 31 32 33 39 public class TypesMapper 40 { 41 private final Map <String ,Class > mMap; 42 43 public 44 TypesMapper( final Class [] interfaces ) 45 { 46 mMap = init( interfaces ); 47 } 48 49 52 private Map <String ,Class > 53 init( final Class [] interfaces ) 54 { 55 final Map <String ,Class > m = new HashMap <String ,Class >(); 56 57 for( int i = 0; i < interfaces.length; ++i ) 58 { 59 final Class theInterface = interfaces[ i ]; 60 61 try 62 { 63 final Field field = theInterface.getField( "J2EE_TYPE" ); 64 final String value = (String )field.get( theInterface ); 65 if ( m.containsKey( value ) ) 66 { 67 final String msg = 68 "TypesMapper: key already present: " + 69 value + " for " + theInterface.getName(); 70 71 assert( false ): msg; 72 throw new RuntimeException ( msg ); 73 } 74 m.put( value, theInterface ); 75 } 76 catch( Exception e ) 77 { 78 e.printStackTrace(); 79 assert( false ); 80 throw new IllegalArgumentException ( theInterface.getName() ); 81 } 82 } 83 84 return( m ); 85 } 86 87 90 public Class 91 getInterfaceForType( final String type ) 92 { 93 final Class theClass = mMap.get( type ); 94 95 return( theClass ); 96 } 97 98 public Set <String > 99 getJ2EETypes() 100 { 101 return Collections.unmodifiableSet( mMap.keySet() ); 102 } 103 104 public Set <Class > 105 getClasses() 106 { 107 final Set <Class > classes = new HashSet <Class >(); 108 classes.addAll( mMap.values() ); 109 return Collections.unmodifiableSet( classes ); 110 } 111 } 112 113 114 115 116 117 118 119 120 121 122 123 | Popular Tags |