From 88c304777b4aa791388233c05638b84ba8482fe9 Mon Sep 17 00:00:00 2001 From: gumartinm Date: Thu, 10 Nov 2011 05:33:19 +0100 Subject: [PATCH] SPRING AOP is a complete mess. --- .../de/spring/example/SpringContextLocator.java | 4 +- SpringJava/SpringAOP20/pom.xml | 663 +++++++++++++++++++++ SpringJava/SpringAOP20/spring-aop-example/pom.xml | 38 ++ .../main/java/de/spring/example/GeneralAccess.java | 17 + .../main/java/de/spring/example/SpringAdvice.java | 18 + .../de/spring/example/SpringContextLocator.java | 53 ++ .../main/java/de/spring/example/SpringStart.java | 21 + .../java/de/spring/example/SystemArchitecture.java | 39 ++ .../main/java/de/spring/example/service/TestB.java | 11 + .../src/main/java/de/spring/example/web/TestA.java | 12 + .../src/main/resources/spring-config.xml | 80 +++ SpringJava/SpringAspectJ/pom.xml | 656 +++++++++++++++++++- .../SpringAspectJ/spring-aspectj-example/pom.xml | 58 +- .../src/main/java/de/spring/example/MyAdvice.java | 16 + .../main/java/de/spring/example/SpringAdvice.java | 18 + .../de/spring/example/SpringContextLocator.java | 53 ++ .../main/java/de/spring/example/SpringStart.java | 17 + .../java/de/spring/example/SystemArchitecture.java | 49 ++ .../src/main/java/de/spring/example/web/Test.java | 12 + .../aspectj/annotations/AnnotationsHandler.java | 33 - .../pos/n2a/aspectj/annotations/AspectHandler.java | 19 - .../es/dia/pos/n2a/aspectj/annotations/Prueba.java | 17 - .../aspectj/annotations/SpringContextLocator.java | 58 -- .../pos/n2a/aspectj/annotations/SpringStart.java | 14 - .../aspectj/annotations/TransactionManagerN2A.java | 41 -- .../n2a/aspectj/annotations/TransactionalN2A.java | 14 - .../src/main/resources/aop.xml | 11 - .../src/main/resources/spring-config.xml | 91 ++- 28 files changed, 1816 insertions(+), 317 deletions(-) create mode 100644 SpringJava/SpringAOP20/pom.xml create mode 100644 SpringJava/SpringAOP20/spring-aop-example/pom.xml create mode 100644 SpringJava/SpringAOP20/spring-aop-example/src/main/java/de/spring/example/GeneralAccess.java create mode 100644 SpringJava/SpringAOP20/spring-aop-example/src/main/java/de/spring/example/SpringAdvice.java create mode 100644 SpringJava/SpringAOP20/spring-aop-example/src/main/java/de/spring/example/SpringContextLocator.java create mode 100644 SpringJava/SpringAOP20/spring-aop-example/src/main/java/de/spring/example/SpringStart.java create mode 100644 SpringJava/SpringAOP20/spring-aop-example/src/main/java/de/spring/example/SystemArchitecture.java create mode 100644 SpringJava/SpringAOP20/spring-aop-example/src/main/java/de/spring/example/service/TestB.java create mode 100644 SpringJava/SpringAOP20/spring-aop-example/src/main/java/de/spring/example/web/TestA.java create mode 100644 SpringJava/SpringAOP20/spring-aop-example/src/main/resources/spring-config.xml create mode 100644 SpringJava/SpringAspectJ/spring-aspectj-example/src/main/java/de/spring/example/MyAdvice.java create mode 100644 SpringJava/SpringAspectJ/spring-aspectj-example/src/main/java/de/spring/example/SpringAdvice.java create mode 100644 SpringJava/SpringAspectJ/spring-aspectj-example/src/main/java/de/spring/example/SpringContextLocator.java create mode 100644 SpringJava/SpringAspectJ/spring-aspectj-example/src/main/java/de/spring/example/SpringStart.java create mode 100644 SpringJava/SpringAspectJ/spring-aspectj-example/src/main/java/de/spring/example/SystemArchitecture.java create mode 100644 SpringJava/SpringAspectJ/spring-aspectj-example/src/main/java/de/spring/example/web/Test.java delete mode 100644 SpringJava/SpringAspectJ/spring-aspectj-example/src/main/java/es/dia/pos/n2a/aspectj/annotations/AnnotationsHandler.java delete mode 100644 SpringJava/SpringAspectJ/spring-aspectj-example/src/main/java/es/dia/pos/n2a/aspectj/annotations/AspectHandler.java delete mode 100644 SpringJava/SpringAspectJ/spring-aspectj-example/src/main/java/es/dia/pos/n2a/aspectj/annotations/Prueba.java delete mode 100644 SpringJava/SpringAspectJ/spring-aspectj-example/src/main/java/es/dia/pos/n2a/aspectj/annotations/SpringContextLocator.java delete mode 100644 SpringJava/SpringAspectJ/spring-aspectj-example/src/main/java/es/dia/pos/n2a/aspectj/annotations/SpringStart.java delete mode 100644 SpringJava/SpringAspectJ/spring-aspectj-example/src/main/java/es/dia/pos/n2a/aspectj/annotations/TransactionManagerN2A.java delete mode 100644 SpringJava/SpringAspectJ/spring-aspectj-example/src/main/java/es/dia/pos/n2a/aspectj/annotations/TransactionalN2A.java delete mode 100644 SpringJava/SpringAspectJ/spring-aspectj-example/src/main/resources/aop.xml diff --git a/SpringJava/AnnotationsCustomHandler/custom-annotations-implementation/src/main/java/de/spring/example/SpringContextLocator.java b/SpringJava/AnnotationsCustomHandler/custom-annotations-implementation/src/main/java/de/spring/example/SpringContextLocator.java index 4d77808..1d5529f 100644 --- a/SpringJava/AnnotationsCustomHandler/custom-annotations-implementation/src/main/java/de/spring/example/SpringContextLocator.java +++ b/SpringJava/AnnotationsCustomHandler/custom-annotations-implementation/src/main/java/de/spring/example/SpringContextLocator.java @@ -24,7 +24,7 @@ public final class SpringContextLocator { */ private SpringContextLocator() { String[] factoryFiles = null; - System.out.println("Loading files context " + + System.out.println("Loading context filex " + SpringContextLocator.SPRING_CONFIG_CONTEXT); factoryFiles = new String[] { SPRING_CONFIG_CONTEXT }; @@ -38,7 +38,7 @@ public final class SpringContextLocator { * Singleton pattern not thread safety. To use SingletoHolder pattern as the best approximation * otherwise to use an Enum class (see Effective Java Second Edition and ) if we need serialization. */ - public synchronized static SpringContextLocator getInstance() { + public static SpringContextLocator getInstance() { if (SpringContextLocator.instance == null) { SpringContextLocator.instance = new SpringContextLocator(); } diff --git a/SpringJava/SpringAOP20/pom.xml b/SpringJava/SpringAOP20/pom.xml new file mode 100644 index 0000000..03f9331 --- /dev/null +++ b/SpringJava/SpringAOP20/pom.xml @@ -0,0 +1,663 @@ + + + + 4.0.0 + de.spring.example + spring-aop + 2.0-SNAPSHOT + spring-aop + http://www.myorganization.de + Spring AspectJ with Spring Libraries + + MyOrganization + http://www.myorganization.de + + pom + + trac + http://noserver/ + + + jenkins + http://noserver/jenkins/ + + + scm:svn:http://noserver + http://noserver + + + + com.sun.jdmk + jmxtools + 1.2.1 + + + javax.activation + activation + 1.1 + + + log4j + log4j + 1.2.15 + + + com.sun.jdmk + jmxtools + + + com.sun.jmx + jmxri + + + javax.mail + mail + + + javax.jms + jms + + + + + junit + junit + 4.4 + test + + + + + + c3p0 + c3p0 + 0.9.1.2 + + + cglib + cglib-nodep + 2.1_3 + + + commons-collections + commons-collections + 3.2.1 + + + commons-configuration + commons-configuration + 1.6 + + + commons-dbcp + commons-dbcp + 1.2.2 + + + commons-io + commons-io + 1.4 + + + commons-lang + commons-lang + 2.4 + + + commons-logging + commons-logging + 1.1.1 + + + commons-net + commons-net + 2.0 + + + commons-pool + commons-pool + 1.3 + + + com.h2database + h2 + 1.2.130 + + + dom4j + dom4j + 1.6.1 + + + xml-apis + xml-apis + + + + + hsqldb + hsqldb + 1.8.0.7 + + + javatar + javatar + 2.5 + + + jpos + jpos + 1.12.2 + provided + + + jpos + jpos-controls + 1.12.2 + provided + + + org.python + jython + 2.5.2b2 + + + urbanophile + java-getopt + 1.0.13 + + + mysql + mysql-connector-java + 5.1.6 + + + org.apache.ibatis + ibatis-sqlmap + 2.3.4.726 + + + org.apache.mina + mina-core + 2.0.0-M6 + + + org.aspectj + aspectjrt + 1.6.5 + + + org.aspectj + aspectjweaver + 1.6.5 + + + org.dbunit + dbunit + 2.4.4 + test + + + org.eclipse.jetty + jetty-continuation + 7.0.0.v20091005 + + + org.eclipse.jetty + jetty-http + 7.0.0.v20091005 + + + org.eclipse.jetty + jetty-io + 7.0.0.v20091005 + + + org.eclipse.jetty + jetty-security + 7.0.0.v20091005 + + + org.eclipse.jetty + jetty-server + 7.0.0.v20091005 + + + org.eclipse.jetty + jetty-servlet + 7.0.0.v20091005 + + + org.eclipse.jetty + jetty-webapp + 7.0.0.v20091005 + + + org.eclipse.jetty + jetty-util + 7.0.0.v20091005 + + + org.eclipse.jetty + jetty-xml + 7.0.0.v20091005 + + + org.slf4j + slf4j-api + 1.5.2 + + + org.slf4j + slf4j-log4j12 + 1.5.2 + + + log4j + log4j + + + + + org.springframework + spring-aop + ${spring.version} + + + org.springframework + spring-beans + ${spring.version} + + + org.springframework + spring-core + ${spring.version} + + + org.springframework + spring-context + ${spring.version} + + + org.springframework + spring-jdbc + ${spring.version} + + + org.springframework + spring-tx + ${spring.version} + + + org.springframework + spring-web + ${spring.version} + + + org.springframework + spring-webmvc + ${spring.version} + + + org.springframework + spring-context-support + ${spring.version} + + + org.springframework + spring-test + ${spring.version} + test + + + org.springframework.batch + spring-batch-test + 2.0.4.RELEASE + + + org.springframework.batch + spring-batch-core + 2.0.4.RELEASE + + + org.springframework.batch + spring-batch-infrastructure + 2.0.4.RELEASE + + + org.springframework + spring-orm + ${spring.version} + + + net.sf.ehcache + ehcache + 1.6.2 + + + org.springmodules + spring-modules-cache + 0.9 + + + p6spy + p6spy + 1.3 + + + javax.transaction + jta + 1.0.1B + + + javax.servlet + servlet-api + 2.5 + + + com.caucho + hessian + 3.1.6 + + + org.codehaus.jettison + jettison + 1.0 + + + com.thoughtworks.xstream + xstream + 1.3 + + + org.ini4j + ini4j + 0.5.1 + + + org.easymock + easymock + 2.4 + test + + + org.easymock + easymockclassextension + 2.4 + test + + + + org.apache.commons + commons-compress + 1.0 + + + org.apache.commons + commons-math + 2.0 + + + dtgjpos_forms + dtgjpos_forms + 1.4.12 + provided + + + org.codehaus.castor + castor-xml + 1.3.1 + + + org.apache.xmlbeans + xmlbeans + 2.5.0 + + + org.apache.velocity.tools + velocity-tools-generic + 1.4 + + + org.apache.velocity + velocity + 1.6.2 + + + org.tmatesoft.svnkit + svnkit + 1.3.1 + + + + + spring-aop-example + + + + + org.apache.maven.plugins + maven-compiler-plugin + 2.0.2 + + 1.6 + 1.6 + ${project.build.sourceEncoding} + + + + + org.apache.maven.plugins + maven-javadoc-plugin + 2.6 + + + org.apache.maven.plugins + maven-surefire-plugin + 2.4.2 + + true + + + + org.codehaus.mojo + jdepend-maven-plugin + 2.0-beta-2 + + + org.apache.maven.plugins + maven-jar-plugin + 2.3.1 + + + + ${project.description} + ${project.version} + ${project.organization.name} + ${project.description} + ${project.version} + ${project.organization.name} + ${BUILD_TAG} + ${BUILD_ID} + ${BUILD_NUMBER} + ${prefix.committedRevision} + ${prefix.repository} + ${prefix.path} + + + + + + com.google.code.maven-svn-revision-number-plugin + maven-svn-revision-number-plugin + 1.6 + + + + revision + + + + + + + prefix + + + + + + + + + + releases + releases + http://noserver/artifactory/custom-annotations-libs-releases-local + + + snapshots-releases + snapshots-releases + http://noserver/artifactory/custom-annotations-libs-snapshots-local + + + noserver + file:///mnt/sdb1/data/downloads/jenkins/ + + + + + + + org.apache.maven.plugins + maven-project-info-reports-plugin + 2.1.2 + + + + index + dependencies + cim + issue-tracking + scm + summary + project-team + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + 2.6.1 + + + html + + MYPROJECT API for ${project.name} ${project.version} + MYPROJECT API for ${project.name} ${project.version} + + + javadoc + aggregate + + + + + + org.codehaus.mojo + taglist-maven-plugin + 2.3 + + + TODO + @todo + FIXME + XXX + + + + + org.apache.maven.plugins + maven-surefire-report-plugin + 2.4.3 + + + integration-tests + + report-only + + + failsafe-report + + target/failsafe-reports + + + + + junit-tests + + report-only + + + surefire-report + + target/surefire-reports + + + + + + + + + UTF-8 + 2.5.6 + + + + + + + + diff --git a/SpringJava/SpringAOP20/spring-aop-example/pom.xml b/SpringJava/SpringAOP20/spring-aop-example/pom.xml new file mode 100644 index 0000000..fc21237 --- /dev/null +++ b/SpringJava/SpringAOP20/spring-aop-example/pom.xml @@ -0,0 +1,38 @@ + + + + + 4.0.0 + + spring-aop + de.spring.example + 2.0-SNAPSHOT + + + spring-aop-example + spring-aop-example + http://maven.apache.org + + + + org.springframework + spring-aspects + 2.5.6 + + + org.springframework + spring-context + + + cglib + cglib-nodep + + + org.springframework + spring-aop + + + diff --git a/SpringJava/SpringAOP20/spring-aop-example/src/main/java/de/spring/example/GeneralAccess.java b/SpringJava/SpringAOP20/spring-aop-example/src/main/java/de/spring/example/GeneralAccess.java new file mode 100644 index 0000000..3f07587 --- /dev/null +++ b/SpringJava/SpringAOP20/spring-aop-example/src/main/java/de/spring/example/GeneralAccess.java @@ -0,0 +1,17 @@ +package de.spring.example; + + +/** + * + * This class is not using the AspectJ annotations, so we could use it on JDK 1.4 and below. + * If we want to use it as an Aspect we may JUST do it using a schema based declaration. + * What means, you can use this class as an Aspect JUST using an xml Spring declaration. + * + */ +public class GeneralAccess { + + public void monitor() + { + System.out.println("I am the Advice monitor for TestB and I will be run before."); + } +} diff --git a/SpringJava/SpringAOP20/spring-aop-example/src/main/java/de/spring/example/SpringAdvice.java b/SpringJava/SpringAOP20/spring-aop-example/src/main/java/de/spring/example/SpringAdvice.java new file mode 100644 index 0000000..90e345e --- /dev/null +++ b/SpringJava/SpringAOP20/spring-aop-example/src/main/java/de/spring/example/SpringAdvice.java @@ -0,0 +1,18 @@ +package de.spring.example; + +import java.lang.reflect.Method; +import org.springframework.aop.MethodBeforeAdvice; + +/** + * + * We are using here an Advice of Spring 1.2 + * See: http://static.springsource.org/spring/docs/3.1.0.RC1/spring-framework-reference/html/aop-api.html#aop-api-advice-types + * + */ +public class SpringAdvice implements MethodBeforeAdvice { + + public void before(Method m, Object[] args, Object target) throws Throwable { + System.out.println("I am the SpringAdvice and I will be run before."); + } + +} diff --git a/SpringJava/SpringAOP20/spring-aop-example/src/main/java/de/spring/example/SpringContextLocator.java b/SpringJava/SpringAOP20/spring-aop-example/src/main/java/de/spring/example/SpringContextLocator.java new file mode 100644 index 0000000..d599c8f --- /dev/null +++ b/SpringJava/SpringAOP20/spring-aop-example/src/main/java/de/spring/example/SpringContextLocator.java @@ -0,0 +1,53 @@ +package de.spring.example; + +import org.springframework.context.ApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; + + +/** + * + */ +public final class SpringContextLocator { + + // Singleton Pattern + private static SpringContextLocator instance; + + // Spring ApplicationContext + private static ApplicationContext context; + + // Spring Context + private static final String SPRING_CONFIG_CONTEXT="spring-config.xml"; + + + /** + * Private constructor. Singleton pattern. + */ + private SpringContextLocator() { + String[] factoryFiles = null; + System.out.println("Loading context files: " + SpringContextLocator.SPRING_CONFIG_CONTEXT); + + factoryFiles = new String[] { SPRING_CONFIG_CONTEXT }; + + SpringContextLocator.context = new ClassPathXmlApplicationContext(factoryFiles); + + System.out.println("The context has been loaded successfully!! "); + } + + /** + * Singleton pattern not thread safety. To use SingletoHolder pattern as the best approximation + * otherwise to use an Enum class (see Effective Java Second Edition and ) if we need serialization. + */ + public static SpringContextLocator getInstance() { + if (SpringContextLocator.instance == null) { + SpringContextLocator.instance = new SpringContextLocator(); + } + return SpringContextLocator.instance; + } + + /** + * Return bean from application context. + */ + public Object getBean(final String name) { + return SpringContextLocator.context.getBean(name); + } +} \ No newline at end of file diff --git a/SpringJava/SpringAOP20/spring-aop-example/src/main/java/de/spring/example/SpringStart.java b/SpringJava/SpringAOP20/spring-aop-example/src/main/java/de/spring/example/SpringStart.java new file mode 100644 index 0000000..2cf4a1a --- /dev/null +++ b/SpringJava/SpringAOP20/spring-aop-example/src/main/java/de/spring/example/SpringStart.java @@ -0,0 +1,21 @@ +package de.spring.example; + +import de.spring.example.service.TestB; +import de.spring.example.web.TestA; + +public class SpringStart { + + /** + * @param args + */ + public static void main(String[] args) { + System.out.println("Starting application"); + SpringContextLocator.getInstance(); + + TestA testA = (TestA) SpringContextLocator.getInstance().getBean("testA"); + testA.myMethod(); + + TestB testB = (TestB) SpringContextLocator.getInstance().getBean("testB"); + testB.myMethod(); + } +} diff --git a/SpringJava/SpringAOP20/spring-aop-example/src/main/java/de/spring/example/SystemArchitecture.java b/SpringJava/SpringAOP20/spring-aop-example/src/main/java/de/spring/example/SystemArchitecture.java new file mode 100644 index 0000000..f9511b2 --- /dev/null +++ b/SpringJava/SpringAOP20/spring-aop-example/src/main/java/de/spring/example/SystemArchitecture.java @@ -0,0 +1,39 @@ +package de.spring.example; + +import org.aspectj.lang.annotation.Pointcut; + +/** + * + * Using the @Aspect annotation you could use this class as an Aspect without + * using a schema based declaration (without using + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/SpringJava/SpringAspectJ/pom.xml b/SpringJava/SpringAspectJ/pom.xml index 3e29b6f..61dfe24 100644 --- a/SpringJava/SpringAspectJ/pom.xml +++ b/SpringJava/SpringAspectJ/pom.xml @@ -1,17 +1,663 @@ - + + 4.0.0 de.spring.example spring-aspectj 2.0-SNAPSHOT - custom-annotations - http://maven.apache.org + spring-aspect + http://www.myorganization.de + Spring AspectJ with Spring Libraries + + MyOrganization + http://www.myorganization.de + pom - + + trac + http://noserver/ + + + jenkins + http://noserver/jenkins/ + + + scm:svn:http://noserver + http://noserver + + + com.sun.jdmk + jmxtools + 1.2.1 + + + javax.activation + activation + 1.1 + + + log4j + log4j + 1.2.15 + + + com.sun.jdmk + jmxtools + + + com.sun.jmx + jmxri + + + javax.mail + mail + + + javax.jms + jms + + + + + junit + junit + 4.4 + test + + + + + c3p0 + c3p0 + 0.9.1.2 + + + cglib + cglib-nodep + 2.1_3 + + + commons-collections + commons-collections + 3.2.1 + + + commons-configuration + commons-configuration + 1.6 + + + commons-dbcp + commons-dbcp + 1.2.2 + + + commons-io + commons-io + 1.4 + + + commons-lang + commons-lang + 2.4 + + + commons-logging + commons-logging + 1.1.1 + + + commons-net + commons-net + 2.0 + + + commons-pool + commons-pool + 1.3 + + + com.h2database + h2 + 1.2.130 + + + dom4j + dom4j + 1.6.1 + + + xml-apis + xml-apis + + + + + hsqldb + hsqldb + 1.8.0.7 + + + javatar + javatar + 2.5 + + + jpos + jpos + 1.12.2 + provided + + + jpos + jpos-controls + 1.12.2 + provided + + + org.python + jython + 2.5.2b2 + + + urbanophile + java-getopt + 1.0.13 + + + mysql + mysql-connector-java + 5.1.6 + + + org.apache.ibatis + ibatis-sqlmap + 2.3.4.726 + + + org.apache.mina + mina-core + 2.0.0-M6 + + + org.aspectj + aspectjrt + 1.6.5 + + + org.aspectj + aspectjweaver + 1.6.5 + + + org.dbunit + dbunit + 2.4.4 + test + + + org.eclipse.jetty + jetty-continuation + 7.0.0.v20091005 + + + org.eclipse.jetty + jetty-http + 7.0.0.v20091005 + + + org.eclipse.jetty + jetty-io + 7.0.0.v20091005 + + + org.eclipse.jetty + jetty-security + 7.0.0.v20091005 + + + org.eclipse.jetty + jetty-server + 7.0.0.v20091005 + + + org.eclipse.jetty + jetty-servlet + 7.0.0.v20091005 + + + org.eclipse.jetty + jetty-webapp + 7.0.0.v20091005 + + + org.eclipse.jetty + jetty-util + 7.0.0.v20091005 + + + org.eclipse.jetty + jetty-xml + 7.0.0.v20091005 + + + org.slf4j + slf4j-api + 1.5.2 + + + org.slf4j + slf4j-log4j12 + 1.5.2 + + + log4j + log4j + + + + + org.springframework + spring-aop + ${spring.version} + + + org.springframework + spring-beans + ${spring.version} + + + org.springframework + spring-core + ${spring.version} + + + org.springframework + spring-context + ${spring.version} + + + org.springframework + spring-jdbc + ${spring.version} + + + org.springframework + spring-tx + ${spring.version} + + + org.springframework + spring-web + ${spring.version} + + + org.springframework + spring-webmvc + ${spring.version} + + + org.springframework + spring-context-support + ${spring.version} + + + org.springframework + spring-test + ${spring.version} + test + + + org.springframework.batch + spring-batch-test + 2.0.4.RELEASE + + + org.springframework.batch + spring-batch-core + 2.0.4.RELEASE + + + org.springframework.batch + spring-batch-infrastructure + 2.0.4.RELEASE + + + org.springframework + spring-orm + ${spring.version} + + + net.sf.ehcache + ehcache + 1.6.2 + + + org.springmodules + spring-modules-cache + 0.9 + + + p6spy + p6spy + 1.3 + + + javax.transaction + jta + 1.0.1B + + + javax.servlet + servlet-api + 2.5 + + + com.caucho + hessian + 3.1.6 + + + org.codehaus.jettison + jettison + 1.0 + + + com.thoughtworks.xstream + xstream + 1.3 + + + org.ini4j + ini4j + 0.5.1 + + + org.easymock + easymock + 2.4 + test + + + org.easymock + easymockclassextension + 2.4 + test + + + org.apache.commons + commons-compress + 1.0 + + + org.apache.commons + commons-math + 2.0 + + + dtgjpos_forms + dtgjpos_forms + 1.4.12 + provided + + + org.codehaus.castor + castor-xml + 1.3.1 + + + org.apache.xmlbeans + xmlbeans + 2.5.0 + + + org.apache.velocity.tools + velocity-tools-generic + 1.4 + + + org.apache.velocity + velocity + 1.6.2 + + + org.tmatesoft.svnkit + svnkit + 1.3.1 + + + - spring-aspectj-example + spring-aspectj-example + + + + org.apache.maven.plugins + maven-compiler-plugin + 2.0.2 + + 1.6 + 1.6 + ${project.build.sourceEncoding} + + + + + org.apache.maven.plugins + maven-javadoc-plugin + 2.6 + + + org.apache.maven.plugins + maven-surefire-plugin + 2.4.2 + + true + + + + org.codehaus.mojo + jdepend-maven-plugin + 2.0-beta-2 + + + org.apache.maven.plugins + maven-jar-plugin + 2.3.1 + + + + ${project.description} + ${project.version} + ${project.organization.name} + ${project.description} + ${project.version} + ${project.organization.name} + ${BUILD_TAG} + ${BUILD_ID} + ${BUILD_NUMBER} + ${prefix.committedRevision} + ${prefix.repository} + ${prefix.path} + + + + + + com.google.code.maven-svn-revision-number-plugin + maven-svn-revision-number-plugin + 1.6 + + + + revision + + + + + + + prefix + + + + + + + + + + releases + releases + http://noserver/artifactory/custom-annotations-libs-releases-local + + + snapshots-releases + snapshots-releases + http://noserver/artifactory/custom-annotations-libs-snapshots-local + + + noserver + file:///mnt/sdb1/data/downloads/jenkins/ + + + + + + + org.apache.maven.plugins + maven-project-info-reports-plugin + 2.1.2 + + + + index + dependencies + cim + issue-tracking + scm + summary + project-team + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + 2.6.1 + + + html + + MYPROJECT API for ${project.name} ${project.version} + MYPROJECT API for ${project.name} ${project.version} + + + javadoc + aggregate + + + + + + org.codehaus.mojo + taglist-maven-plugin + 2.3 + + + TODO + @todo + FIXME + XXX + + + + + org.apache.maven.plugins + maven-surefire-report-plugin + 2.4.3 + + + integration-tests + + report-only + + + failsafe-report + + target/failsafe-reports + + + + + junit-tests + + report-only + + + surefire-report + + target/surefire-reports + + + + + + + + + UTF-8 + 2.5.6 + + + + + + + diff --git a/SpringJava/SpringAspectJ/spring-aspectj-example/pom.xml b/SpringJava/SpringAspectJ/spring-aspectj-example/pom.xml index 0aef4e8..78334dc 100644 --- a/SpringJava/SpringAspectJ/spring-aspectj-example/pom.xml +++ b/SpringJava/SpringAspectJ/spring-aspectj-example/pom.xml @@ -4,75 +4,35 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + 4.0.0 - spring-aspectj de.spring.example 2.0-SNAPSHOT - de.spring.example spring-aspectj-example - 2.0-SNAPSHOT spring-aspectj-example http://maven.apache.org - - - - org.apache.maven - maven-model - 2.2.1 - - - - org.springframework spring-context - 2.5.6 - - - - org.springframework - spring-jdbc - 2.5.6 - - - - c3p0 - c3p0 - 0.9.1.2 - - - org.aspectj - aspectjrt - 1.6.12 + + cglib + cglib-nodep - - org.aspectj - aspectjweaver - 1.6.12 + org.springframework + spring-aop - - - - diff --git a/SpringJava/SpringAspectJ/spring-aspectj-example/src/main/java/de/spring/example/MyAdvice.java b/SpringJava/SpringAspectJ/spring-aspectj-example/src/main/java/de/spring/example/MyAdvice.java new file mode 100644 index 0000000..d45504c --- /dev/null +++ b/SpringJava/SpringAspectJ/spring-aspectj-example/src/main/java/de/spring/example/MyAdvice.java @@ -0,0 +1,16 @@ +package de.spring.example; + +import org.aspectj.lang.annotation.Aspect; +import org.aspectj.lang.annotation.Before; + +@Aspect +public class MyAdvice { + + //This advice is connected with the Pointcut defined in SystemArchitecture. + //So, every method connected to that Pointcut will be run after the + //method defined in this Advice. + @Before("de.spring.example.SystemArchitecture.pointCutMethod())") + public void doAccessCheck() { + System.out.println("I am the Advice and I will be run before."); + } +} diff --git a/SpringJava/SpringAspectJ/spring-aspectj-example/src/main/java/de/spring/example/SpringAdvice.java b/SpringJava/SpringAspectJ/spring-aspectj-example/src/main/java/de/spring/example/SpringAdvice.java new file mode 100644 index 0000000..90e345e --- /dev/null +++ b/SpringJava/SpringAspectJ/spring-aspectj-example/src/main/java/de/spring/example/SpringAdvice.java @@ -0,0 +1,18 @@ +package de.spring.example; + +import java.lang.reflect.Method; +import org.springframework.aop.MethodBeforeAdvice; + +/** + * + * We are using here an Advice of Spring 1.2 + * See: http://static.springsource.org/spring/docs/3.1.0.RC1/spring-framework-reference/html/aop-api.html#aop-api-advice-types + * + */ +public class SpringAdvice implements MethodBeforeAdvice { + + public void before(Method m, Object[] args, Object target) throws Throwable { + System.out.println("I am the SpringAdvice and I will be run before."); + } + +} diff --git a/SpringJava/SpringAspectJ/spring-aspectj-example/src/main/java/de/spring/example/SpringContextLocator.java b/SpringJava/SpringAspectJ/spring-aspectj-example/src/main/java/de/spring/example/SpringContextLocator.java new file mode 100644 index 0000000..d599c8f --- /dev/null +++ b/SpringJava/SpringAspectJ/spring-aspectj-example/src/main/java/de/spring/example/SpringContextLocator.java @@ -0,0 +1,53 @@ +package de.spring.example; + +import org.springframework.context.ApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; + + +/** + * + */ +public final class SpringContextLocator { + + // Singleton Pattern + private static SpringContextLocator instance; + + // Spring ApplicationContext + private static ApplicationContext context; + + // Spring Context + private static final String SPRING_CONFIG_CONTEXT="spring-config.xml"; + + + /** + * Private constructor. Singleton pattern. + */ + private SpringContextLocator() { + String[] factoryFiles = null; + System.out.println("Loading context files: " + SpringContextLocator.SPRING_CONFIG_CONTEXT); + + factoryFiles = new String[] { SPRING_CONFIG_CONTEXT }; + + SpringContextLocator.context = new ClassPathXmlApplicationContext(factoryFiles); + + System.out.println("The context has been loaded successfully!! "); + } + + /** + * Singleton pattern not thread safety. To use SingletoHolder pattern as the best approximation + * otherwise to use an Enum class (see Effective Java Second Edition and ) if we need serialization. + */ + public static SpringContextLocator getInstance() { + if (SpringContextLocator.instance == null) { + SpringContextLocator.instance = new SpringContextLocator(); + } + return SpringContextLocator.instance; + } + + /** + * Return bean from application context. + */ + public Object getBean(final String name) { + return SpringContextLocator.context.getBean(name); + } +} \ No newline at end of file diff --git a/SpringJava/SpringAspectJ/spring-aspectj-example/src/main/java/de/spring/example/SpringStart.java b/SpringJava/SpringAspectJ/spring-aspectj-example/src/main/java/de/spring/example/SpringStart.java new file mode 100644 index 0000000..c378221 --- /dev/null +++ b/SpringJava/SpringAspectJ/spring-aspectj-example/src/main/java/de/spring/example/SpringStart.java @@ -0,0 +1,17 @@ +package de.spring.example; + +import de.spring.example.web.Test; + +public class SpringStart { + + /** + * @param args + */ + public static void main(String[] args) { + System.out.println("Starting application"); + SpringContextLocator.getInstance(); + + Test test = (Test) SpringContextLocator.getInstance().getBean("test"); + test.myMethod(); + } +} diff --git a/SpringJava/SpringAspectJ/spring-aspectj-example/src/main/java/de/spring/example/SystemArchitecture.java b/SpringJava/SpringAspectJ/spring-aspectj-example/src/main/java/de/spring/example/SystemArchitecture.java new file mode 100644 index 0000000..a3ec844 --- /dev/null +++ b/SpringJava/SpringAspectJ/spring-aspectj-example/src/main/java/de/spring/example/SystemArchitecture.java @@ -0,0 +1,49 @@ +package de.spring.example; + +import org.aspectj.lang.annotation.AfterReturning; +import org.aspectj.lang.annotation.Aspect; +import org.aspectj.lang.annotation.Pointcut; + +/** + * + * We are using here the @AspectJ annotations to declare + * Proxies. If we want to use these kinds of proxies on the Spring framework + * we have to use the annotation on the Spring xml file + * (the Spring context file) + */ +@Aspect +public class SystemArchitecture { + + //Coonecting to the execution of any method defined in the + //package: de.spring.example.web + //We are connecting the methods defined in that package with this + //Pointcut. So, when executing any of those methods defined in that + //package we will run the Advice related to this Pointcut (if there is an Advice) + @Pointcut("execution(* de.spring.example.web.*.*(..))") + public void pointCutMethod() + { + System.out.println("I am the Pointcut and you will never see me."); + //This is the PointCut. + //You can write code here, but it will be useless because while running + //the methods connected to the Pointcut, this code will not be executed. + //Just the advice will run!!!! :/ + //Is not this weird? We are here defining a method whose code + //will never be run. When the hell should we write code here? + //This is a waste of time and code IMHO. Isn't it? + } + + //NOTICE: YOU DO NOT NEED TO CREATE A SPECIAL CLASS FOR THE ADVICE + // YOU COULD USE THE SAME CLASS FOR THE POINTCUTS AND FOR THE + // ADVICES. IN THIS CASE FOR EXAMPLE WE HAVE THE @AfterReturning + // ADVICE IN THIS CLASS AND THE @Before ADVICE IN THE CLASS CALLED + // MyAdvice + //This advice is connected with the another Pointcut. + //The returning value of every method connected to that Pointcut + //will be caught by this method. + @AfterReturning(pointcut="de.spring.example.SystemArchitecture.pointCutMethod())", + returning="retVal") + public void doAccessCheck(final Object retVal) { + System.out.println("The returned value by the method " + + "connected to the Pointcut: " + retVal); + } +} \ No newline at end of file diff --git a/SpringJava/SpringAspectJ/spring-aspectj-example/src/main/java/de/spring/example/web/Test.java b/SpringJava/SpringAspectJ/spring-aspectj-example/src/main/java/de/spring/example/web/Test.java new file mode 100644 index 0000000..3df70ac --- /dev/null +++ b/SpringJava/SpringAspectJ/spring-aspectj-example/src/main/java/de/spring/example/web/Test.java @@ -0,0 +1,12 @@ +package de.spring.example.web; + + +public class Test { + public int myMethod() + { + System.out.println("The Advice should be run before."); + + //This value will be caught by the Advice with the @AfterReturning annotation. + return 666; + } +} diff --git a/SpringJava/SpringAspectJ/spring-aspectj-example/src/main/java/es/dia/pos/n2a/aspectj/annotations/AnnotationsHandler.java b/SpringJava/SpringAspectJ/spring-aspectj-example/src/main/java/es/dia/pos/n2a/aspectj/annotations/AnnotationsHandler.java deleted file mode 100644 index 034a7a3..0000000 --- a/SpringJava/SpringAspectJ/spring-aspectj-example/src/main/java/es/dia/pos/n2a/aspectj/annotations/AnnotationsHandler.java +++ /dev/null @@ -1,33 +0,0 @@ -package de.spring.example; - -import java.util.Map; -import org.springframework.beans.BeansException; -import org.springframework.beans.factory.InitializingBean; -import org.springframework.beans.factory.generic.GenericBeanFactoryAccessor; -import org.springframework.context.ApplicationContext; -import org.springframework.context.ApplicationContextAware; - - -public class AnnotationsHandler implements ApplicationContextAware, InitializingBean { - private ApplicationContext applicationContext; - - @Override - public void afterPropertiesSet() { - GenericBeanFactoryAccessor genericBeanFactoryAccessor = new GenericBeanFactoryAccessor(applicationContext); - - final Map transactionalClass = genericBeanFactoryAccessor.getBeansWithAnnotation(TransactionalN2A.class); - - for (final Object myFoo : transactionalClass.values()) { - final Class fooClass = myFoo.getClass(); - final TransactionalN2A annotation = fooClass.getAnnotation(TransactionalN2A.class); - System.out.println("Found 1 foo class: " + fooClass + ", with tags: "); - } - } - - @Override - public void setApplicationContext(final ApplicationContext applicationContext) - throws BeansException { - this.applicationContext = applicationContext; - } - } - diff --git a/SpringJava/SpringAspectJ/spring-aspectj-example/src/main/java/es/dia/pos/n2a/aspectj/annotations/AspectHandler.java b/SpringJava/SpringAspectJ/spring-aspectj-example/src/main/java/es/dia/pos/n2a/aspectj/annotations/AspectHandler.java deleted file mode 100644 index 0f0da3f..0000000 --- a/SpringJava/SpringAspectJ/spring-aspectj-example/src/main/java/es/dia/pos/n2a/aspectj/annotations/AspectHandler.java +++ /dev/null @@ -1,19 +0,0 @@ -package de.spring.example; - -import java.util.Map; - -import org.aspectj.lang.annotation.Aspect; -import org.springframework.beans.BeansException; -import org.springframework.beans.factory.InitializingBean; -import org.springframework.beans.factory.generic.GenericBeanFactoryAccessor; -import org.springframework.context.ApplicationContext; -import org.springframework.context.ApplicationContextAware; - -@Aspect -public class AspectHandler { - - - - - } - diff --git a/SpringJava/SpringAspectJ/spring-aspectj-example/src/main/java/es/dia/pos/n2a/aspectj/annotations/Prueba.java b/SpringJava/SpringAspectJ/spring-aspectj-example/src/main/java/es/dia/pos/n2a/aspectj/annotations/Prueba.java deleted file mode 100644 index 548c5e9..0000000 --- a/SpringJava/SpringAspectJ/spring-aspectj-example/src/main/java/es/dia/pos/n2a/aspectj/annotations/Prueba.java +++ /dev/null @@ -1,17 +0,0 @@ -package de.spring.example; - - -public class Prueba { - public void bar(){ - System.out.println("I am not a number, I am a free man!"); - } - - @TransactionalN2A - public class InnerService { - public void innerMethod() { - System.out.println("xxx: AopService$InnerClass.innerMethod()"); - } - } - -} - diff --git a/SpringJava/SpringAspectJ/spring-aspectj-example/src/main/java/es/dia/pos/n2a/aspectj/annotations/SpringContextLocator.java b/SpringJava/SpringAspectJ/spring-aspectj-example/src/main/java/es/dia/pos/n2a/aspectj/annotations/SpringContextLocator.java deleted file mode 100644 index cc452f6..0000000 --- a/SpringJava/SpringAspectJ/spring-aspectj-example/src/main/java/es/dia/pos/n2a/aspectj/annotations/SpringContextLocator.java +++ /dev/null @@ -1,58 +0,0 @@ -package de.spring.example; - -import org.springframework.context.ApplicationContext; -import org.springframework.context.support.ClassPathXmlApplicationContext; - - -/** - * Localizador de beans para de los dispositivos - * - * @author rvp001es - */ -public final class SpringContextLocator { - - - // Singleton Pattern - private static SpringContextLocator instance; - - // Spring ApplicationContext - private static ApplicationContext context; - - // Dispositivos logicos - private static final String SPRING_CONFIG_CONTEXT="spring-config.xml"; - //private static final String DATABASE_CONFIG="database-config.xml"; - - - /** - * Private constructor. Singleton pattern. - */ - private SpringContextLocator() { - String[] factoryFiles = null; - System.out.println("Loading files context " + - SpringContextLocator.SPRING_CONFIG_CONTEXT); - - factoryFiles = new String[] { SPRING_CONFIG_CONTEXT }; - - SpringContextLocator.context = new ClassPathXmlApplicationContext(factoryFiles); - - System.out.println("The N2A devices context and test " + - "context has been loaded successfully!! "); - } - - /** - * Singleton pattern. GetInstance() - */ - public synchronized static SpringContextLocator getInstance() { - if (SpringContextLocator.instance == null) { - SpringContextLocator.instance = new SpringContextLocator(); - } - return SpringContextLocator.instance; - } - - /** - * Return a bean in application context. - */ - public Object getBean(final String name) { - return SpringContextLocator.context.getBean(name); - } -} diff --git a/SpringJava/SpringAspectJ/spring-aspectj-example/src/main/java/es/dia/pos/n2a/aspectj/annotations/SpringStart.java b/SpringJava/SpringAspectJ/spring-aspectj-example/src/main/java/es/dia/pos/n2a/aspectj/annotations/SpringStart.java deleted file mode 100644 index b566806..0000000 --- a/SpringJava/SpringAspectJ/spring-aspectj-example/src/main/java/es/dia/pos/n2a/aspectj/annotations/SpringStart.java +++ /dev/null @@ -1,14 +0,0 @@ -package de.spring.example; - -public class SpringStart { - - /** - * @param args - */ - public static void main(String[] args) { - System.out.println("HOLA"); - SpringContextLocator.getInstance(); - - } - -} diff --git a/SpringJava/SpringAspectJ/spring-aspectj-example/src/main/java/es/dia/pos/n2a/aspectj/annotations/TransactionManagerN2A.java b/SpringJava/SpringAspectJ/spring-aspectj-example/src/main/java/es/dia/pos/n2a/aspectj/annotations/TransactionManagerN2A.java deleted file mode 100644 index 30e9b66..0000000 --- a/SpringJava/SpringAspectJ/spring-aspectj-example/src/main/java/es/dia/pos/n2a/aspectj/annotations/TransactionManagerN2A.java +++ /dev/null @@ -1,41 +0,0 @@ -package de.spring.example; - -import org.springframework.jdbc.datasource.DataSourceTransactionManager; -import org.springframework.transaction.TransactionStatus; - - -public class TransactionManagerN2A { - private static TransactionManagerN2A instance = new TransactionManagerN2A(); - private DataSourceTransactionManager transactionManager; - private TransactionStatus transactionStatus; - - //Why could you want to extend this class? - private TransactionManagerN2A() {} - - public static TransactionManagerN2A getInstance() { - return instance; - } - - public void initTransaction() - { - transactionStatus = this.transactionManager.getTransaction(null); - } - - public void rollbackTransaction() - { - this.transactionManager.rollback(this.transactionStatus); - } - - public void commitTransaction() - { - this.transactionManager.commit(this.transactionStatus); - } - - - /************************* Setters and getters *******************************************/ - public void setTransactionManager(final DataSourceTransactionManager transactionManager) - { - this.transactionManager = transactionManager; - } -} - diff --git a/SpringJava/SpringAspectJ/spring-aspectj-example/src/main/java/es/dia/pos/n2a/aspectj/annotations/TransactionalN2A.java b/SpringJava/SpringAspectJ/spring-aspectj-example/src/main/java/es/dia/pos/n2a/aspectj/annotations/TransactionalN2A.java deleted file mode 100644 index 474dc63..0000000 --- a/SpringJava/SpringAspectJ/spring-aspectj-example/src/main/java/es/dia/pos/n2a/aspectj/annotations/TransactionalN2A.java +++ /dev/null @@ -1,14 +0,0 @@ -/** - * - */ -package de.spring.example; - -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import org.springframework.stereotype.Component; - - -@Retention(RetentionPolicy.RUNTIME) -@Component -public @interface TransactionalN2A { -} diff --git a/SpringJava/SpringAspectJ/spring-aspectj-example/src/main/resources/aop.xml b/SpringJava/SpringAspectJ/spring-aspectj-example/src/main/resources/aop.xml deleted file mode 100644 index 12e9571..0000000 --- a/SpringJava/SpringAspectJ/spring-aspectj-example/src/main/resources/aop.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - \ No newline at end of file diff --git a/SpringJava/SpringAspectJ/spring-aspectj-example/src/main/resources/spring-config.xml b/SpringJava/SpringAspectJ/spring-aspectj-example/src/main/resources/spring-config.xml index 6ea229c..9081c6c 100644 --- a/SpringJava/SpringAspectJ/spring-aspectj-example/src/main/resources/spring-config.xml +++ b/SpringJava/SpringAspectJ/spring-aspectj-example/src/main/resources/spring-config.xml @@ -11,66 +11,49 @@ http://www.springframework.org/schema/context/spring-context-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd"> - - - - - - - - - - - - - - - - - - - - - - - - - - + + - + + + + - - - - - + + + - - - - - + + - - + + - + + + + + -- 2.1.4