Results 1 to 7 of 7

Thread: Changing method signature through AOP

  1. #1

    Default Changing method signature through AOP

    Is it possible to change a methods signature (add an optional argument) using AOP. I need to wrap by service methods in an advice that requires an additional argument that is not required by the method itself but it is provider by (some) consumers of that method.

    If AOP is not the way to go is there another way?

    Thanks,
    Lili
    cheers,
    Lili

  2. #2
    Join Date
    Nov 2007
    Posts
    420

    Default

    Quote Originally Posted by lnader View Post
    Is it possible to change a methods signature (add an optional argument) using AOP. I need to wrap by service methods in an advice that requires an additional argument that is not required by the method itself but it is provider by (some) consumers of that method.
    If AOP is not the way to go is there another way?
    Thanks,
    Lili
    how will an argument that is not provided by the interface be "provided by (some) consumers of that method"?

  3. #3

    Default

    I should have mentioned this. The "some" consumers are RPCs through flex and blazeDS.
    cheers,
    Lili

  4. #4
    Join Date
    Nov 2007
    Posts
    420

    Default

    Quote Originally Posted by lnader View Post
    I should have mentioned this. The "some" consumers are RPCs through flex and blazeDS.
    again - how will an argument that is not provided by the interface be "provided by (some) consumers of that method"?

  5. #5

    Default

    Here's my enviroment in more detail. I have business services that being used by local classes running inside the same JVM AND by remote consumers. I need to include a version number (as an argument) in the remote API call (which is not needed for local calls). On the remote calls the method signature is obviously not checked until runtime. I was hoping to wrap these calls with an @Before advice that will do the version checking and fail/forward accordingly.

    I am already aware of the following options but don't like them (maintenance nightmare):

    1. Overload each method to add an additional argument.
    2. Add an optional argument to all methods
    3. Create a second set of interfaces and services that pretty much mirror the existing services. In other words wrapper classes.

    So I was looking for other alternatives in particular a runtime solution hence looking at AOP.
    cheers,
    Lili

  6. #6
    Join Date
    Jul 2010
    Location
    Venice, Italy
    Posts
    709

    Default

    Spring's AOP works through proxies (jdk interface proxies or cglib class proxies) so it won't suit your particular needs (if I understood them correctly). Without entering into details, I think AspectJ's load-time weaving can let you achieve something close to what you need to do.

  7. #7
    Join Date
    Nov 2007
    Posts
    420

    Default

    Quote Originally Posted by lnader View Post
    Here's my enviroment in more detail. I have business services that being used by local classes running inside the same JVM AND by remote consumers. I need to include a version number (as an argument) in the remote API call (which is not needed for local calls). On the remote calls the method signature is obviously not checked until runtime. I was hoping to wrap these calls with an @Before advice that will do the version checking and fail/forward accordingly.

    I am already aware of the following options but don't like them (maintenance nightmare):

    1. Overload each method to add an additional argument.
    2. Add an optional argument to all methods
    3. Create a second set of interfaces and services that pretty much mirror the existing services. In other words wrapper classes.

    So I was looking for other alternatives in particular a runtime solution hence looking at AOP.
    Why don't you use varargs in your methods like:

    Code:
    public Object serviceMethod(Object param1, Object param2, Object... optionalArguments)
    You won't have maintenance nightmare and you can pass in any number of optional parameters (if more are needed later)...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •