KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > cruisecontrol > interceptor > PluginLocator


1 /********************************************************************************
2  * CruiseControl, a Continuous Integration Toolkit
3  * Copyright (c) 2005 ThoughtWorks, Inc.
4  * 651 W Washington Ave. Suite 600
5  * Chicago, IL 60661 USA
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * + Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  *
15  * + Redistributions in binary form must reproduce the above
16  * copyright notice, this list of conditions and the following
17  * disclaimer in the documentation and/or other materials provided
18  * with the distribution.
19  *
20  * + Neither the name of ThoughtWorks, Inc., CruiseControl, nor the
21  * names of its contributors may be used to endorse or promote
22  * products derived from this software without specific prior
23  * written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
29  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36  ********************************************************************************/

37 package net.sourceforge.cruisecontrol.interceptor;
38
39 import java.io.IOException JavaDoc;
40 import java.util.Collection JavaDoc;
41 import java.util.LinkedList JavaDoc;
42
43 import javax.management.AttributeNotFoundException JavaDoc;
44 import javax.management.InstanceNotFoundException JavaDoc;
45 import javax.management.MBeanException JavaDoc;
46 import javax.management.ReflectionException JavaDoc;
47
48 import net.sourceforge.cruisecontrol.Configuration;
49 import net.sourceforge.cruisecontrol.CruiseControlException;
50 import net.sourceforge.cruisecontrol.PluginDetail;
51 import net.sourceforge.cruisecontrol.PluginType;
52
53 import org.jdom.JDOMException;
54
55 /**
56  * Understands how to find plugins.
57  */

58 public class PluginLocator {
59     private Configuration configuration;
60
61     public PluginLocator(Configuration configuration) {
62         this.configuration = configuration;
63     }
64
65     public PluginDetail[] getAvailablePlugins(String JavaDoc type) throws AttributeNotFoundException JavaDoc,
66             InstanceNotFoundException JavaDoc, MBeanException JavaDoc, ReflectionException JavaDoc, IOException JavaDoc {
67         return getAvailablePlugins(PluginType.find(type));
68     }
69
70     public PluginDetail[] getAvailablePlugins(PluginType type) throws ReflectionException JavaDoc, IOException JavaDoc,
71             InstanceNotFoundException JavaDoc, MBeanException JavaDoc, AttributeNotFoundException JavaDoc {
72         PluginDetail[] availablePlugins = configuration.getPluginDetails();
73         Collection JavaDoc desiredPlugins = new LinkedList JavaDoc();
74         for (int i = 0; i < availablePlugins.length; i++) {
75             PluginDetail nextPlugin = availablePlugins[i];
76
77             if (nextPlugin.getType() == type) {
78                 desiredPlugins.add(nextPlugin);
79             }
80         }
81
82         return (PluginDetail[]) desiredPlugins.toArray(new PluginDetail[desiredPlugins.size()]);
83     }
84
85     public PluginDetail[] getConfiguredPlugins(String JavaDoc project, String JavaDoc type) throws AttributeNotFoundException JavaDoc,
86             InstanceNotFoundException JavaDoc, MBeanException JavaDoc, ReflectionException JavaDoc, IOException JavaDoc, CruiseControlException,
87             JDOMException {
88         if ("listener".equals(type)) {
89             return configuration.getConfiguredListeners(project);
90         } else if ("bootstrapper".equals(type)) {
91             return configuration.getConfiguredBootstrappers(project);
92         } else if ("sourcecontrol".equals(type)) {
93             return configuration.getConfiguredSourceControls(project);
94         } else if ("builder".equals(type)) {
95             return configuration.getConfiguredBuilders(project);
96         } else if ("logger".equals(type)) {
97             return configuration.getConfiguredLoggers(project);
98         } else if ("publisher".equals(type)) {
99             return configuration.getConfiguredPublishers(project);
100         } else {
101             return null;
102         }
103     }
104
105     public PluginDetail getPluginDetail(String JavaDoc name, String JavaDoc type) throws AttributeNotFoundException JavaDoc,
106             InstanceNotFoundException JavaDoc, MBeanException JavaDoc, ReflectionException JavaDoc, IOException JavaDoc {
107         PluginDetail[] plugins = getAvailablePlugins(type);
108         for (int i = 0; i < plugins.length; i++) {
109             if (plugins[i].getName().equals(name)) {
110                 return plugins[i];
111             }
112         }
113
114         return null;
115     }
116 }
117
Popular Tags