1 17 18 package org.objectweb.jac.aspects.naming; 19 20 import org.aopalliance.intercept.ConstructorInvocation; 21 import org.aopalliance.intercept.MethodInvocation; 22 import org.objectweb.jac.core.*; 23 import org.objectweb.jac.wrappers.ForwardingWrapper; 24 25 42 43 public class BindingWrapper extends Wrapper { 44 45 50 51 public BindingWrapper(AspectComponent ac, String logicalName) { 52 super(ac); 53 this.logicalName = logicalName; 54 } 55 56 57 protected String logicalName; 58 59 64 65 public String getLogicalName() { 66 return logicalName; 67 } 68 69 78 79 public Object bind(Interaction interaction) throws BindingErrorException { 80 81 82 NameRepository repository = (NameRepository) NameRepository.get(); 83 84 if (repository == null) { 85 throw new BindingErrorException("Binding aspect cannot work without the naming aspect."); 86 } 87 88 90 91 Object object = repository.getObject(logicalName); 92 93 95 if (object == null) { 96 throw new BindingErrorException( 97 "Object '" + logicalName + "' not found in the repository."); 98 } 99 100 Object to_forward = null; 102 103 107 108 122 126 127 128 ForwardingWrapper forwarder = 129 new ForwardingWrapper(getAspectComponent(), object); 130 Wrapping.unwrapAll(interaction.wrappee, null, this); 131 Wrapping.wrapAll(interaction.wrappee, null, forwarder); 132 133 134 Object ret = 135 interaction.method.invoke(interaction.wrappee, interaction.args); 136 return ret; 137 138 } 139 140 public Object invoke(MethodInvocation invocation) throws Throwable { 141 return bind((Interaction) invocation); 142 } 143 144 public Object construct(ConstructorInvocation invocation) 145 throws Throwable { 146 throw new Exception ("Wrapper "+this+" does not support construction interception."); 147 } 148 149 } 150 | Popular Tags |