KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.util.Iterator JavaDoc;
25 import java.util.List JavaDoc;
26
27 import org.jboss.aop.AspectManager;
28 import org.jboss.aop.advice.AdviceBinding;
29 import org.jboss.aop.advice.AspectDefinition;
30 import org.jboss.aop.advice.ScopedInterceptorFactory;
31 import org.jboss.util.id.GUID;
32
33 public class StackBinding
34 {
35    protected String JavaDoc name = GUID.asString();
36
37    protected AspectManager manager;
38    
39    protected String JavaDoc pointcut;
40
41    protected List JavaDoc advices;
42    
43    /**
44     * Get the manager.
45     *
46     * @return the manager.
47     */

48    public AspectManager getManager()
49    {
50       return manager;
51    }
52
53    /**
54     * Set the manager.
55     *
56     * @param manager The manager to set.
57     */

58    public void setManager(AspectManager manager)
59    {
60       this.manager = manager;
61    }
62
63    /**
64     * Get the pointcut.
65     *
66     * @return the pointcut.
67     */

68    public String JavaDoc getPointcut()
69    {
70       return pointcut;
71    }
72
73    /**
74     * Set the pointcut.
75     *
76     * @param pointcut The pointcut to set.
77     */

78    public void setPointcut(String JavaDoc pointcut)
79    {
80       this.pointcut = pointcut;
81    }
82
83    /**
84     * Get the advices.
85     *
86     * @return the advices.
87     */

88    public List JavaDoc getAdvices()
89    {
90       return advices;
91    }
92
93    /**
94     * Set the advices.
95     *
96     * @param advices The advices to set.
97     */

98    public void setAdvices(List JavaDoc advices)
99    {
100       this.advices = advices;
101    }
102
103    public void start() throws Exception JavaDoc
104    {
105       if (pointcut == null)
106          throw new IllegalArgumentException JavaDoc("Null pointcut");
107       if (manager == null)
108          throw new IllegalArgumentException JavaDoc("Null manager");
109       if (advices == null || advices.size() == 0)
110          throw new IllegalArgumentException JavaDoc("No advices");
111       AdviceBinding binding = new AdviceBinding(name, pointcut, null);
112       for (Iterator JavaDoc i = advices.iterator(); i.hasNext();)
113       {
114          AspectDefinition aspect = (AspectDefinition) i.next();
115          binding.addInterceptorFactory(new ScopedInterceptorFactory(aspect));
116       }
117       manager.addBinding(binding);
118    }
119    
120    public void stop() throws Exception JavaDoc
121    {
122       manager.removeBinding(name);
123    }
124 }
125
Popular Tags