-
1. Re: PLEASE answer me I really need your help
kabirkhan Oct 1, 2009 2:21 PM (in response to souma)In the documentation and tutorials
-
2. Re: PLEASE answer me I really need your help
souma Oct 1, 2009 2:47 PM (in response to souma)yes I found it but it is not complete .. how can i manage it via a Main class for example (I know it it is a bad question!!!but I'm beginner)
PS: i am sorry for my bad english ..please help me -
3. Re: PLEASE answer me I really need your help
souma Oct 1, 2009 4:00 PM (in response to souma)example I want to translate the pattern memnto (from aspectj) to jboss aop
package MEMENTO; public class Initiateur { protected int valeur = 0; public void incrementation() { valeur++; } public void affichage() { System.out.println("La valeur courante est : " + valeur); } public void setMemento(InitiateurI o, Memento m){} }
package MEMENTO; public class Initiateur1Memento implements InitiateurI{ public Initiateur1Memento (){ } public Memento createMementoFor(InitiateurI o) { if (o instanceof Initiateur) { Memento m = new Memento() { private Integer state; public void setetat(Integer state) { this.state = (Integer) state; } public int getState(){ return state; } }; m.setetat(new Integer(((Initiateur)o).valeur)); return m; } else { throw new MementoException("Initialisateur invalide"); } } public void setMemento(InitiateurI o, Memento m) { if (o instanceof Initiateur) { Integer integer = (Integer) m.getState(); ((Initiateur)o).valeur = integer.intValue(); } else { throw new MementoException("Initialisateur invalide"); } } }
package MEMENTO; public interface InitiateurI { public Memento createMementoFor(InitiateurI o); public void setMemento(InitiateurI o, Memento m); }
package MEMENTO; public interface Memento { public void setetat(Integer state); public int getState(); }
public class Main { public static void main(String[] args) { Memento memento1 = null; Initiateur initiateur = new Initiateur(); for (int i=1; i<=5; i++) { if (i==1){memento1= Initiateur1Memento.createMementoFor(initiateur);} else {memento1.setetat(initiateur.valeur);} initiateur.incrementation(); initiateur.affichage(); } System.out.println(""); System.out.println(" <- annuler"); Initiateur1Memento.setMemento(initiateur, memento1); initiateur.affichage(); } }
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <aop> <introduction expr="has(* *->incrementation())"> <mixin> <interfaces> MEMENTO.InitiateurI </interfaces> <class>MEMENTO.Initiateur1Memento</class> <construction>new MEMENTO.Initiateur1Memento(this)</construction> </mixin> </introduction> </aop>
eclipse tells me 2 error in the Main
line 14 "The method createMementoFor(InitiateurI) in the type Initiateur1Memento is not applicable for the arguments (Initiateur)"
line23 "The method setMemento(InitiateurI, Memento) in the type Initiateur1Memento is not applicable for the arguments (Initiateur, Memento)" -
4. Re: PLEASE answer me I really need your help
flavia.rainone Oct 2, 2009 8:33 AM (in response to souma)The point is that you are trying to achieve something with a framework that you used to do with a language extension.
Given AspectJ is a language extension of Java, its compiler would know to recognize that Initiateur now implements InitiateurI. JBoss AOP is not an extension of Java, it is a framework. Hence you have to use javac standard compiler to compile your code; javac won't recognize that after compiling you are going to use a tool that makes Initiateur implemnt InitiateurI. So, you have to use a casting:... if (i==1){memento1= Initiateur1Memento.createMementoFor((InitiateurI) initiateur);} ... Initiateur1Memento.setMemento((InitiateurI) initiateur, memento1); ...
-
5. Re: PLEASE answer me I really need your help
souma Oct 2, 2009 11:35 AM (in response to souma)Merci beaucoup(thank you very much) ... it work:)