1 23 24 package com.sun.enterprise.management.offline; 25 26 import java.io.File ; 27 28 import java.util.Map ; 29 import java.util.HashMap ; 30 31 import com.sun.appserv.management.base.AMXDebug; 32 33 import com.sun.enterprise.config.ConfigContext; 34 import com.sun.enterprise.config.ConfigBean; 35 import com.sun.enterprise.config.ConfigException; 36 import com.sun.enterprise.config.ConfigFactory; 37 38 import com.sun.enterprise.config.impl.ConfigContextImpl; 39 40 41 43 public final class ConfigDelegateFactory 44 { 45 private ConfigContext mConfigContext; 46 private final File mDomainXML; 47 48 private static Map <File ,ConfigDelegateFactory> mFactories; 49 50 private 51 ConfigDelegateFactory(final File domainXML ) 52 throws ConfigException 53 { 54 mDomainXML = domainXML; 55 mConfigContext = createConfigContext( mDomainXML ); 56 } 57 58 private void 59 debug( final Object o ) 60 { 61 AMXDebug.getInstance().getOutput( "ConfigDelegateFactory" ).println( o ); 62 } 63 64 public static synchronized ConfigDelegateFactory 65 getInstance( final File domainXML ) 66 throws ConfigException 67 { 68 if ( mFactories == null ) 69 { 70 mFactories = new HashMap <File ,ConfigDelegateFactory>(); 71 } 72 73 ConfigDelegateFactory instance = mFactories.get( domainXML ); 74 if ( instance == null ) 75 { 76 instance = new ConfigDelegateFactory( domainXML ); 77 mFactories.put( domainXML, instance ); 78 } 79 80 return instance; 81 } 82 83 synchronized ConfigDelegate 84 createConfigDelegate( final ConfigBean configBean ) 85 throws ConfigException 86 { 87 if ( getConfigContext() != configBean.getConfigContext() ) 88 { 89 throw new IllegalArgumentException ( "ConfigBean " + 90 configBean.getXPath() + " has mismatched ConfigContext" ); 91 } 92 93 return new ConfigDelegate( getConfigContext(), configBean ); 94 } 95 96 private ConfigContext 97 createConfigContext( final File domainXML ) 98 throws ConfigException 99 { 100 setPreEnvironment(); 101 102 final ConfigContext ctx = 103 ConfigFactory.createConfigContext( domainXML.toString(), 104 true, true, true ); 105 106 setPostEnvironment( ctx ); 107 108 return ctx; 109 } 110 111 public ConfigContext 112 getConfigContext() 113 { 114 return mConfigContext; 115 } 116 117 118 private void 119 setPreEnvironment() 120 { 121 System.setProperty( 122 "com.sun.enterprise.config.config_environment_factory_class", 123 "com.sun.enterprise.config.serverbeans.AppserverConfigEnvironmentFactory" 124 ); 125 } 126 127 private void 128 setPostEnvironment( final ConfigContext ctx) 129 { 130 try 131 { 132 ((ConfigContextImpl)ctx).setXPathInAllBeans(); 133 } 134 catch(ConfigException e) 135 { 136 throw new RuntimeException ( e ); 137 } 138 } 139 } 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 | Popular Tags |