Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: package annotations -- was Re: [aspectj-users] Some questions/suggestions about AspectJ

Hi Wes,

First of all, sorry for putting all three questions in one single e-mail. I will do what you asked me to for future e-mails :)

Citando Wes Isberg <wes@xxxxxxxxxxxxxx>:

So, my question is: would it be possible to use AspectJ
to declare classes on packages?

I'm not sure what you're asking.  You can declare classes
in Java, so you can do it in AspectJ.

I would like to know if it is possible to "generate" one class in a certain package. Is it? Let us say we have the package "mypackage" and we want to "insert" or generate the class "MyClass" in it. Can we do something like that?

Nor am I sure why you're trying to defeat Java's
incremental class loading.  If no class in that package is
ever loaded, why worry about permissions for that package?

Well, actually, we declare the permissions in one place but we use them anywhere. For example, we can have the declaration of some permissions in a package "mypackage":

// The permissions will have the fully qualified name, like "" // and ""
@DeclarePermission(permissions = {"foo", "bar"})
package mypackage;

Then, in one class we might refer to them by using the fully qualified name:

package another;

public class A {

 @AccessControlled(requires = "")
 public void foo() {


If there were no classes being loaded in the package "mypackage", then it would not be possible to detect the permission "" declared in it, simply because it hadn't been loaded yet. I hope I had made myself clearer this time.



Paulo Zenida

On Thu, 15 Jun 2006 21:38:49 +0100
Paulo Alexandre Corigo Zenida <paulo.zenida@xxxxxxxx>
Hello there,

I have a few questions and suggestions that I would like
to share with the AspectJ community.

First of all, I would like to know why it isn't possible
to inject exceptions in methods. I know it is not
possible to make an advice throw an exception other than
the ones in the contract of a method, which makes sense.
However, why can't we make a method, annotated with a
certain annotation, for example, throw a checked
exception, through ITD? I am working on my master degree
thesis project, about access control, and I am using
annotations to specify the points in the code that
require some kind of permission. This way, I am doing
something like this on methods:

@AccessControlled(requires = "foo")
public void foo() {

In order for client code to be able to deal with the lack
of permissions by the principals, I would like to make it
possible to throw a checked exception (at the moment, I
am just throwing an unchecked exception, which is not
what we want here!). Shouldn't this be possible?
Something like:

declare throws :

Second: I would also like to know why isn't possible to
extend concrete aspects. I have one situation in which I
would like to make the aspect application mandatory (a
concrete aspect) but, at the same time, make it possible
to "refine" the pointcuts definitions in it (an abstract
aspect). More concretely, I have created an aspect which
enforces some policies, which must always be applied.
However, I would like to make it possible to switch from
warning to error messages, as wanted. Example:

public aspect MyAspect {

  public final pointcut all() : !none();

  public final pointcut none();

  public pointcut declareWarningScope() :    all();

  public final pointcut declareErrorScope() :

  declare warning :    declareWarningScope() && ... :
"Warning: Blabla";
   declare error :    declareErrorScope() && ... :
"Error: Blabla";


This aspect should always be applied but I would like to
make it possible to redefine the declareWarningScope()
pointcut. However, I cannot extend that aspect so I have
a problem! To fix this, I have created a workaround,
together with my thesis advisor (Manuel Menezes de
Sequeira), which I would like to share and, maybe, get
some feedback about it.

The idea is that we put the pointcuts definitions (the
declareWarningScope and declareErrorScope pointcuts) in a
class, which the aspect extends (not an interface so that
the declareErrorScope() can be final):

public abstract class MyClass {
   public pointcut declareWarningScope() :

  public final pointcut declareErrorScope() :


public aspect MyAspect extends MyClass {

  declare warning :    declareWarningScope() && ... :
"Warning: Blabla";
   declare error :    declareErrorScope() && ... :
"Error: Blabla";


Then, when we make the project available for others, we
create two JAR files: one with everything, except the
class MyClass, jar-base.jar, and another one with just
the class MyClass, jar-ext.jar.

When we want to refine the pointcuts definition, we don't
use the second JAR, which will cause a compile time
error, due to the unexistence of the class MyClass. That
forces the user to create that class in the specified
package, where he may define the pointcut as wanted. If
he does not want a redefinition of those pointcuts, he
simply uses both JAR's. What do you think about this
solution? Is there one better for this problem?

Finally, I am using annotations in packages to declare
the permissions for all members of that same package.
This way, I try to verify if the permission requirements
for a certain method have been declared or not in a
certain class or package. However, when those are
declared in packages, I cannot guarantee that the package
have been actually loaded: only if a class in that
package have been loaded, right? This way, I force a
class to be loaded in a certain package. The convention
was that one aspect in my project, when instantiated, is
passed a list of classes that should be instantiated, so
that the packages and their annotations are loaded and
stored in that aspect. However, if we have a class A in
the package pt.iscte but no class in the package pt, the
package pt will not be recognized. So, my question is:
would it be possible to use AspectJ to declare classes on
packages? If that would be possible, I would not have to
create a class myself but I could use AspectJ to create
it, and then pass it to that Aspect that loads the

I hope I have made myself clear and sorry for the mail

Thanks for your attention and interest.


Paulo Zenida

Mensagem enviada usando o IMP (Internet Messaging

aspectj-users mailing list

aspectj-users mailing list

Mensagem enviada usando o IMP (Internet Messaging Program).

Back to the top