1 7 package com.inversoft.verge.mvc.controller.actionflow.config; 8 9 10 import java.util.ArrayList ; 11 import java.util.HashMap ; 12 import java.util.Iterator ; 13 import java.util.List ; 14 import java.util.Map ; 15 16 import org.jdom.Element; 17 18 import com.inversoft.util.StringTools; 19 import com.inversoft.verge.mvc.controller.actionflow.NodeExecutor; 20 21 22 32 public class BaseNode implements Node { 33 34 38 public static class BaseValues { 39 public String name; 40 public String type; 41 public String className; 42 public String repositoryId; 43 public boolean defaultEntry; 44 public boolean exitPoint; 45 public NodeExecutor executor; 46 public boolean longTxnEnabled; 47 public String longTxnStartURL; 48 public String longTxnEndURL; 49 public String longTxnCategory; 50 } 51 52 53 56 protected Map namedLinks; 57 58 61 protected List regexLinks; 62 63 66 protected Namespace namespace; 67 68 71 protected BaseValues values; 72 73 76 private Element element; 77 78 79 97 public BaseNode(String name, String type, Namespace namespace, String className, 98 String repositoryId, boolean defaultEntry, boolean exitPoint, 99 NodeExecutor executor) { 100 assert (!StringTools.isEmpty(name)) : "name is null or empty"; 101 assert (!StringTools.isEmpty(type)) : "type is null or empty"; 102 assert (namespace != null) : "namespace == null"; 103 104 values = new BaseValues(); 105 values.repositoryId = repositoryId; 106 values.name = name; 107 values.type = type; 108 values.className = className; 109 values.defaultEntry = defaultEntry; 110 values.exitPoint = exitPoint; 111 values.executor = executor; 112 this.namespace = namespace; 113 this.namedLinks = new HashMap (); 114 this.regexLinks = new ArrayList (); 115 } 116 117 125 public BaseNode(BaseNode.BaseValues values, Namespace namespace) { 126 assert (values != null) : "values == null"; 127 assert (namespace != null) : "namespace == null"; 128 assert (values.name != null) : "values.name == null"; 129 assert (values.type != null) : "values.type == null"; 130 131 this.values = values; 132 this.namespace = namespace; 133 this.namedLinks = new HashMap (); 134 this.regexLinks = new ArrayList (); 135 } 136 137 144 public BaseNode(BaseNode orig) { 145 assert (orig != null) : "orig == null"; 146 147 this.values = orig.values; 148 this.namespace = orig.namespace; 149 this.element = orig.element; 150 this.namedLinks = orig.namedLinks; 151 this.regexLinks = orig.regexLinks; 152 } 153 154 155 160 public String getName() { 161 return values.name; 162 } 163 164 169 public String getType() { 170 return values.type; 171 } 172 173 178 public Namespace getNamespace() { 179 return namespace; 180 } 181 182 198 public String getClassName() { 199 return values.className; 200 } 201 202 217 public String getRepositoryId() { 218 return values.repositoryId; 219 } 220 221 228 public boolean isDefaultEntry() { 229 return values.defaultEntry; 230 } 231 232 239 public boolean acceptEntry(String name) { 240 return false; 241 } 242 243 253 public boolean isExitPoint() { 254 return values.exitPoint; 255 } 256 257 263 public Link [] getLinks() { 264 List list = new ArrayList (regexLinks); 265 list.addAll(namedLinks.values()); 266 return (Link []) list.toArray(new Link [0]); 267 } 268 269 279 public Link findLink(Object action) { 280 281 assert (action != null) : "action == null"; 282 283 Link link = null; 284 285 if (action instanceof Exception ) { 291 Class currentClass = action.getClass(); 292 while (currentClass != Throwable .class) { 293 294 link = (Link) namedLinks.get(currentClass); 295 if (link != null) { 296 return link; 297 } 298 299 currentClass = currentClass.getSuperclass(); 300 } 301 302 return null; 303 } 304 305 link = (Link) namedLinks.get(action); 307 if (link != null) { 308 return link; 309 } 310 311 Iterator iter = regexLinks.iterator(); 313 while (iter.hasNext()) { 314 link = (Link) iter.next(); 315 if (link.acceptAction(action)) { 316 return link; 317 } 318 } 319 320 return null; 321 } 322 323 333 public Link addLink(Link link) { 334 335 assert (link != null) : "link == null"; 336 337 Link old = null; 338 if (link instanceof ActionLink) { 339 old = (Link) namedLinks.put(((ActionLink) link).getAction(), link); 340 } else if (link instanceof RegexLink) { 341 regexLinks.add(link); 342 } else if (link instanceof ExceptionLink) { 343 344 old = (Link) namedLinks.put( 346 ((ExceptionLink) link).getException().getClass(), link); 347 } else { 348 assert (false) : "The Link is a type not supported by BaseNode"; 349 } 350 351 return old; 352 } 353 354 360 public NodeExecutor getExecutor() { 361 return values.executor; 362 } 363 364 370 public void setExecutor(NodeExecutor executor) { 371 372 assert (executor != null) : "executor == null"; 373 values.executor = executor; 374 } 375 376 383 public boolean isLongTxnEnabled() { 384 return values.longTxnEnabled; 385 } 386 387 394 public String getLongTxnStartURL() { 395 return values.longTxnStartURL; 396 } 397 398 405 public String getLongTxnEndURL() { 406 return values.longTxnEndURL; 407 } 408 409 416 public String getLongTxnCategory() { 417 return values.longTxnCategory; 418 } 419 420 421 425 426 431 public Element getElement() { 432 return element; 433 } 434 435 440 public void setElement(Element element) { 441 this.element = element; 442 } 443 444 449 public String toString() { 450 StringBuffer buf = new StringBuffer (); 451 buf.append("Node: [").append(values.name).append(" ").append(values.type); 452 buf.append("]"); 453 return buf.toString(); 454 } 455 } | Popular Tags |