[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
| Re: [aspectj-dev] Getting a local variable from the caller to the	advice | 
Thanks Dean. But guess this would not solve the problem because the code injection is before the execute method. I guess I could still achieve without using AspectJ by using a decorator pattern where the code injection is before the execute method call.
Something like:
MyCommandWithPreProcessor{
   MyCommand cmd = new MyCommand();
   execute(Map CacheManager)
   {
         preProcessor(CacheManager);
         cmd.execute(CacheManager);
    }
 
   private void preProcessor(Map CacheManager){
      //Do Preprocessing logic here...
   }
}
Problem is when I want to inject code just before the Service Call through the ServiceUtil.getService
(). All my commands extend an interface Command with an execute(Map) method.
public class MyCommand implements Command{
	public void execute(Map CacheManager)
	{
		//code for getting objects, values from cache
		......
		.....  
		CallHookerPreProcessor(
this.class, CacheManager );  //Need to inject this PreProcessor
		//Code for calling service .Invoke EJB etc.
Service ser = (Service)ServiceUtil.getService("Name");
		ser.MYServiceMethod
(Param1, Param2);
...
		...
...
	 } 	
}On 5/31/07, Dean Wampler <dean@xxxxxxxxxxxxxxxxxxxxx
> wrote:How about this; change you pointcut to match calls to execute, then you can add the cachemanager as an argument to the pointcut and the advice. Something like
pointcut callExecuteThatCallsGetServiceUtil(Map cacheManager):
	call (public void MyCommand.execute(Map)) && args(cacheManager);
before (Map cacheManager): callExecuteThatCallsGetServiceUtil(cacheManager) {
        Class Command = thisJoinPoint.getSourceLocation ().getWithinType();    
        IPreProcessor preprocessor =  (IPreProcessor)PrePostProcessorResolver.getPreProcessor(Command);
        preprocessor.preprocess( cachmanager);
    }
dean
On May 31, 2007, at 3:56 AM, Ingudam Manoranjan wrote:
I have the following scenario:
public class MyCommand {
    public void execute(Map cachmanager) {
        System.out.println("I am in MyCommand: Before Service Call"); 
        ServiceUtil.getService ("MyService");
        System.out.println("I am in MyCommand: After Service Call");
    }
public class ServiceUtil {
    public static String getService(String serviceName){
        String serviceObject = "Static Service"; 
        System.out.println("Service invoked is : "+ serviceName);
        return serviceObject;
    }
}
I want to add Preprocessing beforethe Service Call. 
public aspect ServiceUtilAspect { 
    
    pointcut callServiceUtil():
        call (public static String 
ServiceUtil.getService(String));
    before() :callServiceUtil()
    {
        Class Command = thisJoinPoint.getSourceLocation ().getWithinType();    
        IPreProcessor preprocessor =  (IPreProcessor)PrePostProcessorResolver.getPreProcessor(Command);
        //Map cachmanager = new HashMap();
        preprocessor.preprocess( cachmanager);
    }
}
I want to be get the cachmanager from the Command. Is it possible using Aspectj? Can anyone help?
 
_______________________________________________
aspectj-dev mailing list
 
 
Dean Wampler, Ph.D.
I want my tombstone to say:
  Unknown Application Error in Dean Wampler.exe.
  Application Terminated.
      [Okay]        [Cancel]
  
_______________________________________________
aspectj-dev mailing list
aspectj-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-dev