1 53 54 package org.swixml; 55 56 import java.lang.reflect.Method ; 57 import java.util.HashMap ; 58 import java.util.Iterator ; 59 import java.util.Map ; 60 61 71 public abstract class TagLibrary { 72 73 private Map tags = new HashMap (); 74 75 78 public TagLibrary() { 79 registerTags(); 80 } 81 82 85 abstract protected void registerTags(); 86 87 93 public void registerTag( String name, Class template ) { 94 registerTag( name, new DefaultFactory( template ) ); 95 } 96 97 103 public void registerTag( String name, Factory factory ) { 104 tags.put( name.toLowerCase(), factory ); 105 } 106 107 113 public boolean unregisterTag( String name ) { 114 return (null != tags.remove( name )); 115 } 116 117 121 public Map getTagClasses() { 122 return tags; 123 } 124 125 130 public Factory getFactory( String name ) { 131 return (Factory) tags.get( name.toLowerCase() ); 132 } 133 134 139 public Factory getFactory( Class template ) { 140 Factory factory = null; 141 Iterator it = tags.values().iterator(); 142 while (it != null && it.hasNext()) { 143 Factory f = (Factory) it.next(); 144 if (f.getTemplate().equals( template )) { 145 factory = f; 146 break; 147 } 148 } 149 return factory; 150 } 151 152 160 protected Method getSetter( Class template, String name ) { 161 Method method = null; 162 Factory factory = getFactory( template.getName() ); 163 if (factory != null) { 164 method = factory.getSetter( name ); 165 } 166 return method; 167 } 168 169 177 protected Method guessSetter( Class template, String name ) { 178 Method method = null; 179 Factory factory = getFactory( template.getName() ); 180 if (factory != null) { 181 method = factory.guessSetter( name ); 182 } 183 return method; 184 } 185 186 } 187 | Popular Tags |