1 24 package org.riotfamily.forms.factory; 25 26 import java.util.ArrayList ; 27 import java.util.Collection ; 28 import java.util.HashMap ; 29 import java.util.Iterator ; 30 import java.util.Map ; 31 32 import org.riotfamily.forms.Form; 33 34 35 36 39 public abstract class AbstractFormRepository implements FormRepository { 40 41 private HashMap factories = new HashMap (); 42 43 public boolean containsForm(String id) { 44 return factories.containsKey(id); 45 } 46 47 protected FormFactory getFormFactory(String id) { 48 FormFactory factory = (FormFactory) factories.get(id); 49 if (factory == null) { 50 throw new FormDefinitionException("No such form: " + id); 51 } 52 return factory; 53 } 54 55 public Form createForm(String id) { 56 Form form = getFormFactory(id).createForm(); 57 form.setId(id); 58 return form; 59 } 60 61 public Class getBeanClass(String id) { 62 return getFormFactory(id).getBeanClass(); 63 } 64 65 public Collection getFormIds() { 66 ArrayList ids = new ArrayList (); 67 Iterator it = factories.entrySet().iterator(); 68 while (it.hasNext()) { 69 Map.Entry entry = (Map.Entry ) it.next(); 70 ids.add(entry.getKey()); 71 } 72 return ids; 73 } 74 75 public void registerFormFactory(String id, FormFactory formFactory) { 76 factories.put(id, formFactory); 77 } 78 79 protected HashMap getFactories() { 80 return this.factories; 81 } 82 83 } 84 | Popular Tags |