KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > cruisecontrol > PluginType


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;
38
39 import net.sourceforge.cruisecontrol.buildloggers.MergeLogger;
40 import net.sourceforge.cruisecontrol.publishers.email.EmailMapper;
41 import net.sourceforge.cruisecontrol.publishers.email.EmailMapping;
42
43 import java.io.Serializable JavaDoc;
44 import java.util.HashMap JavaDoc;
45 import java.util.HashSet JavaDoc;
46 import java.util.Iterator JavaDoc;
47 import java.util.Map JavaDoc;
48 import java.util.Set JavaDoc;
49
50 /**
51  * Type-safe, enumeration of CruiseControl plugin types.
52  */

53 public final class PluginType implements Serializable JavaDoc {
54     public static final PluginType BOOTSTRAPPER = new PluginType("bootstrapper", "bootstrappers");
55     public static final PluginType BOOTSTRAPPERS = new PluginType("bootstrappers", "project");
56     public static final PluginType BUILDER = new PluginType("builder", "schedule");
57     public static final PluginType DATE_FORMAT = new PluginType("dateformat", "project");
58     public static final PluginType LABEL_INCREMENTER = new PluginType("labelincrementer", "project");
59     public static final PluginType LISTENER = new PluginType("listener", "listeners");
60     public static final PluginType LISTENERS = new PluginType("listeners", "project");
61     public static final PluginType LOG = new PluginType("log", "project");
62     public static final PluginType MAP = new PluginType("map", "email");
63     public static final PluginType MERGE_LOGGER = new PluginType("logger", "log");
64     public static final PluginType MANIPULATORS = new PluginType("manipulators", "log");
65     public static final PluginType MODIFICATION_SET = new PluginType("modificationset", "project");
66     public static final PluginType PROJECT = new PluginType("project", "cruisecontrol");
67     public static final PluginType EMAIL_MAPPER = new PluginType("propertiesmapper", "email");
68     public static final PluginType PAUSE = new PluginType("pause", "schedule");
69     public static final PluginType PUBLISHER = new PluginType("publisher", "publishers");
70     public static final PluginType PUBLISHERS = new PluginType("publishers", "project");
71     public static final PluginType SCHEDULE = new PluginType("schedule", "project");
72     public static final PluginType SOURCE_CONTROL = new PluginType("sourcecontrol", "modificationset");
73
74     private static final Map JavaDoc PLUGIN_TYPES = new HashMap JavaDoc() {
75         {
76             put(Bootstrapper.class, BOOTSTRAPPER);
77             put(ProjectConfig.Bootstrappers.class, BOOTSTRAPPERS);
78             put(Builder.class, BUILDER);
79             put(CCDateFormat.class, DATE_FORMAT);
80             put(LabelIncrementer.class, LABEL_INCREMENTER);
81             put(Listener.class, LISTENER);
82             put(ProjectConfig.Listeners.class, LISTENERS);
83             put(Log.class, LOG);
84             put(EmailMapping.class, MAP);
85             put(MergeLogger.class, MERGE_LOGGER);
86             put(Manipulator.class, MANIPULATORS);
87             put(ModificationSet.class, MODIFICATION_SET);
88             put(ProjectConfig.class, PROJECT);
89             put(EmailMapper.class, EMAIL_MAPPER);
90             put(ProjectConfig.Publishers.class, PUBLISHERS);
91             put(PauseBuilder.class, PAUSE);
92             put(Publisher.class, PUBLISHER);
93             put(Schedule.class, SCHEDULE);
94             put(SourceControl.class, SOURCE_CONTROL);
95         }
96     };
97
98     private final String JavaDoc name;
99     private final String JavaDoc parentElementName;
100
101
102     private PluginType(String JavaDoc type, String JavaDoc parentElementName) {
103         this.name = type;
104         this.parentElementName = parentElementName;
105     }
106
107     public static PluginType find(Class JavaDoc pluginClass) {
108         if (pluginClass != null) {
109             for (Iterator JavaDoc i = PLUGIN_TYPES.entrySet().iterator(); i.hasNext();) {
110                 Map.Entry JavaDoc element = (Map.Entry JavaDoc) i.next();
111                 if (((Class JavaDoc) element.getKey()).isAssignableFrom(pluginClass)) {
112                     return (PluginType) element.getValue();
113                 }
114             }
115         }
116
117         throw new IllegalArgumentException JavaDoc(pluginClass + " is not a CruiseControl plugin.");
118     }
119
120     public static PluginType[] getTypes() {
121         Set JavaDoc uniqueValues = new HashSet JavaDoc(PLUGIN_TYPES.values());
122         return (PluginType[]) uniqueValues.toArray(new PluginType[uniqueValues.size()]);
123     }
124
125     public static PluginType find(String JavaDoc name) {
126         if (name != null) {
127             for (Iterator JavaDoc iter = PLUGIN_TYPES.entrySet().iterator(); iter.hasNext();) {
128                 Map.Entry JavaDoc element = (Map.Entry JavaDoc) iter.next();
129                 PluginType nextType = (PluginType) element.getValue();
130                 if (nextType.getName().equals(name)) {
131                     return nextType;
132                 }
133             }
134         }
135
136         throw new IllegalArgumentException JavaDoc(name + " is not a CruiseControl plugin.");
137     }
138
139     public String JavaDoc getName() {
140         return this.name;
141     }
142
143     public String JavaDoc getParentElementName() {
144         return parentElementName;
145     }
146
147     public String JavaDoc toString() {
148         return getName();
149     }
150
151     private Object JavaDoc readResolve() {
152         return PluginType.find(this.name);
153     }
154 }
155
Popular Tags