1 7 package com.inversoft.verge.mvc.controller.actionflow.config; 8 9 10 import java.util.HashMap ; 11 import java.util.Iterator ; 12 import java.util.Map ; 13 14 import com.inversoft.util.StringTools; 15 import com.inversoft.verge.mvc.config.BaseFormConfig; 16 import com.inversoft.verge.mvc.controller.LongTxnSetup; 17 import com.inversoft.verge.mvc.controller.actionflow.ActionFlowAction; 18 19 20 28 public class BaseNamespace implements Namespace { 29 30 33 protected Map nodes; 34 35 38 protected Node defaultNode; 39 40 43 protected Map forms; 44 45 private String name; 46 private String type; 47 private String errorPage; 48 private LongTxnSetup longTxnSetup; 49 50 51 59 public BaseNamespace(String name, String type) { 60 this(name, type, null, null); 61 } 62 63 72 public BaseNamespace(String name, String type, String errorPage, 73 LongTxnSetup longTxnSetup) { 74 assert (!StringTools.isEmpty(name)) : "name is null or empty"; 75 assert (!StringTools.isEmpty(type)) : "type is null or empty"; 76 77 this.name = name; 78 this.type = type; 79 this.errorPage = errorPage; 80 this.nodes = new HashMap (); 81 this.forms = new HashMap (); 82 this.longTxnSetup = longTxnSetup; 83 } 84 85 86 91 public String getName() { 92 return name; 93 } 94 95 100 public String getType() { 101 return type; 102 } 103 104 109 public String getErrorPage() { 110 return errorPage; 111 } 112 113 118 public Node getNode(String name) { 119 return (Node) nodes.get(name); 120 } 121 122 134 public Node addNode(Node node) throws IllegalArgumentException { 135 if (node == null) { 136 throw new IllegalArgumentException ("The Node is null"); 137 } 138 139 Node oldNode = (Node) nodes.put(node.getName(), node); 140 if (node.isDefaultEntry()) { 141 defaultNode = node; 142 } 143 144 return oldNode; 145 } 146 147 154 public Iterator nodeIterator() { 155 return nodes.values().iterator(); 156 } 157 158 169 public Node findEntry(String name) { 170 if (StringTools.isEmpty(name)) { 171 return defaultNode; 172 } 173 174 Node node = (Node) nodes.get(name); 175 if (node != null) { 176 return node; 177 } 178 179 Iterator iter = nodes.values().iterator(); 181 while (iter.hasNext()) { 182 node = (Node) iter.next(); 183 if (node.acceptEntry(name)) { 184 return node; 185 } 186 } 187 188 return null; 189 } 190 191 202 public BaseFormConfig addForm(BaseFormConfig form) throws IllegalArgumentException { 203 if (form == null) { 204 throw new IllegalArgumentException ("The form is null"); 205 } 206 207 return (BaseFormConfig) forms.put(form.getName(), form); 208 } 209 210 217 public Iterator formIterator() { 218 return forms.values().iterator(); 219 } 220 221 228 public BaseFormConfig lookupForm(String name) { 229 return (BaseFormConfig) forms.get(name); 230 } 231 232 238 public LongTxnSetup getLongTxnSetup() { 239 return longTxnSetup; 240 } 241 242 247 public String getLongTxnStartURL(ActionFlowAction action) { 248 return longTxnSetup.getLongTxnStartURL(action); 249 } 250 251 256 public String getLongTxnEndURL(ActionFlowAction action) { 257 return longTxnSetup.getLongTxnEndURL(action); 258 } 259 } | Popular Tags |