1 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 ; 44 import java.util.HashMap ; 45 import java.util.HashSet ; 46 import java.util.Iterator ; 47 import java.util.Map ; 48 import java.util.Set ; 49 50 53 public final class PluginType implements Serializable { 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 PLUGIN_TYPES = new HashMap () { 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 name; 99 private final String parentElementName; 100 101 102 private PluginType(String type, String parentElementName) { 103 this.name = type; 104 this.parentElementName = parentElementName; 105 } 106 107 public static PluginType find(Class pluginClass) { 108 if (pluginClass != null) { 109 for (Iterator i = PLUGIN_TYPES.entrySet().iterator(); i.hasNext();) { 110 Map.Entry element = (Map.Entry ) i.next(); 111 if (((Class ) element.getKey()).isAssignableFrom(pluginClass)) { 112 return (PluginType) element.getValue(); 113 } 114 } 115 } 116 117 throw new IllegalArgumentException (pluginClass + " is not a CruiseControl plugin."); 118 } 119 120 public static PluginType[] getTypes() { 121 Set uniqueValues = new HashSet (PLUGIN_TYPES.values()); 122 return (PluginType[]) uniqueValues.toArray(new PluginType[uniqueValues.size()]); 123 } 124 125 public static PluginType find(String name) { 126 if (name != null) { 127 for (Iterator iter = PLUGIN_TYPES.entrySet().iterator(); iter.hasNext();) { 128 Map.Entry element = (Map.Entry ) 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 (name + " is not a CruiseControl plugin."); 137 } 138 139 public String getName() { 140 return this.name; 141 } 142 143 public String getParentElementName() { 144 return parentElementName; 145 } 146 147 public String toString() { 148 return getName(); 149 } 150 151 private Object readResolve() { 152 return PluginType.find(this.name); 153 } 154 } 155 | Popular Tags |