1 15 package org.apache.hivemind.service.impl; 16 17 import java.lang.reflect.Constructor ; 18 import java.util.List ; 19 20 import org.apache.hivemind.ApplicationRuntimeException; 21 import org.apache.hivemind.InterceptorStack; 22 import org.apache.hivemind.ServiceInterceptorFactory; 23 import org.apache.hivemind.internal.Module; 24 import org.apache.hivemind.service.ClassFactory; 25 import org.apache.hivemind.service.MethodContribution; 26 27 33 public class LoggingInterceptorFactory implements ServiceInterceptorFactory 34 { 35 private ClassFactory _factory; 36 private String _serviceId; 37 38 41 public void createInterceptor( 42 InterceptorStack stack, 43 Module contributingModule, 44 Object parameters) 45 { 46 createInterceptor(stack, contributingModule, (List ) parameters); 47 } 48 49 57 public void createInterceptor( 58 InterceptorStack stack, 59 Module contributingModule, 60 List parameters) 61 { 62 LoggingInterceptorClassFactory classFactory = new LoggingInterceptorClassFactory(_factory); 63 Class interceptorClass = classFactory.constructInterceptorClass(stack, (List ) parameters); 64 65 try 66 { 67 Object interceptor = instantiateInterceptor(stack, interceptorClass); 68 69 stack.push(interceptor); 70 } 71 catch (Exception ex) 72 { 73 throw new ApplicationRuntimeException( 74 ServiceMessages.errorInstantiatingInterceptor( 75 _serviceId, 76 stack, 77 interceptorClass, 78 ex), 79 ex); 80 } 81 } 82 83 private Object instantiateInterceptor(InterceptorStack stack, Class interceptorClass) 84 throws Exception 85 { 86 Object stackTop = stack.peek(); 87 88 Constructor c = interceptorClass.getConstructors()[0]; 89 90 return c.newInstance(new Object [] { stack.getServiceLog(), stackTop }); 91 } 92 93 public void setFactory(ClassFactory factory) 94 { 95 _factory = factory; 96 } 97 98 public void setServiceId(String string) 99 { 100 _serviceId = string; 101 } 102 } 103 | Popular Tags |