View Javadoc
1 /* 2 * Created on 22.mar.2003 3 * 4 */ 5 package net.sf.panoptes.model.component.registry; 6 7 import java.util.HashMap; 8 import java.util.HashSet; 9 import java.util.Iterator; 10 import java.util.Set; 11 12 /*** 13 * 14 * 15 * @author Dag Liodden 16 * @version 0.1 17 */ 18 public class ConfiguratorRegistry { 19 20 private HashMap configurators = new HashMap(); 21 22 public ConfiguratorRegistry() { 23 24 } 25 26 /*** 27 * Adds a <code>Configurator</code> to the registry. 28 * 29 * @param name the nickname of the configurator (to be used in configuration files) 30 * @param className the FQCN of the class 31 * @param patterns comma-delimited string of patterns that can be parsed as <code>ComponentName</code> 32 * @throws ConfiguratorRegistryException if configurator already is added or has an invalid className 33 * @see net.sf.panoptes.view.configurator.ComponentConfigurator 34 */ 35 public ConfiguratorEntry addConfigurator(String name, String className, String patterns, HashMap attributes) 36 throws ConfiguratorRegistryException, MalformedComponentNameException { 37 if (configurators.get(name) != null) 38 throw new ConfiguratorRegistryException("Duplicate configurator name " + name); 39 40 try { 41 // Check that the classname is valid 42 Class clazz = Class.forName(className); 43 ConfiguratorEntry entry = new ConfiguratorEntry(name, clazz, new ComponentName(patterns), attributes); 44 configurators.put(name, entry); 45 return entry; 46 } catch (ClassNotFoundException e) { 47 throw new ConfiguratorRegistryException("Configurator class '" + className + "' does not exists", e); 48 } 49 } 50 51 /*** 52 * Fetches configurators that match the <code>Componentname</code>. 53 * 54 * @param componentName the name of the component. If it's null, only configurators with patterns that match any component are returned 55 * @return 56 */ 57 public Set findConfigurators(ComponentName componentName) { 58 try { 59 HashSet configs = new HashSet(); 60 for (Iterator i = configurators.values().iterator(); i.hasNext();) { 61 ConfiguratorEntry e = (ConfiguratorEntry) i.next(); 62 63 // Do we have a null? 64 if (componentName == null) { 65 if (e.getPattern().toString().equals("*.*")) configs.add(e); 66 } else if (componentName.matches(e.getPattern())) { 67 configs.add(e); 68 } 69 } 70 return configs; 71 } catch (Exception e) { 72 e.printStackTrace(); 73 return null; 74 } 75 76 } 77 }

This page was automatically generated by Maven