1 /* 2 * Copyright the original author or authors. 3 * 4 * Licensed under the MOZILLA PUBLIC LICENSE, Version 1.1 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.mozilla.org/MPL/MPL-1.1.html 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 import org.as2lib.app.exec.Executable; 18 import org.as2lib.env.overload.Overload; 19 import org.as2lib.aop.JoinPoint; 20 import org.as2lib.aop.Pointcut; 21 import org.as2lib.aop.advice.AbstractBeforeAdvice; 22 import org.as2lib.aop.advice.BeforeAdvice; 23 24 /** 25 * {@code DynamicBeforeAdvice} executes a callback at the weave-in point. 26 * 27 * @author Simon Wacker 28 */ 29 class org.as2lib.aop.advice.DynamicBeforeAdvice extends AbstractBeforeAdvice implements BeforeAdvice { 30 31 /** The callback to invoke. */ 32 private var callback:Executable; 33 34 /** 35 * @overload #DynamicBeforeAdviceByPointcut 36 * @overload #DynamicBeforeAdviceByPointcutPattern 37 */ 38 public function DynamicBeforeAdvice() { 39 var o:Overload = new Overload(this); 40 o.addHandler([Pointcut, Executable], DynamicBeforeAdviceByPointcut); 41 o.addHandler([String, Executable], DynamicBeforeAdviceByPointcutPattern); 42 o.forward(arguments); 43 } 44 45 /** 46 * Constrcuts a new {@code DynamicBeforeAdvice} instance with a pointcut. 47 * 48 * @param pointcut the pointcut that determines the join points to weave this 49 * advice in 50 * @param callback the callback that is executed at the weave-in point 51 */ 52 private function DynamicBeforeAdviceByPointcut(pointcut:Pointcut, callback:Executable) { 53 setPointcutByPointcut(pointcut); 54 this.callback = callback; 55 } 56 57 /** 58 * Constrcuts a new {@code DynamicBeforeAdvice} instance with a pointcut pattern. 59 * 60 * @param pointcut the pointcut that determines the join points to weave this 61 * advice in 62 * @param callback the callback that is executed at the weave-in point 63 */ 64 private function DynamicBeforeAdviceByPointcutPattern(pointcut:String, callback:Executable) { 65 setPointcutByString(pointcut); 66 this.callback = callback; 67 } 68 69 /** 70 * Executes the callback passing the passed {@code joinPoint} and {@code args}. 71 * 72 * @param joinPoint the join point the advice was woven into 73 * @param args the arguments passed to the join point 74 */ 75 public function execute(joinPoint:JoinPoint, args:Array):Void { 76 callback.execute(joinPoint, args); 77 } 78 79 }