Java Login

About javalogin.com

Hello guys,
javalogin.com is for Java and J2EE developers, all examples are simple and easy to understand 

It is developed and maintained by Vaibhav Sharma. The views expressed on this website are his own and do not necessarily reflect the views of his former, current or future employers. I am professional Web development. I work for an IT company as Senior Consultant. Primary I write about spring, hibernate and web-services. I am trying to present here new technologies.


     << Previous
Next >>     


JoinPoints

A join point is the specific point in the application such as method execution, exception handling, changing object variable values etc. In Spring AOP a join points is always the execution of a method.

Join points are the options on the menu and pointcuts are the items you select. A joinpoint is an opportunity within code for you to apply an aspect, just an opportunity. Once you take that opportunity and select one or more joinpoints and apply an aspect to them, you've got a pointcut.

Rose.java

package org.vtechnology.model;

public class Rose {

private String name;

public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}

Lotus.java

package org.vtechnology.model;

public class Lotus {

private String name;

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}
}

Flower.java

package org.vtechnology.service;

import org.vtechnology.model.Lotus;
import org.vtechnology.model.Rose;

public class Flower {

private Rose rose;
private Lotus lotus;
public Rose getRose() {
return rose;
}
public void setRose(Rose rose) {
this.rose = rose;
}
public Lotus getLotus() {
return lotus;
}
public void setLotus(Lotus lotus) {
this.lotus = lotus;
}
}

spring.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context">

xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">

<aop:aspectj-autoproxy/>

<bean id="rose" class="org.vtechnology.model.Rose">
<property name="name" value="Flower Name is Rose"/>
</bean>

<bean id="lotus" class="org.vtechnology.model.Lotus">
<property name="name" value="Flower Name is Lotus"/>
</bean>

<bean name="flower" class="org.vtechnology.service.Flower"
autowire="byName">

<bean class="org.vtechnology.aop.LoggingAOP"/>

</beans>

LoggingAOP.java

package org.vtechnology.aop;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.vtechnology.model.Lotus;

@Aspect
public class LoggingAOP {

@Before("pointcutGetter()")
public void loggingAdvice() {
System.out.println("Logging Advice Run before getName Method");
}

@Pointcut("execution(public String get*())")
public void pointcutGetter() {
}

@Before("allGetter1()")
public void loggingAdvice1(JoinPoint joinPoint){
System.out.println("=======JoinPoint Information=======");
System.out.println(joinPoint.toString());

Lotus lotus = (Lotus)joinPoint.getTarget();
System.out.println(lotus.getName());
System.out.println("===================================");
}

@Pointcut("within(org.vtechnology.model.Lotus)")
public void allGetter1(){
}

@Before("args(name)")
public void stringArgumentMethod(String name){
System.out.println("A Method that takes String Arguments has been
called. The value is "+name);
}

}

AopMain.java

package org.vtechnology.main;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class AopMain {

public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext
("spring.xml");

Flower flower = context.getBean("flower", Flower.class);
System.out.println("<-------First Method called--------->");
System.out.println(flower.getRose().getName());
System.out.println("<-------First Method called--------->");
flower.getLotus().setName("Dummy Flower");
System.out.println(flower.getLotus().getName());
}
}

In this example, I have described how use within and args. Joinpoint give the information in runthime about the class. It is useful when you want target object information during running program.


     << Previous
Next >>