国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 學(xué)院 > 開(kāi)發(fā)設(shè)計(jì) > 正文

Second-generation aspect-oriented programming By Dave Schweisguth

2019-11-18 11:30:31
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

Dynamic AOP with JBoss AOP
JBoss AOP is an AOP implementation developed by JBoss. While it came out of the desire to use AOP in the JBoss application server, it is an independent framework like aspectJ that can be used in any java PRogram. To see how it compares to AspectJ, let's jump right in to the same example recoded for AspectJ. We'll use all of the same code we used with the AspectJ example with a few exceptions. Here's what advice looks like in JBoss AOP:

public class ContextPasser implements Interceptor {
   public String getName() {
      return getClass().getName();
   }

   public Object invoke(Invocation invocation) throws Throwable {
      ServerSideContext.instance().setContext(
         ClientSideContext.instance().getContext());
      return invocation.invokeNext();
   }

}

JBoss AOP advice is simply a Java class that implements the interface org.jboss.aop.Interceptor. This interface has one trivial method: getName(), which is used for display, and one interesting method, invoke(Invocation), which is where we put the same context-passing code we put in the AspectJ advice. The last line of invoke(Invocation) returns control to the framework. Here it's just a bit of boilerplate, but in a different situation, we could replace the value returned from the actual method call with something else.

That's it! Advice is just a Java class in JBoss AOP, so there is no new syntax to learn and all of your development tools work with it like any other Java code. That takes care of the first objection we raised above.

But where's the equivalent to AspectJ's pointcut eXPression, which binds the advice to a method call? JBoss AOP provides two different ways to do this. The first uses a configuration file, usually called jboss-aop.xml:

<aop>
   <bind pointcut="execution(* *->@contextual(..))">
      <interceptor class="ContextPasser"/>
   </bind>
</aop>

This file is usually read at class load time, so we can add and remove advice and change the methods to which advice applies without recompiling. If we wish, we can compile our aspects instead, just as we did with AspectJ; this file will then be interpreted at compile time rather than at load time.

The other way to attach our advice is even more flexible. We still need a pointcut in jboss-aop.xml to tell JBoss AOP what methods we might want to advise:

<aop>


發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 丹寨县| 禄丰县| 香河县| 巴彦淖尔市| 高州市| 保德县| 高密市| 漯河市| 时尚| 治县。| 乌鲁木齐县| 崇州市| 灌阳县| 堆龙德庆县| 大厂| 江孜县| 越西县| 宁国市| 综艺| 固原市| 麻江县| 合肥市| 鄂伦春自治旗| 临猗县| 曲靖市| 夏河县| 萝北县| 察哈| 汉中市| 阳高县| 开封县| 德兴市| 长沙县| 南开区| 成安县| 隆林| 乡宁县| 桂平市| 遵义市| 轮台县| 蒙阴县|