1 package org.sapia.regis.forms; 2 3 import java.util.ArrayList ; 4 import java.util.Collection ; 5 import java.util.HashMap ; 6 import java.util.Map ; 7 8 import org.sapia.regis.Node; 9 10 public class Forms { 11 12 public static final String DEFAULT = "Default"; 13 14 private static Map _forms = new HashMap (); 15 16 17 public static Form create(String type){ 18 if(_forms.containsKey(type)){ 19 throw new IllegalStateException ("Form already exists for: " + type); 20 } 21 Form f = new Form(type); 22 _forms.put(type, f); 23 return f; 24 } 25 26 public static Collection getForms(){ 27 return new ArrayList (_forms.values()); 28 } 29 30 public static Form getFormFor(Node node){ 31 if(node.getType() == null || node.getType().equals(DEFAULT)){ 32 return null; 33 } 34 Form f = (Form)_forms.get(node.getType()); 35 if(f == null){ 36 throw new IllegalArgumentException ("No form for: " + node.getType()); 37 } 38 return f; 39 } 40 } 41 | Popular Tags |