1 55 56 package org.jboss.axis.configuration; 57 58 import org.apache.commons.discovery.ResourceClassIterator; 59 import org.apache.commons.discovery.tools.ClassUtils; 60 import org.jboss.axis.AxisProperties; 61 import org.jboss.axis.EngineConfigurationFactory; 62 import org.jboss.axis.utils.Messages; 63 import org.jboss.logging.Logger; 64 65 import java.lang.reflect.InvocationTargetException ; 66 import java.lang.reflect.Method ; 67 import java.security.AccessController ; 68 import java.security.PrivilegedAction ; 69 70 71 84 public class EngineConfigurationFactoryFinder 85 { 86 private static Logger log = Logger.getLogger(EngineConfigurationFactoryFinder.class.getName()); 87 88 private static final Class mySpi = EngineConfigurationFactory.class; 89 90 private static final Class [] newFactoryParamTypes = 91 new Class []{Object .class}; 92 93 private static final String requiredMethod = 94 "public static EngineConfigurationFactory newFactory(Object)"; 95 96 static 97 { 98 AxisProperties.setClassOverrideProperty(EngineConfigurationFactory.class, 99 EngineConfigurationFactory.SYSTEM_PROPERTY_NAME); 100 101 AxisProperties.setClassDefaults(EngineConfigurationFactory.class, 102 new String []{ 103 "org.jboss.axis.configuration.EngineConfigurationFactoryServlet", 104 "org.jboss.axis.configuration.EngineConfigurationFactoryDefault", 105 }); 106 } 107 108 private EngineConfigurationFactoryFinder() 109 { 110 } 111 112 113 140 public static EngineConfigurationFactory newFactory(final Object obj) 141 { 142 146 final Object [] params = new Object []{obj}; 147 148 151 return (EngineConfigurationFactory)AccessController.doPrivileged(new PrivilegedAction () 152 { 153 public Object run() 154 { 155 ResourceClassIterator services = AxisProperties.getResourceClassIterator(mySpi); 156 157 EngineConfigurationFactory factory = null; 158 159 while (factory == null && services.hasNext()) 160 { 161 try 162 { 163 Class service = services.nextResourceClass().loadClass(); 164 165 168 if (service != null) 169 { 170 factory = newFactory(service, newFactoryParamTypes, params); 171 } 172 } 173 catch (Exception e) 174 { 175 } 181 } 182 183 if (factory != null) 184 { 185 if (log.isDebugEnabled()) 186 { 187 log.debug(Messages.getMessage("engineFactory", factory.getClass().getName())); 188 } 189 } 190 else 191 { 192 log.error(Messages.getMessage("engineConfigFactoryMissing")); 193 } 201 202 return factory; 203 } 204 }); 205 } 206 207 public static EngineConfigurationFactory newFactory() 208 { 209 return newFactory(null); 210 } 211 212 private static EngineConfigurationFactory newFactory(Class service, 213 Class [] paramTypes, 214 Object [] param) 215 { 216 222 223 try 224 { 225 229 Method method = ClassUtils.findPublicStaticMethod(service, 230 EngineConfigurationFactory.class, 231 "newFactory", 232 paramTypes); 233 234 if (method == null) 235 { 236 log.warn(Messages.getMessage("engineConfigMissingNewFactory", 237 service.getName(), 238 requiredMethod)); 239 } 240 else 241 { 242 try 243 { 244 return (EngineConfigurationFactory)method.invoke(null, param); 245 } 246 catch (InvocationTargetException e) 247 { 248 if (e.getTargetException() instanceof NoClassDefFoundError ) 249 { 250 log.debug(Messages.getMessage("engineConfigLoadFactory", 251 service.getName())); 252 } 253 else 254 { 255 log.warn(Messages.getMessage("engineConfigInvokeNewFactory", 256 service.getName(), 257 requiredMethod), e); 258 } 259 } 260 catch (Exception e) 261 { 262 log.warn(Messages.getMessage("engineConfigInvokeNewFactory", 263 service.getName(), 264 requiredMethod), e); 265 } 266 } 267 } 268 catch (NoClassDefFoundError e) 269 { 270 log.debug(Messages.getMessage("engineConfigLoadFactory", 271 service.getName())); 272 } 273 274 return null; 275 } 276 } 277 | Popular Tags |