1 16 17 package org.apache.axis.configuration; 18 19 import org.apache.axis.AxisProperties; 20 import org.apache.axis.EngineConfigurationFactory; 21 import org.apache.axis.components.logger.LogFactory; 22 import org.apache.axis.utils.Messages; 23 import org.apache.commons.discovery.ResourceClassIterator; 24 import org.apache.commons.discovery.tools.ClassUtils; 25 import org.apache.commons.logging.Log; 26 27 import java.lang.reflect.InvocationTargetException ; 28 import java.lang.reflect.Method ; 29 import java.security.AccessController ; 30 import java.security.PrivilegedAction ; 31 32 33 46 public class EngineConfigurationFactoryFinder 47 { 48 protected static Log log = 49 LogFactory.getLog(EngineConfigurationFactoryFinder.class.getName()); 50 51 private static final Class mySpi = EngineConfigurationFactory.class; 52 53 private static final Class [] newFactoryParamTypes = 54 new Class [] { Object .class }; 55 56 private static final String requiredMethod = 57 "public static EngineConfigurationFactory newFactory(Object)"; 58 59 static { 60 AxisProperties.setClassOverrideProperty( 61 EngineConfigurationFactory.class, 62 EngineConfigurationFactory.SYSTEM_PROPERTY_NAME); 63 64 AxisProperties.setClassDefaults(EngineConfigurationFactory.class, 65 new String [] { 66 "org.apache.axis.configuration.EngineConfigurationFactoryServlet", 67 "org.apache.axis.configuration.EngineConfigurationFactoryDefault", 68 }); 69 } 70 71 private EngineConfigurationFactoryFinder() { 72 } 73 74 75 103 public static EngineConfigurationFactory newFactory(final Object obj) { 104 108 final Object [] params = new Object [] { obj }; 109 110 113 return (EngineConfigurationFactory)AccessController.doPrivileged( 114 new PrivilegedAction () { 115 public Object run() { 116 ResourceClassIterator services = AxisProperties.getResourceClassIterator(mySpi); 117 118 EngineConfigurationFactory factory = null; 119 120 while (factory == null && services.hasNext()) { 121 try { 122 Class service = services.nextResourceClass().loadClass(); 123 124 127 if (service != null) { 128 factory = newFactory(service, newFactoryParamTypes, params); 129 } 130 } catch (Exception e) { 131 } 137 } 138 139 if (factory != null) { 140 if(log.isDebugEnabled()) { 141 log.debug(Messages.getMessage("engineFactory", factory.getClass().getName())); 142 } 143 } else { 144 log.error(Messages.getMessage("engineConfigFactoryMissing")); 145 } 153 154 return factory; 155 } 156 }); 157 } 158 159 public static EngineConfigurationFactory newFactory() { 160 return newFactory(null); 161 } 162 163 private static EngineConfigurationFactory newFactory(Class service, 164 Class [] paramTypes, 165 Object [] param) { 166 172 173 try { 174 178 Method method = ClassUtils.findPublicStaticMethod(service, 179 EngineConfigurationFactory.class, 180 "newFactory", 181 paramTypes); 182 183 if (method == null) { 184 log.warn(Messages.getMessage("engineConfigMissingNewFactory", 185 service.getName(), 186 requiredMethod)); 187 } else { 188 try { 189 return (EngineConfigurationFactory)method.invoke(null, param); 190 } catch (InvocationTargetException e) { 191 if (e.getTargetException() instanceof NoClassDefFoundError ) { 192 log.debug(Messages.getMessage("engineConfigLoadFactory", 193 service.getName())); 194 } else { 195 log.warn(Messages.getMessage("engineConfigInvokeNewFactory", 196 service.getName(), 197 requiredMethod), e); 198 } 199 } catch (Exception e) { 200 log.warn(Messages.getMessage("engineConfigInvokeNewFactory", 201 service.getName(), 202 requiredMethod), e); 203 } 204 } 205 } catch (NoClassDefFoundError e) { 206 log.debug(Messages.getMessage("engineConfigLoadFactory", 207 service.getName())); 208 } 209 210 return null; 211 } 212 } 213 | Popular Tags |