Re: first steps with nanning

Jon Tirsén <[email protected]> Wed, 30 Jul 2003 16:44:52 +0200 (CEST)
Newsgroups gmane.comp.java.nanning.devel
Message-ID <[email protected]>
Yes that is most certainly possible. You should really
start using the AspectSystem stuff instead. That makes
it possible to modularize your aspects. So to have an
aspect that adds a singleton mixin I would do:

public class ArticleContainerAspect implements Aspect
{
  Pointcut objectsHavingArticleContainer =
P.or(P.isClass(ClassHavingArticle.class),
     P.isClass(SecondClassHavingArticle.class));

  ArticleContainer singletonArticleContainer = new
ArticleContainerImpl();

  public void introduce(AspectInstance instance) {
    objectsHavingArticleContainer.introduce(new
Mixin(ArticleContainer.class,
singletonArticleContainer);
  );

  public void advise(AspectInstance instance) {}
}

In your factory you would keep a singleton
AspectSystem and add the aspect:
private static AspectSystem aspectSystem;

static {
  aspectSystem.addAspect(new
FindTargetMixinAspect("Impl")); // this will find the
implementation of the main class as "Class" ->
"ClassImpl"
  aspectSystem.addAspect(new
ArticleContainerAspect());
}

To actually instantiate an object you'd do:
ClassHavingArticle classHavingArticle =
aspectSystem.newInstance(ClassHavingArticle.class);

>         AspectInstance instance = new
> AspectInstance();
>         Mixin mixin = new
> Mixin(ArticleContainer.class, new 
> ArticleContainerImpl());
>         instance.addMixin(mixin);

This will work too, but when the system starts to grow
it is definitely worthwhile to learn the
AspectSystem-stuff.

The Pointcut-stuff (Pointcut and the P-class) is still
a little bit new so everything isn't completely worked
out.

Hope that helps, good luck!
Jon

 --- Christoph Sturm <[email protected]> skrev: >
Hi jon!
> 
> I am trying to port my app from AW to nanning. In
> aspectwerkz, I can also 
> have singleton mixins. Does that work in nanning
> too? For example, can I 
> write it like this:
> 
>         AspectInstance instance = new
> AspectInstance();
>         Mixin mixin = new
> Mixin(ArticleContainer.class, new 
> ArticleContainerImpl());
>         instance.addMixin(mixin);
> 
>         AspectInstance instance2 = new
> AspectInstance();
>         instance2.addMixin(mixin);
> 
> 
> onw instance and instance2 share the same instance
> of the mixin. will that 
> work?
> 
> thx
>  chris
> 
> 
> 
> -- 
> Using M2, Opera's revolutionary e-mail client:
http://www.opera.com/m2/ 

_____________________________________________________
Gå före i kön och få din sajt värderad på nolltid med Yahoo! Express
Se mer på: http://se.docs.yahoo.com/info/express/help/index.html