[jboss-user] [JBoss AOP Users] - Re: PLEASE answer me I really need your help

souma do-not-reply at jboss.com
Thu Oct 1 16:00:48 EDT 2009


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)"


View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4258278#4258278

Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4258278



More information about the jboss-user mailing list