KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > aop > microcontainer > beans > AspectBinding


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

22 package org.jboss.aop.microcontainer.beans;
23
24 import org.jboss.aop.AspectManager;
25 import org.jboss.aop.advice.AdviceBinding;
26 import org.jboss.aop.advice.AdviceFactory;
27 import org.jboss.aop.advice.AspectDefinition;
28 import org.jboss.logging.Logger;
29 import org.jboss.util.id.GUID;
30
31 /**
32  * An AspectBinding.
33  *
34  * @author <a HREF="adrian@jboss.com">Adrian Brock</a>
35  * @version $Revision: 44470 $
36  */

37 public class AspectBinding
38 {
39    private static final Logger log = Logger.getLogger(AspectBinding.class);
40    
41    protected AspectManager manager;
42    
43    protected String JavaDoc name = GUID.asString();
44    
45    protected String JavaDoc pointcut;
46    
47    protected AspectDefinition aspect;
48    
49    protected String JavaDoc method = "invoke";
50    
51    /**
52     * Get the aspectDefinition.
53     *
54     * @return the aspectDefinition.
55     */

56    public AspectDefinition getAspect()
57    {
58       return aspect;
59    }
60
61    /**
62     * Set the aspectDefinition.
63     *
64     * @param aspectDefinition The aspectDefinition to set.
65     */

66    public void setAspect(AspectDefinition aspect)
67    {
68       this.aspect = aspect;
69    }
70
71    /**
72     * Get the manager.
73     *
74     * @return the manager.
75     */

76    public AspectManager getManager()
77    {
78       return manager;
79    }
80
81    /**
82     * Set the manager.
83     *
84     * @param manager The manager to set.
85     */

86    public void setManager(AspectManager manager)
87    {
88       this.manager = manager;
89    }
90
91    /**
92     * Get the method.
93     *
94     * @return the method.
95     */

96    public String JavaDoc getMethod()
97    {
98       return method;
99    }
100
101    /**
102     * Set the method.
103     *
104     * @param method The method to set.
105     */

106    public void setMethod(String JavaDoc method)
107    {
108       this.method = method;
109    }
110
111    /**
112     * Get the pointcut.
113     *
114     * @return the pointcut.
115     */

116    public String JavaDoc getPointcut()
117    {
118       return pointcut;
119    }
120
121    /**
122     * Set the pointcut.
123     *
124     * @param pointcut The pointcut to set.
125     */

126    public void setPointcut(String JavaDoc pointcut)
127    {
128       this.pointcut = pointcut;
129    }
130
131    public void start() throws Exception JavaDoc
132    {
133       if (pointcut == null)
134          throw new IllegalArgumentException JavaDoc("Null pointcut");
135       if (manager == null)
136          throw new IllegalArgumentException JavaDoc("Null manager");
137       if (aspect == null)
138          throw new IllegalArgumentException JavaDoc("Null aspect definition");
139       AdviceBinding binding = new AdviceBinding(name, pointcut, null);
140       binding.addInterceptorFactory(new AdviceFactory(aspect, method));
141       manager.addBinding(binding);
142       log.debug("Bound binding " + name);
143    }
144    
145    public void stop() throws Exception JavaDoc
146    {
147       manager.removeBinding(name);
148    }
149
150    public void uninstall() throws Exception JavaDoc
151    {
152       stop();
153    }
154    
155    public void rebind(AspectDefinition aspect) throws Exception JavaDoc
156    {
157       this.aspect = aspect;
158       stop();
159       start();
160    }
161 }
162
Popular Tags