Re: first steps with nanning
Jon Tirsén <[email protected]> Thu, 31 Jul 2003 12:14:28 +0200 (CEST)
| Newsgroups | gmane.comp.java.nanning.devel |
|---|---|
| Message-ID | <20030731101428.94876.qmail__12312.0010867298$1059646527@web40605.mail.yahoo.com> |
--- Christoph Sturm <[email protected]> skrev: > hi jon! > > thanks for helping me out. It really seems that > theres almost no > documentation for nanning, but thats not a problem, > because the code looks > very clear. But I still have some more questions: No problem at all. As I said, I promise I will answer any question until proper documentation is in there. > for example this class: > > public class DirectoryEntryAspect implements Aspect > { > Pointcut objectsHavingDirectoryEntryAttibute = > P.classAttribute("directoryEntry"); > > > public void introduce(AspectInstance > aspectInstance) { > > objectsHavingDirectoryEntryAttibute.introduce(aspectInstance, > new > Mixin(DirectoryEntry.class, new > DirectoryEntryImpl())); > } > > public void advise(AspectInstance > aspectInstance) { > //To change body of implemented methods use > Options | File > Templates. > } > } > > I think introduce is called for every object that > the aspectsystem creates, > and i decide with the pointcut where to apply it. > But with the code above I > create a new DirectoryEntryImpl every time the > function is called, and not > only when the introduction really is applied. Is > there a better way to > write this? Actually that *is* documented. :-) http://nanning.snipsnap.org/space/Config Basically you put an if(pointcut.introduceOn(instance)) around there. Which is probably better. > > With aspects you mean mixins and interceptors > right? > > You can do the same thing if you use AspectSystem. > You > > just do aspectSystem.newInstance(obj.getClass()). > > ok, i will try that. But it seems strange to me that > obj.getClass() doesnt > return the classIdentifier, but Proxy$0. Does it > work anyway? Ah. Ooops... You're absolutely right, it probably won't work. I'd do the following then instead: aspectSystem.newInstance(Aspects.getAspectInstance(obj).getClassIdentifier()); _____________________________________________________ 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