Introduction to JBoss-IDE AOP (translation)

xiaoxiao2021-03-06  41

Introduction to JBoss-IDE AOP (translation)

1: Installation

The JBoss-IDE AOP will be included in the JBoss-IDE, you can choose the AOP option together when installing JBoss-IDE. The installation jboss-IDE can be referred to http://dev.9cbs.net/Article/25/25104.shtm. If you just want to install JBoss-IDE AOP separately, don't choose JBoss-IDE during the JBoss-IDE, just select 'JBoss-Ide AOP Standalone'.

This article introduces the AOP app in JBoss-IDE, so it is recommended to install with JBoss-IDE.

2: Introduction

This will teach how to create a simple AOP project in Eclipse's JBoss-IDE, first you have to have certain awareness of Java, AOP, and Eclipse to continue.

2.1: Creating a project

In the main directory of Eclipse, choose 'File Menu' -> 'New' -> 'Project ...'

Double-click 'JBoss AOP Project' in 'JBossaop' options

Fill in 'HelloAop' in 'Project Name'

Other settings can be lacking in the province, press 'Finish'

2.2: Create a class

Next, create a normal Java class, extend the 'HelloAop' right-click 'src' -> 'New' -> 'Class' in Eclipse project tree.

'Name' fills in 'HelloAop' and press 'Finish'

Modify the following code in 'HelloAop':

Public class helloaop {

Public void callme () {

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

}

Public static void main (string args []) {

New helloaop (). Callme ();

}

}

2.3: Create interceptor

Then add an interceptor class

Extending 'HelloAop' right-click 'src' -> 'New' -> 'Class'

'Name' fills in 'HelloAopinterceptor', 'interface' select 'interceptor' (org.jboss.aop.advice.interceptor), press 'Finish'

Modify the following code in 'HelloAopinterceptor':

Import Org.jboss.Aop.Advice.Interceptor;

Import org.jboss.aop.joinpoint.invocation;

Public class helloaopinterceptor imports 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 ();

}

2.4: Interceptor

Now we want to use Interceptor on HelloAop's Callme () method, first in Eclipse to edit 'Helloaop.java' window

The 'Outline' window below will see the Callme () method. (If you don't see you can choose 'Window' -> 'show view' -> 'Outline') in the main directory bar.

Right click on this method, press 'JBoss AOP' -> 'Apply Interceptor (s)'

Then there will appear interceptors, select 'HelloAopinterceptor', press 'Finish'

The 'JBoss-aop.xml' file in the project will be automatically changed after success.

2.5: Implementation

First create an executable, press 'Run ...' in the main directory bar above

Double-click the 'JBoss AoP Application' on the left hand on the pop-up window, then appear new execution set 'Hello AOP', press it and press 'Run'

Followed in the bottom window, 'Hello AOP!', And 'Hello' is added by Interceptor.

3: Features

When you really do some large projects, you will involve different code responsible for different programs. At this time, I don't know if I will apply aspect.

JBoss-IDE / AOP has used some strategic to proceed to pay attention to these places.

3.1: Recommended label

The label appears in Eclipse a small pattern that appears in the left hand of the window, I believe that most of the Open Eclispe will know.

AOP IDE also displays a label in places with Interceptor. As long as you press 'Ctrl 1' in the label, all methods and properties in the INTERCEPTORS in the project will appear.

This makes it easy to find Interceptors.

3.2: Recommended tab

Recommended tab window can make a pristine to see all Interceptors in this class in each class.

Choose 'Window' -> 'SHOW View' -> 'Other ...'

The 'JBoss AOP' is selected by ' ' extension after the pop-up window will be selected. 'Advised Members'

After completion, the suggested tag window is displayed under Eclipse.

3.3: Aspect administrator window

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.

The Aspect administrator window is image the AOP describing the file (JBoss-aop.xml). It can also use Interceptor or Advice in the method, and remove Interceptor or Advice by PointCut.

Choose 'Window' -> 'SHOW View' -> 'Other ...'

In the pop-up window, you will see 'JBoss AOP' press the ' ' extension after the 'Advised Manager' will display the Aspect administrator window under the Eclipse.

Source: http://docs.jboss.org/aop/aspect-framework/reference/en/html/aopide.html#aopide-install

转载请注明原文地址:https://www.9cbs.com/read-73693.html

New Post(0)