KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tirsen > nanning > jelly > AspectTag


1 /*
2  * Nanning Aspects
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7 package com.tirsen.nanning.jelly;
8
9 import com.tirsen.nanning.definition.AspectClass;
10 import com.tirsen.nanning.definition.AspectDefinition;
11 import com.tirsen.nanning.definition.AspectRepository;
12 import org.apache.commons.jelly.JellyTagException;
13 import org.apache.commons.jelly.TagSupport;
14 import org.apache.commons.jelly.XMLOutput;
15
16 /**
17  * TODO document AspectTag
18  *
19  * <!-- $Id: AspectTag.java,v 1.10 2003/05/11 13:40:52 tirsen Exp $ -->
20  *
21  * @author $Author: tirsen $
22  * @version $Revision: 1.10 $
23  */

24 public class AspectTag extends TagSupport {
25     protected AspectDefinition aspectDefinition;
26     private Class JavaDoc aspectRef;
27
28     public void setInterface(String JavaDoc interfaceClass) throws ClassNotFoundException JavaDoc {
29         this.aspectRef =
30                 Thread.currentThread().getContextClassLoader().loadClass(interfaceClass);
31     }
32
33     public AspectDefinition getAspectDefinition() {
34         return aspectDefinition;
35     }
36
37     public void doTag(XMLOutput xmlOutput) throws JellyTagException {
38         // find repository and class where I'm contained
39
AspectRepository aspectRepository = null;
40         AspectClass aspectClass = null;
41         AspectRepositoryTag aspectRepositoryTag =
42                 (AspectRepositoryTag) findAncestorWithClass(AspectRepositoryTag.class);
43         if (aspectRepositoryTag != null) {
44             aspectRepository = aspectRepositoryTag.getAspectRepository();
45         }
46         AspectClassTag aspectClassTag = (AspectClassTag) findAncestorWithClass(AspectClassTag.class);
47         if (aspectClassTag != null) {
48             aspectClass = aspectClassTag.getAspectClass();
49         }
50
51         // find or instantiate aspect
52
if (aspectRef == null) {
53             aspectDefinition = new AspectDefinition();
54         } else {
55             aspectDefinition = aspectRepository.getAspect(aspectRef);
56         }
57
58         invokeBody(xmlOutput);
59
60         // addLink aspect to class or define in repository
61
if (aspectClass != null) {
62             aspectClass.addAspect(aspectDefinition);
63         } else if (aspectRepository != null) {
64             aspectRepository.defineAspect(aspectDefinition);
65         } else {
66             throw new IllegalStateException JavaDoc("Must be contained within 'aspect-repository' or 'class'.");
67         }
68     }
69
70     public void addInterceptor(Class JavaDoc interceptorClass) {
71         aspectDefinition.addInterceptor(interceptorClass);
72     }
73
74     public void setAspectInterface(Class JavaDoc interfaceClass) {
75         aspectDefinition.setInterface(interfaceClass);
76     }
77
78     public void setTarget(Class JavaDoc targetClass) {
79         aspectDefinition.setTarget(targetClass);
80     }
81 }
82
Popular Tags