1 23 24 package com.sun.enterprise.management.offline; 25 26 import java.util.Map ; 27 import java.util.HashMap ; 28 29 30 import com.sun.appserv.management.base.AMXDebug; 31 32 33 import com.sun.enterprise.config.ConfigContext; 34 import com.sun.enterprise.config.ConfigBean; 35 import com.sun.enterprise.config.ConfigException; 36 37 import com.sun.enterprise.config.impl.ConfigContextImpl; 38 39 40 45 final class ConfigBeanHelperFactory 46 { 47 private final ConfigContext mConfigContext; 48 private final Map <String ,ConfigBeanHelper> mHelperCache; 49 50 private static ConfigBeanHelperFactory INSTANCE = null; 51 52 private static Map <ConfigContext,ConfigBeanHelperFactory> mFactories; 53 54 private 55 ConfigBeanHelperFactory( final ConfigContext configContext) 56 { 57 mConfigContext = configContext; 58 mHelperCache = new HashMap <String ,ConfigBeanHelper>(); 59 } 60 61 private void 62 debug( final Object o ) 63 { 64 AMXDebug.getInstance().getOutput( "ConfigBeanHelperFactory" ).println( o ); 65 } 66 67 protected void 68 sdebug( Object o ) 69 { 70 debug( o ); 71 System.out.println( "" + o ); 72 } 73 74 public static synchronized ConfigBeanHelperFactory 75 getInstance( final ConfigContext configContext ) 76 { 77 if ( mFactories == null ) 78 { 79 mFactories = new HashMap <ConfigContext,ConfigBeanHelperFactory>(); 80 } 81 82 ConfigBeanHelperFactory instance = mFactories.get( configContext ); 83 if ( instance == null ) 84 { 85 instance = new ConfigBeanHelperFactory( configContext ); 86 mFactories.put( configContext, instance ); 87 } 88 89 return instance; 90 } 91 92 private ConfigBeanHelper 93 createHelper( final String xPath ) 94 throws ConfigException 95 { 96 ConfigBeanHelper helper = null; 97 final String type = ConfigBeanHelper._getType( xPath ); 98 99 final ConfigBean configBean = mConfigContext.exactLookup( xPath ); 100 if ( configBean == null ) 101 { 102 throw new IllegalArgumentException ( 103 "Null configBean returned for type: " + type ); 104 } 105 106 if ( "auth-realm".equals( type ) ) 107 { 108 helper = new AuthRealmConfigBeanHelper( mConfigContext, configBean ); 109 } 110 else if ( "security-map".equals( type ) ) 111 { 112 helper = new SecurityMapConfigBeanHelper( mConfigContext, configBean ); 113 } 114 else if ( "java-config".equals( type ) ) 115 { 116 helper = new JavaConfigConfigBeanHelper( mConfigContext, configBean ); 117 } 118 else 119 { 120 helper = new StdConfigBeanHelper( mConfigContext, configBean ); 121 } 122 123 debug( "CREATED: " + xPath ); 124 125 return helper; 126 } 127 128 public ConfigBeanHelper 129 getHelper( final String xPath ) 130 throws ConfigException 131 { 132 if ( xPath == null ) 133 { 134 throw new IllegalArgumentException ( "null xPath" ); 135 } 136 137 ConfigBeanHelper helper = mHelperCache.get( xPath ); 138 139 if ( helper == null ) 140 { 141 helper = createHelper( xPath ); 142 143 mHelperCache.put( xPath, helper ); 144 } 145 146 return helper; 147 } 148 149 public ConfigBeanHelper 150 getHelper( final ConfigBean configBean ) 151 { 152 try 153 { 154 return getHelper( configBean.getXPath() ); 155 } 156 catch( Exception e ) 157 { 158 throw new RuntimeException ( e ); 159 } 160 } 161 } 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 | Popular Tags |