KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > aop > microcontainer > junit > AOPMicrocontainerTestDelegate


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.junit;
23
24 import java.net.URL JavaDoc;
25 import java.util.Iterator JavaDoc;
26
27 import org.jboss.aop.AspectXmlLoader;
28 import org.jboss.test.kernel.junit.MicrocontainerTestDelegate;
29
30 import EDU.oswego.cs.dl.util.concurrent.CopyOnWriteArrayList;
31
32 /**
33  *
34  * An AOPMicrocontainerTestDelegate.
35  *
36  * @author <a HREF="adrian@jboss.com">Adrian Brock</a>
37  * @version $Revision: 58245 $
38  */

39 public class AOPMicrocontainerTestDelegate extends MicrocontainerTestDelegate
40 {
41    /** The deployed urls */
42    private static final CopyOnWriteArrayList urls = new CopyOnWriteArrayList();
43
44    /**
45     * Create a new AOPMicrocontainerTestDelegate.
46     *
47     * @param clazz the class
48     * @throws Exception for any error
49     */

50    public AOPMicrocontainerTestDelegate(Class JavaDoc clazz) throws Exception JavaDoc
51    {
52       super(clazz);
53    }
54
55    public void setUp() throws Exception JavaDoc
56    {
57       super.setUp();
58       log.debug("Security enabled: " + enableSecurity);
59    }
60
61    
62
63    protected void deploy() throws Exception JavaDoc
64    {
65       String JavaDoc testName = clazz.getName();
66       testName = testName.replace('.', '/') + "-aop.xml";
67       URL JavaDoc url = clazz.getClassLoader().getResource(testName);
68       if (url != null)
69          deployAOP(url);
70       else
71          log.debug("No test specific deployment " + testName);
72
73       super.deploy();
74    }
75
76    protected void undeploy()
77    {
78
79       super.undeploy();
80       for (Iterator JavaDoc i = urls.iterator(); i.hasNext();)
81       {
82          URL JavaDoc url = (URL JavaDoc) i.next();
83          undeployAOP(url);
84       }
85    }
86    
87    /**
88     * Deploy the aop config
89     *
90     * @param url the url
91     * @throws Exception for any error
92     */

93    protected void deployAOP(URL JavaDoc url) throws Exception JavaDoc
94    {
95       log.debug("Deploying " + url);
96       urls.add(url);
97       AspectXmlLoader.deployXML(url);
98    }
99
100    /**
101     * Undeploy the aop config
102     *
103     * @param url the url
104     */

105    protected void undeployAOP(URL JavaDoc url)
106    {
107       try
108       {
109          log.debug("Undeploying " + url);
110          urls.remove(url);
111          AspectXmlLoader.undeployXML(url);
112       }
113       catch (Exception JavaDoc e)
114       {
115          log.warn("Ignored error undeploying " + url, e);
116       }
117    }
118 }
119
Popular Tags