1 23 package com.sun.enterprise.pluggable; 24 25 import java.lang.reflect.InvocationHandler ; 26 import java.lang.reflect.Method ; 27 import java.util.Properties ; 28 import java.util.logging.Level ; 29 import java.util.logging.Logger ; 30 31 38 public abstract class PluggableFeatureFactoryBaseImpl implements InvocationHandler { 39 40 43 private Logger _logger; 44 45 49 private Properties _featureImplClasses; 50 51 56 protected PluggableFeatureFactoryBaseImpl(Logger logger) { 57 _logger = logger; 58 } 59 60 67 public Object invoke(Object proxy, Method method, Object [] args) 68 throws Throwable { 69 String featureName = findFeatureFromMethod(method); 70 String className = _featureImplClasses.getProperty(featureName); 71 Object featureImpl = Class.forName(className).newInstance(); 72 return featureImpl; 73 } 74 75 protected abstract String getDefaultFeatureFactoryPropertyName(); 76 77 93 public Object getInstance() { 94 String propClassName = System.getProperty( 95 getDefaultFeatureFactoryPropertyName()); 96 return getInstance(propClassName); 97 } 98 99 116 public Object getInstance(String propClassName) { 117 if (propClassName == null) { 118 return null; 119 } 120 Properties props = null; 121 try { 122 props = (Properties )Class.forName(propClassName).newInstance(); 123 } catch (Exception ex) { 124 String msg = "Error loading pluggable features class " 125 + propClassName; 126 if (_logger != null) { 127 _logger.log(Level.WARNING, msg, ex); 128 } else { 129 System.err.println(msg + "\nStack Trace:"); 130 ex.printStackTrace(); 131 } 132 } 133 return getInstance(props); 134 } 135 136 151 protected abstract Object createFeatureFactory(InvocationHandler handler); 152 153 public Object getInstance(Properties props) { 154 if (props == null) { 155 return null; 156 } 157 _featureImplClasses = props; 158 return createFeatureFactory(this); 159 } 160 161 171 private String findFeatureFromMethod(Method method) { 172 Class returnType = method.getReturnType(); 173 return Utils.getNQClassName(returnType); 174 } 175 176 } 177 | Popular Tags |