分享
 
 
 

JBoss AOP - IDE 学习笔记

王朝java/jsp·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

同时也是JBoss AOP - Reference 的Chapter 12

Chapter 12. JBoss AOP IDE

12.1. The AOP IDE

JBoss AOP comes with an Eclipse plugin that helps you define interceptors to an eclipse project via a GUI, and to run the appication from within Eclipse. This is a new project, and expect the feature set to grow quickly!

12.2. Installing

You install the JBoss AOP IDE in the same way as any other Eclipse plugin.

Make sure you have Eclipse 3.0.x installed, and start it up.

Select Help > Software Updates > Find and Install in the Eclipse workbench.

In the wizard that opens, click on the "Search for new features to install" radio button, and click Next.

On the next page you will need to add a new update site for JBossIDE. Click the "New Remote Site.." button.

Type in "JBossIDE" for the name, and "http://jboss.sourceforge.net/jbosside/updates" for the URL, and click OK.

You should see a new site in the list now called JBossIDE. click the "+" sign next to it to show the platforms available.

Now, depending if you just want to install the AOP IDE (if you don't know what JBoss-IDE is, go for this set of options):

Check the "JBoss-IDE AOP Standalone" checkbox.

In the feature list you should check the "JBoss-IDE AOP Standalone 1.0" checkbox.

If you have JBoss-IDE installed, or want to use all the other (non-AOP) features of JBoss-IDE:

If you don't have JBossIDE installed, check the "JBoss-IDE 1.4/Eclipse 3.0" checkbox.

Check the "JBoss-IDE AOP Extension" checkbox.

In the feature list you should check the "JBoss-IDE AOP Extension 1.0" checkbox, and the JBoss-IDE (1.4.0) checkbox if you don't have JBossIDE installed.

At this point you should only need to accept the license agreement(s) and wait for the install process to finish.

12.3. Tutorial

This tutorial is meant to guide you through creating a new AOP project in eclipse using the AOP extension to JBossIDE. It assumes that you have some working knowledge of AOP, and Java.. and possibly some minimal experience dealing with eclipse as well.

12.3.1. Create Project

From eclipse's main menu, you can click on the File Menu, and under it, New > Project...

Double click on JBoss AOP Project under the JBossAOP folder

In the Project Name text box, let's enter HelloAOP.

Use Default should be fine for the project location. (If you want to use an external location, make sure there are no spaces in the path.)

Click Finish

At this point, your eclipse workbench should look something like this:

12.3.2. Create Class

Next step is to create a normal Java class.

Right click on the "src" directory in the Package Explorer and in the menu, click New > Class.

The only thing you should need to change is the Name of the class. Enter HelloAOP without quotes into the Name textbox, and click Finish

Modify the code for your class so it loks like

public class HelloAOP {

public void callMe ()

{

System.out.println("AOP!");

}

public static void main (String args[])

{

new HelloAOP().callMe();

}

}

12.3.3. Create Interceptor

Next we want to create an interceptor to the class.

Right click on the "src" directory in the Package Explorer and in the menu, click New > Class. In the resulting dialog:

Name the class HelloAOPInterceptor

Add org.jboss.aop.advice.Interceptor to the list of interceptors.

Then modify the class so it looks like:

import org.jboss.aop.advice.Interceptor;

import org.jboss.aop.joinpoint.Invocation;

public class HelloAOPInterceptor implements Interceptor {

public String getName() {

return "HelloAOPInterceptor";

}

//We renamed the arg0 parameter to invocation

public Object invoke(Invocation invocation) throws Throwable {

System.out.print("Hello, ");

//Here we invoke the next in the chain

return invocation.invokeNext();

}

}

12.3.4. Applying the Interceptor

In order to apply your Interceptor to the callMe() method, we'll first need to switch back to the HelloAOP.java editor. Once the editor is active, you should be able to see the callMe() method in the Outline view (If you cannot see the outline view, go to Window > Show View > Outline).

Right click on this method, and click JBoss AOP > Apply Interceptor(s)... A dialog should open, with a list of available Interceptors. Click on HelloAOPInterceptor, and click Finish.

You should see in your Package Explorer that the file "jboss-aop.xml" now exists under your project root.

12.3.5. Running

Now all that's left is running the application! Similar to running a normal Java Application from Eclipse, you must create a Run Configuration for your project.

From the Run menu of eclipse, and choose "Run..."

In the dialog that opens, you should see a few choices in a list on the left. Double click on "JBoss AOP Application".

Once it is finished loading, you should have a new Run Configuration under JBoss AOP Application called "Hello AOP".

Click the "Run" button

The Eclipse console should now say: Hello, AOP!, where the Hello, bit has been added by the interceptor.

12.3.6. Navigation

In the real world, when developing AOP application across a development team, you can expect it will be hard to understand when and where aspects are applied in your codebase. JBoss-IDE/AOP has a few different strategies for notifying developers when an aspect is applied to a certain part of code.

12.3.6.1. Advised Markers

发布的IDE中还没有这个功能,可能CVS head的版本中有。

A marker in eclipse is a small icon that appears on the left side of the editor. Most developers are familiar with the Java Error and Bookmark markers. The AOP IDE provides markers for methods and fields which are intercepted. To further facilitate this marking, anytime the developer presses Ctrl + 1 (the default key combination for the Eclipse Quick Fix functionality)), a list of interceptors and advice will be given for that method or field. This makes navigation between methods and their interceptors extremeley easy!

12.3.6.2. The Advised Members View

The Advised Members view gives the developer an overview of every single method and field in the current class that is advised by an Aspect or Interceptor. Let's have a look.

From the Eclipse main menu, click on Window > Show View > Other...

In the window that opens, you should see a folder called "JBoss AOP". Press the "+" to expand it.

Double click on "Advised Members"

Once you've done this, you should now make sure you are currently editing the HelloAOP class we created in the last tutorial. Once you have that class open in an editor, you should see something similar to this in the Advised Members view:

Here we see that the method "callMe()" is intercepted by the interceptor HelloInterceptor. Double clicking on HelloInterceptor will take you straight to it. This view is similar to the Outline view, except it only shows members in your class which are intercepted.

12.3.6.3. The Aspect Manager View

The Aspect Manager View is a graphical representation of the AOP descriptor file (jboss-aop.xml). It allows you to remove an Interceptor or advice from a pointcut, as well as apply new Interceptors and Advice to existing pointcuts.

From the Eclipse main menu, click on Window > Show View > Other...

In the window that opens, you should see a folder called "JBoss AOP". Press the "+" to expand it.

Double click on "Aspect Manager"

Under Bindings, you'll notice that a pointcut is already defined that matches our "callMe()" method, and our HelloInterceptor is directly under it. Right Click on HelloInterceptor will provide you with this menu:

You can remove the interceptor, or jump to it directly in code. If you right click on the binding (pointcut) itself, you'll be able to apply more interceptors and advice just like when right clicking on a field or method in the outline view. You can also remove the entire binding altogether (which subsequently removes all child interceptors and advice, be warned)

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有