1 15 package hivemind.test.services; 16 17 import hivemind.test.services.impl.StringHolderImpl; 18 19 import java.lang.reflect.Constructor ; 20 import java.util.Collections ; 21 22 import org.apache.hivemind.ApplicationRuntimeException; 23 import org.apache.hivemind.InterceptorStack; 24 import org.apache.hivemind.definition.InterceptorConstructor; 25 import org.apache.hivemind.definition.InterceptorDefinition; 26 import org.apache.hivemind.definition.ServicePointDefinition; 27 import org.apache.hivemind.definition.impl.ModuleDefinitionHelper; 28 import org.apache.hivemind.definition.impl.ModuleDefinitionImpl; 29 import org.apache.hivemind.definition.impl.InterceptorDefinitionImpl; 30 import org.apache.hivemind.impl.DefaultClassResolver; 31 import org.apache.hivemind.internal.AbstractServiceInterceptorConstructor; 32 import org.apache.hivemind.internal.Module; 33 import org.apache.hivemind.service.ClassFactory; 34 import org.apache.hivemind.service.impl.LoggingInterceptorClassFactory; 35 36 39 public class StringHolderModule extends ModuleDefinitionImpl 40 { 41 public StringHolderModule(String serviceModel) 42 { 43 super("hivemind.test.services", null, new DefaultClassResolver(), null); 44 45 ModuleDefinitionHelper helper = new ModuleDefinitionHelper(this); 46 ServicePointDefinition sp = helper.addServicePoint("StringHolder", StringHolder.class.getName()); 47 helper.addSimpleServiceImplementation(sp, StringHolderImpl.class.getName(), serviceModel); 48 49 InterceptorConstructor constructor = new AbstractServiceInterceptorConstructor(getLocation()) { 50 51 public void constructServiceInterceptor(InterceptorStack interceptorStack, Module contributingModule) 52 { 53 ClassFactory cf = (ClassFactory) contributingModule.getService(ClassFactory.class); 54 LoggingInterceptorClassFactory f = new LoggingInterceptorClassFactory(cf); 57 Class interceptorClass = f.constructInterceptorClass(interceptorStack, Collections.EMPTY_LIST); 58 Constructor c = interceptorClass.getConstructors()[0]; 59 Object interceptor; 60 try 61 { 62 interceptor = c.newInstance(new Object [] { interceptorStack.getServiceLog(), interceptorStack.peek() }); 63 } 64 catch (Exception e) { 65 throw new ApplicationRuntimeException(e); 66 } 67 interceptorStack.push(interceptor); 68 }}; 69 InterceptorDefinition interceptor = new InterceptorDefinitionImpl(helper.getModule(), "hivemind.LoggingInterceptor", getLocation(), constructor); 70 sp.addInterceptor(interceptor); 71 } 72 } 73 | Popular Tags |