1 15 package org.apache.hivemind.impl; 16 17 import org.apache.commons.logging.Log; 18 import org.apache.hivemind.ApplicationRuntimeException; 19 import org.apache.hivemind.InterceptorStack; 20 import org.apache.hivemind.definition.InterceptorDefinition; 21 import org.apache.hivemind.internal.Module; 22 import org.apache.hivemind.internal.ServicePoint; 23 import org.apache.hivemind.util.ToStringBuilder; 24 25 31 public final class InterceptorStackImpl implements InterceptorStack 32 { 33 private final Log _log; 34 35 private InterceptorDefinition _interceptorDefinition; 36 private ServicePoint _sep; 37 private Class _interfaceClass; 38 private Object _top; 39 40 public InterceptorStackImpl(Log log, ServicePoint sep, Object root) 41 { 42 _log = log; 43 _sep = sep; 44 _top = root; 45 _interfaceClass = sep.getServiceInterface(); 46 } 47 48 public String toString() 49 { 50 ToStringBuilder builder = new ToStringBuilder(this); 51 builder.append("contribution", _interceptorDefinition); 52 builder.append("interfaceClass", _interfaceClass); 53 builder.append("top", _top); 54 55 return builder.toString(); 56 } 57 58 public String getServiceExtensionPointId() 59 { 60 return _sep.getExtensionPointId(); 61 } 62 63 public Module getServiceModule() 64 { 65 return _sep.getModule(); 66 } 67 68 public Class getServiceInterface() 69 { 70 return _interfaceClass; 71 } 72 73 public Object peek() 74 { 75 return _top; 76 } 77 78 public void push(Object interceptor) 79 { 80 if (interceptor == null) 81 throw new ApplicationRuntimeException( 82 ImplMessages.nullInterceptor(_interceptorDefinition, _sep), 83 _interceptorDefinition.getLocation(), 84 null); 85 86 if (!_interfaceClass.isAssignableFrom(interceptor.getClass())) 87 throw new ApplicationRuntimeException( 88 ImplMessages.interceptorDoesNotImplementInterface( 89 interceptor, 90 _interceptorDefinition, 91 _sep, 92 _interfaceClass), 93 _interceptorDefinition.getLocation(), 94 null); 95 96 _top = interceptor; 97 } 98 99 104 105 public void process(InterceptorDefinition interceptorDefinition) 106 { 107 if (_log.isDebugEnabled()) 108 _log.debug("Applying interceptor factory " + interceptorDefinition.getName()); 109 110 try 112 { 113 _interceptorDefinition = interceptorDefinition; 114 Module contributingModule = getServiceModule().getRegistry().getModule(interceptorDefinition.getModuleId()); 115 _interceptorDefinition.getInterceptorConstructor().constructServiceInterceptor(this, contributingModule); 116 } 117 finally 118 { 119 _interceptorDefinition = null; 120 } 121 } 122 123 public Log getServiceLog() 124 { 125 return _log; 126 } 127 } 128 | Popular Tags |