hi guys,

i have this senario and i want know if that is possible. i want to apply some aspect-oriented concept.
i want to have something like, say two classes. one extract some piece of data from xml file and use JSP to display the data.
another class/aspect that log the same data from the xml to a text file( for simplicity, but it could be a database).

so i want the logging to be the crosscutting concerns.i.e as i read the xml and display the data,the logging also happens.

how can i go about this problem?
any good links on these?

> so i want the logging to be the crosscutting concerns.i.e as i read the xml and
> display the data,the logging also happens

In layman's terms, a cross-cutting concern is simply any task or requirement which doesn't belong to any single layer and yet is required by all/some of the layers. For e.g. logging is a cross cutting concern because even though layers require that their processing be logged, it per-se isn't a responsibility of any of the layers. The business layer is concerned with implementing the business logic, the DAO layer is concerned with data access etc. Or it can be said that logging is a concern which "spans" across layers.

Fundamental to the concept of AOP is the concept of weaving, wherein the AOP implementation "weaves" aspects into your code. AFAIK, there are three ways of doing this:

  • Compile time weaving: wherein you use a special compiler to modify your existing code based on the aspects written.
  • Load time weaving: wherein you weave the aspects into your classes as they are being loaded, typically by specifying an external JVM agent implementation.
  • Runtime weaving: The approach adopted by frameworks like Spring wherein proxy classes are created to implement AOP. This is the most limited approach to AOP for obvious reasons; e.g. you can intercept on public method calls. Typical enterprise applications which use the Spring framework for assembling their components adopt this approach.

That being said, the implementation in your specific case depends on your current architecture. Are you using any framework which has built-in AOP support like Spring? Are modifications to the compiled class files by the AOP compiler permitted in your case? Do you have the control of specifying your own JVM agent?

Regarding the links, you might find these two (one & two) short tutorials useful. (registration required for second link)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.