Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
RE: [aspectj-users] adding a import statement into a JAR file.

Hi Trishan,

Ahhh, I can see what you're trying to do. It does appear to be a misunderstanding of what AspectJ can do for you. I believe that you don't need to add the import at all, in fact the class is probably not needed. It looks like you simply need an aspect like the example below:

<EXAMPLE CODE>

// Place any imports for your concrete logging classes

public aspect SimpleExampleLogging 
{

   // Initialise anything you want to for logging clases here, these can then be used
   // throughout the advice within this aspect as you were using in your example class

   // The specification of the AspectLoggerTestbed class is probably incorrect for your design.
   // It should be pointing at the classes and methods you want to log from in your actual
   // business classes. But it's included here as it's the only class I know for sure you have :)
   pointcut log() : execution(void AspectLoggerTestbed.someMethod(..));

   pointcut logException() : handler(Throwable +);

   // The !within definition is not needed in this example, however it is a bit of good practice
   // to protect your aspect from recursion problems as you change the specification of the
   // log() pointcut to specify your application classes.
   before() : log() && !within(SimpleExampleLogging +)
   {
     // This advice would be used for general logging
     // Use any concrete logging calls here
   }

   before() : logException() && !within(SimpleExampleLogging +)
   {
     // This advice would be used for exception logging
     // Use any concrete logging calls here
   }

}

</EXAMPLE CODE>

That should hopefully do something like what you would want to do. But the first thing I would look at is your understanding of how AspectJ can be used to apply logic to existing applications, as this is one of it's definite powers. Rather than declaring a specific class and amending it's imports, the entire logging behaviour and it's rules for application can be modularized within a concrete aspect like the one above and then the logging applied at build time.

But the way, if you are logging in exactly the same ways and because both advices are 'before()' advice you could then combine the advice into one. But that's up to you :)

Have Fun and hope this helps,

Russ
 
On Friday, November 14, 2003, at 09:32AM, Trishan de Lanerolle <tlanerolle@xxxxxxxxxxx> wrote:

>Hi Russ, 
>I think you have the correct understanding. I think I'm looking at this incorrectly. I am working from the architects requirements. I haven't fully come to terms with using AspectJ. The whole concept of AOP was new to me before I was introduced to it, when I took over from the previous person assigned to this research. The problem I have to solve or at least show it could be done is as shown. Any advice or inputs would be appricated.
>Thank you
>Trishan
>
>
>//  <IMPORT>    
>/*
>* [1] the following dummy import statement is to be replaced by:
>*    --> import com.sys.logging.*; 
>*/
>import java.lang.ref.*;
>//  </IMPORT>
>
>/**
> * 
> *
> * testbed for replacing and inserting code via aspects
> * ..to confirm expected results before applying the aspect to source targets
> */
>public class AspectLoggerTestbed {
>	
>
>	
>
>	public void someMethod() {
>
>        //  <LOG_VARIABLE>    
>	/*
>	 *   [2] create a variable that holds a reference to the derived logger
>	 *    --> Logger LOG = Loggers.assessLogger(this.class);
>	 */
>	 //  <LOG_VARIABLE>
>
>		try {} catch (Exception e) {
>			// <EXCEPTION> a block that contains an exception
>			/* 
>			 * [3] this syntax is used to log the stack trace
>			 * --> LOG.debug("..exception caught", new Throwable());
>			 */
>			// </EXCEPTION>      
>		}
>
>	}
>
>}
>
>
>
>
>
>-----Original Message-----
>From: Russell Miles [mailto:russellmiles@xxxxxxx]
>Sent: Friday, November 14, 2003 9:57 AM
>To: aspectj-users@xxxxxxxxxxx
>Subject: RE: [aspectj-users] adding a import statement into a JAR file.
>
>
>
>Hi Trishan,
>
>I'm not sure I quite understand why you need to add an import? This is a pretty standard use of aspectJ in my experience and I've always done it by using around advice on the execution or call to the existing logging mechanisms (dependant on where I want to join, or where I am allowed to join for that matter due to licenses). This way the existing logging mechanism is still there but I have overriden it with the new mechanisms. But this approach doesn't lead me to needed to add import statements as the aspect itself then encapsulates the new logging logic, or in turn makes the onward call to the logging mechanism of choice.
>
>Am I not understanding something on this ?
>
>Cheers
>
>Russ Miles
>
>
>
>On Friday, November 14, 2003, at 03:49AM, Trishan de Lanerolle <tlanerolle@xxxxxxxxxxx> wrote:
>
>>Why do you need it?
>>We are looking into using AspectJ to replace a existing loging system (Log4J) with our custom built one, may be implimented using the around advice. (any "advice" you may have on doing this would be appriciated)We would identify the method calls and replace it with our own ones. We are using the JAR file as an experiement, we have the source files to play with as well. However when the program goes into 100-1000s files adding a single statement in becomes tedious to say the least. Its a task given by the architects to try out AspectJ in their projects.
>>Thanks
>>Trishan
>>
>>
>>-----Original Message-----
>>From: Wes Isberg [mailto:wes@xxxxxxxxxxxxxx]
>>Sent: Thursday, November 13, 2003 11:42 PM
>>To: aspectj-users@xxxxxxxxxxx
>>Subject: Re: [aspectj-users] adding a import statement into a JAR file.
>>
>>
>>AspectJ doesn't do that.  Why do you need it?
>>
>>Wes
>>
>>Trishan de Lanerolle wrote:
>>>             
>>> Questions
>>> How can I add a new package import for specific java classes contained within a JAR file using aspectJ.
>>> I think it has to be done with around advice. However I am not replacing anything just adding the line. I appologise in advance if the answer is obvious. I am new at this and I'm short for time and thought getting your input on this would help. 
>>> Thank you
>>> Trishan
>>> _______________________________________________
>>> aspectj-users mailing list
>>> aspectj-users@xxxxxxxxxxx
>>> http://dev.eclipse.org/mailman/listinfo/aspectj-users
>>>
>>
>>_______________________________________________
>>aspectj-users mailing list
>>aspectj-users@xxxxxxxxxxx
>>http://dev.eclipse.org/mailman/listinfo/aspectj-users
>>_______________________________________________
>>aspectj-users mailing list
>>aspectj-users@xxxxxxxxxxx
>>http://dev.eclipse.org/mailman/listinfo/aspectj-users
>>
>>
>_______________________________________________
>aspectj-users mailing list
>aspectj-users@xxxxxxxxxxx
>http://dev.eclipse.org/mailman/listinfo/aspectj-users
>_______________________________________________
>aspectj-users mailing list
>aspectj-users@xxxxxxxxxxx
>http://dev.eclipse.org/mailman/listinfo/aspectj-users
>
>


Back to the top