From: gumartinm Date: Wed, 9 Nov 2011 15:07:18 +0000 (+0100) Subject: Messing around with Spring. X-Git-Url: https://git.gumartinm.name/?a=commitdiff_plain;h=4ab5e132e1e85d676c0d8e34b15365b18c7a2207;p=JavaForFun Messing around with Spring. Annotations handler and programming with Aspects. Could be useful or not, but at least it seems interesting. --- diff --git a/AndroidTetris/AndroidManifest.xml b/AndroidTetris/AndroidManifest.xml index 217d49f..edd8d88 100644 --- a/AndroidTetris/AndroidManifest.xml +++ b/AndroidTetris/AndroidManifest.xml @@ -5,9 +5,9 @@ android:versionName="1.0"> - + + android:theme="@android:style/Theme.NoTitleBar"> diff --git a/AndroidTetris/src/de/android/androidtetris/DrawView.java b/AndroidTetris/src/de/android/androidtetris/DrawView.java index c51d0f2..d140432 100644 --- a/AndroidTetris/src/de/android/androidtetris/DrawView.java +++ b/AndroidTetris/src/de/android/androidtetris/DrawView.java @@ -8,6 +8,7 @@ import android.content.Context; import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Color; +import android.view.KeyEvent; import android.view.SurfaceHolder; import android.view.SurfaceView; @@ -16,28 +17,21 @@ import android.view.SurfaceView; * */ public class DrawView extends SurfaceView { - int position = 150; private SurfaceHolder holder; private AndroidTetrisThread gameLoopThread; - private static final int TILESIZE=16; - //now for the map... private static final int MAPWIDTH=10; private static final int MAPHEIGHT=30; private static final int GREY=8; - - private AndroidTetrisThread thread; - - Bitmap[] tileArray; - Tile[][] mapMatrix; - Piece prePiece; - Piece currentPiece; + private Bitmap[] tileArray; + private Tile[][] mapMatrix; + private Piece prePiece; + private Piece currentPiece; class AndroidTetrisThread extends Thread { private DrawView view; - private boolean running = false; @@ -56,20 +50,15 @@ public class DrawView extends SurfaceView { { while (running) { - Canvas c = null; - try { - c = view.getHolder().lockCanvas(); - synchronized (view.getHolder()) - { - view.move(0, 1); - view.drawMap(c); - //view.onDraw(c); - } - }finally { - if (c != null) - view.getHolder().unlockCanvasAndPost(c); - } - } + Canvas c = view.getHolder().lockCanvas(); + synchronized (view.getHolder()) + { + view.move(0, 1); + view.drawMap(c); + //view.onDraw(c); + } + view.getHolder().unlockCanvasAndPost(c); + } } } @@ -86,53 +75,53 @@ public class DrawView extends SurfaceView { public DrawView(Context context) { super(context); - this.resetTiles(10); - for (Tile color : Tile.values() ) - { - this.loadTile(color.getColor(), color.getColorRGBA()); - } - mapMatrix = new Tile[MAPWIDTH][MAPHEIGHT+1]; - this.NewGame(); - this.newBlock(); - + + this.newGame(); + currentPiece = newBlock(); + currentPiece.x = MAPWIDTH/2-2; + currentPiece.y = -1; + prePiece = newBlock(); + prePiece.x=MAPWIDTH+2; + prePiece.y=GREY/4; + // register our interest in hearing about changes to our surface //SurfaceHolder holder = getHolder(); //holder.addCallback(this); - gameLoopThread = new AndroidTetrisThread(this); - holder = getHolder(); - holder.addCallback(new SurfaceHolder.Callback() { - @Override - public void surfaceDestroyed(SurfaceHolder holder) { - boolean retry = true; - gameLoopThread.setRunning(false); - while (retry) { - try { - gameLoopThread.join(); - retry = false; - } catch (InterruptedException e) { - - } - } - } - - @Override - public void surfaceCreated(SurfaceHolder holder) { - gameLoopThread.setRunning(true); - gameLoopThread.start(); - } - - @Override - public void surfaceChanged(SurfaceHolder holder, int format, - int width, int height) { - - } + gameLoopThread = new AndroidTetrisThread(this); + holder = getHolder(); + holder.addCallback(new SurfaceHolder.Callback() { + @Override + public void surfaceDestroyed(SurfaceHolder holder) { + boolean retry = true; + gameLoopThread.setRunning(false); + while (retry) { + try { + gameLoopThread.join(); + retry = false; + } catch (InterruptedException e) { + + } + } + } + + @Override + public void surfaceCreated(SurfaceHolder holder) { + gameLoopThread.setRunning(true); + gameLoopThread.start(); + } + + @Override + public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { + + } + }); + } - }); - } public void resetTiles(int tilecount) { tileArray = new Bitmap[tilecount]; } + public void loadTile(int key, int color) { @@ -145,9 +134,17 @@ public class DrawView extends SurfaceView { } tileArray[key] = bitmap; } + - protected void NewGame() + protected void newGame() { + this.resetTiles(10); + for (Tile color : Tile.values() ) + { + this.loadTile(color.getColor(), color.getColorRGBA()); + } + mapMatrix = new Tile[MAPWIDTH][MAPHEIGHT+1]; + //start out the map for(int x=0;x< MAPWIDTH;x++) { @@ -158,17 +155,13 @@ public class DrawView extends SurfaceView { } } - protected void newBlock() + protected Piece newBlock() { Random random = new Random(); - currentPiece = Piece.getPiece(random.nextInt(7)%7); - currentPiece.x = MAPWIDTH/2-2; - currentPiece.y = -1; + Piece piece = Piece.getPiece(random.nextInt(7)%7); - prePiece = Piece.getPiece(random.nextInt(7)%7); - prePiece.x=MAPWIDTH+2; - prePiece.y=GREY/4; + return piece; } protected void drawTile(Canvas canvas, int color, int x, int y) @@ -207,7 +200,12 @@ public class DrawView extends SurfaceView { { if (this.collisionTest(x, y)) { - this.newBlock(); + currentPiece = prePiece; + currentPiece.x = MAPWIDTH/2-2; + currentPiece.y = -1; + prePiece = newBlock(); + prePiece.x=MAPWIDTH+2; + prePiece.y=GREY/4; } else { @@ -239,6 +237,30 @@ public class DrawView extends SurfaceView { return false; } + + @Override + public boolean onKeyDown(int keyCode, KeyEvent msg) { + if (keyCode == KeyEvent.KEYCODE_DPAD_RIGHT) { + try { + AndroidTetrisThread.sleep(1000000); + } catch (InterruptedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + Canvas c =null; + c = this.getHolder().lockCanvas(); + synchronized (this.getHolder()) + { + this.move(1, 0); + this.drawMap(c); + //view.onDraw(c); + } + return true; + } + return false; + } + + @Override protected void onDraw(Canvas canvas) { canvas.drawColor(Color.BLACK); diff --git a/SpringJava/AnnotationsCustomHandler/custom-annotations-implementation/pom.xml b/SpringJava/AnnotationsCustomHandler/custom-annotations-implementation/pom.xml new file mode 100644 index 0000000..dab88d4 --- /dev/null +++ b/SpringJava/AnnotationsCustomHandler/custom-annotations-implementation/pom.xml @@ -0,0 +1,78 @@ + + + + 4.0.0 + + + custom-annotations + de.spring.example + 2.0-SNAPSHOT + + + de.spring.example + custom-annotations-implementation + 2.0-SNAPSHOT + custom-annotations-implementation + 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 + + + + org.aspectj + aspectjweaver + 1.6.12 + + + + + + + diff --git a/SpringJava/AnnotationsCustomHandler/custom-annotations-implementation/src/main/java/es/dia/pos/n2a/aspectj/annotations/AnnotationsHandler.java b/SpringJava/AnnotationsCustomHandler/custom-annotations-implementation/src/main/java/es/dia/pos/n2a/aspectj/annotations/AnnotationsHandler.java new file mode 100644 index 0000000..034a7a3 --- /dev/null +++ b/SpringJava/AnnotationsCustomHandler/custom-annotations-implementation/src/main/java/es/dia/pos/n2a/aspectj/annotations/AnnotationsHandler.java @@ -0,0 +1,33 @@ +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/AnnotationsCustomHandler/custom-annotations-implementation/src/main/java/es/dia/pos/n2a/aspectj/annotations/AspectHandler.java b/SpringJava/AnnotationsCustomHandler/custom-annotations-implementation/src/main/java/es/dia/pos/n2a/aspectj/annotations/AspectHandler.java new file mode 100644 index 0000000..0f0da3f --- /dev/null +++ b/SpringJava/AnnotationsCustomHandler/custom-annotations-implementation/src/main/java/es/dia/pos/n2a/aspectj/annotations/AspectHandler.java @@ -0,0 +1,19 @@ +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/AnnotationsCustomHandler/custom-annotations-implementation/src/main/java/es/dia/pos/n2a/aspectj/annotations/Prueba.java b/SpringJava/AnnotationsCustomHandler/custom-annotations-implementation/src/main/java/es/dia/pos/n2a/aspectj/annotations/Prueba.java new file mode 100644 index 0000000..548c5e9 --- /dev/null +++ b/SpringJava/AnnotationsCustomHandler/custom-annotations-implementation/src/main/java/es/dia/pos/n2a/aspectj/annotations/Prueba.java @@ -0,0 +1,17 @@ +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/AnnotationsCustomHandler/custom-annotations-implementation/src/main/java/es/dia/pos/n2a/aspectj/annotations/SpringContextLocator.java b/SpringJava/AnnotationsCustomHandler/custom-annotations-implementation/src/main/java/es/dia/pos/n2a/aspectj/annotations/SpringContextLocator.java new file mode 100644 index 0000000..cc452f6 --- /dev/null +++ b/SpringJava/AnnotationsCustomHandler/custom-annotations-implementation/src/main/java/es/dia/pos/n2a/aspectj/annotations/SpringContextLocator.java @@ -0,0 +1,58 @@ +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/AnnotationsCustomHandler/custom-annotations-implementation/src/main/java/es/dia/pos/n2a/aspectj/annotations/SpringStart.java b/SpringJava/AnnotationsCustomHandler/custom-annotations-implementation/src/main/java/es/dia/pos/n2a/aspectj/annotations/SpringStart.java new file mode 100644 index 0000000..b566806 --- /dev/null +++ b/SpringJava/AnnotationsCustomHandler/custom-annotations-implementation/src/main/java/es/dia/pos/n2a/aspectj/annotations/SpringStart.java @@ -0,0 +1,14 @@ +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/AnnotationsCustomHandler/custom-annotations-implementation/src/main/java/es/dia/pos/n2a/aspectj/annotations/TransactionManagerN2A.java b/SpringJava/AnnotationsCustomHandler/custom-annotations-implementation/src/main/java/es/dia/pos/n2a/aspectj/annotations/TransactionManagerN2A.java new file mode 100644 index 0000000..30e9b66 --- /dev/null +++ b/SpringJava/AnnotationsCustomHandler/custom-annotations-implementation/src/main/java/es/dia/pos/n2a/aspectj/annotations/TransactionManagerN2A.java @@ -0,0 +1,41 @@ +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/AnnotationsCustomHandler/custom-annotations-implementation/src/main/java/es/dia/pos/n2a/aspectj/annotations/TransactionalN2A.java b/SpringJava/AnnotationsCustomHandler/custom-annotations-implementation/src/main/java/es/dia/pos/n2a/aspectj/annotations/TransactionalN2A.java new file mode 100644 index 0000000..474dc63 --- /dev/null +++ b/SpringJava/AnnotationsCustomHandler/custom-annotations-implementation/src/main/java/es/dia/pos/n2a/aspectj/annotations/TransactionalN2A.java @@ -0,0 +1,14 @@ +/** + * + */ +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/AnnotationsCustomHandler/custom-annotations-implementation/src/main/resources/aop.xml b/SpringJava/AnnotationsCustomHandler/custom-annotations-implementation/src/main/resources/aop.xml new file mode 100644 index 0000000..12e9571 --- /dev/null +++ b/SpringJava/AnnotationsCustomHandler/custom-annotations-implementation/src/main/resources/aop.xml @@ -0,0 +1,11 @@ + + + + + + + + + + \ No newline at end of file diff --git a/SpringJava/AnnotationsCustomHandler/custom-annotations-implementation/src/main/resources/spring-config.xml b/SpringJava/AnnotationsCustomHandler/custom-annotations-implementation/src/main/resources/spring-config.xml new file mode 100644 index 0000000..6ea229c --- /dev/null +++ b/SpringJava/AnnotationsCustomHandler/custom-annotations-implementation/src/main/resources/spring-config.xml @@ -0,0 +1,76 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/SpringJava/AnnotationsCustomHandler/pom.xml b/SpringJava/AnnotationsCustomHandler/pom.xml new file mode 100644 index 0000000..fa98657 --- /dev/null +++ b/SpringJava/AnnotationsCustomHandler/pom.xml @@ -0,0 +1,17 @@ + + + 4.0.0 + de.spring.example + custom-annotations + 2.0-SNAPSHOT + custom-annotations + http://maven.apache.org + pom + + + + + + custom-annotations-implementation + + diff --git a/SpringJava/SpringAspectJ/pom.xml b/SpringJava/SpringAspectJ/pom.xml new file mode 100644 index 0000000..3e29b6f --- /dev/null +++ b/SpringJava/SpringAspectJ/pom.xml @@ -0,0 +1,17 @@ + + + 4.0.0 + de.spring.example + spring-aspectj + 2.0-SNAPSHOT + custom-annotations + http://maven.apache.org + pom + + + + + + spring-aspectj-example + + diff --git a/SpringJava/SpringAspectJ/spring-aspectj-example/pom.xml b/SpringJava/SpringAspectJ/spring-aspectj-example/pom.xml new file mode 100644 index 0000000..0aef4e8 --- /dev/null +++ b/SpringJava/SpringAspectJ/spring-aspectj-example/pom.xml @@ -0,0 +1,78 @@ + + + + 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 + + + + org.aspectj + aspectjweaver + 1.6.12 + + + + + + + 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 new file mode 100644 index 0000000..034a7a3 --- /dev/null +++ b/SpringJava/SpringAspectJ/spring-aspectj-example/src/main/java/es/dia/pos/n2a/aspectj/annotations/AnnotationsHandler.java @@ -0,0 +1,33 @@ +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 new file mode 100644 index 0000000..0f0da3f --- /dev/null +++ b/SpringJava/SpringAspectJ/spring-aspectj-example/src/main/java/es/dia/pos/n2a/aspectj/annotations/AspectHandler.java @@ -0,0 +1,19 @@ +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 new file mode 100644 index 0000000..548c5e9 --- /dev/null +++ b/SpringJava/SpringAspectJ/spring-aspectj-example/src/main/java/es/dia/pos/n2a/aspectj/annotations/Prueba.java @@ -0,0 +1,17 @@ +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 new file mode 100644 index 0000000..cc452f6 --- /dev/null +++ b/SpringJava/SpringAspectJ/spring-aspectj-example/src/main/java/es/dia/pos/n2a/aspectj/annotations/SpringContextLocator.java @@ -0,0 +1,58 @@ +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 new file mode 100644 index 0000000..b566806 --- /dev/null +++ b/SpringJava/SpringAspectJ/spring-aspectj-example/src/main/java/es/dia/pos/n2a/aspectj/annotations/SpringStart.java @@ -0,0 +1,14 @@ +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 new file mode 100644 index 0000000..30e9b66 --- /dev/null +++ b/SpringJava/SpringAspectJ/spring-aspectj-example/src/main/java/es/dia/pos/n2a/aspectj/annotations/TransactionManagerN2A.java @@ -0,0 +1,41 @@ +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 new file mode 100644 index 0000000..474dc63 --- /dev/null +++ b/SpringJava/SpringAspectJ/spring-aspectj-example/src/main/java/es/dia/pos/n2a/aspectj/annotations/TransactionalN2A.java @@ -0,0 +1,14 @@ +/** + * + */ +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 new file mode 100644 index 0000000..12e9571 --- /dev/null +++ b/SpringJava/SpringAspectJ/spring-aspectj-example/src/main/resources/aop.xml @@ -0,0 +1,11 @@ + + + + + + + + + + \ 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 new file mode 100644 index 0000000..6ea229c --- /dev/null +++ b/SpringJava/SpringAspectJ/spring-aspectj-example/src/main/resources/spring-config.xml @@ -0,0 +1,76 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +