JBoss AOP - IDE 学习笔记

原创 2004年10月31日 14:33:00

同时也是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 ()
	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. 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! 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. 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)

JBoss AOP - User Guide 学习笔记

JBoss AOP - User GuideThe Case For Aspects1.0Table of ContentsPreface 1. What Is Aspect-Oriented Pro...
  • tl_ang
  • tl_ang
  • 2004年10月31日 13:49
  • 1753

Jboss AOP术语与Aspects 实现

术语     Joinpoint:joinpoint是java程序中的任何点,例如方法调用,构造器访问一个域的执行等。也可以将它看作这是java事件。例如方法调用、构造器调用和数据域访问。    ...
  • fanshadoop
  • fanshadoop
  • 2012年12月17日 21:01
  • 954

eclispe jboss freemarker ide 插件安装

首先打开jbossTools的下载页面 http://www.jboss.org/tools/download/ 进入到此页面,看到图上的红色框吗?这里的链接是安装jboss tools...
  • u013277135
  • u013277135
  • 2014年02月12日 19:15
  • 1337


IDE中添加Jboss服务器插件 顾名思义,笔者接下来给大家介绍如何在IDE如eclipse、springToolSuite等中添加JBoss服务器插件。正常情况下,纯净版本的IDE目前也支持JBo...
  • huanghaifeng1990
  • huanghaifeng1990
  • 2014年01月21日 10:36
  • 1859

AOP与eclipse--JBoss AOP IDE (转自jboss)

12.1. The AOP IDEJBoss AOP comes with an Eclipse plugin that helps you define interceptors to an ecl...
  • rosonsandy
  • rosonsandy
  • 2005年03月15日 19:15
  • 904

jboss 学习笔记1

 jboss 类加载架构jboss类加载机构中的核心组件是类装载器org.jboss.mx.loading.UnifiedClassLoader3(这里我们简称UCL).这个装载器是标准的java.n...
  • peace_apple
  • peace_apple
  • 2007年12月04日 13:38
  • 1470

Spring AOP学习笔记(1):AOP基础知识

  • lmy86263
  • lmy86263
  • 2016年02月27日 01:49
  • 1174


  • pofycn
  • pofycn
  • 2016年07月03日 17:24
  • 499

Spring 4 学习笔记5:Spring AOP

面向切面编程(Aspect Oriented Programming)是Spring的重要内容,本文主要介绍AOP的概念,以及一些主要用法。...
  • w1196726224
  • w1196726224
  • 2016年01月18日 11:35
  • 779

Spring 4 学习笔记4:Java动态代理(Spring AOP原理)

介绍Spring AOP原理,Java动态代理
  • w1196726224
  • w1196726224
  • 2016年01月05日 13:44
  • 436
您举报文章:JBoss AOP - IDE 学习笔记