1 4 package com.inversoft.verge.mvc.controller.actionflow.config; 5 6 7 import java.util.regex.Matcher ; 8 import java.util.regex.Pattern ; 9 10 import com.inversoft.util.StringTools; 11 12 13 27 public class RegexLink extends BaseLink { 28 29 private Pattern regex; 30 31 32 36 public RegexLink(String regex, Node origin, Node destination) { 37 38 super(origin, destination); 39 if (StringTools.isEmpty(regex)) { 40 throw new IllegalArgumentException ("The regex is empty or null"); 41 } 42 43 this.regex = Pattern.compile(regex); 44 } 45 46 47 52 public Pattern getRegex() { 53 return regex; 54 } 55 56 61 public String getValue() { 62 return regex.pattern(); 63 } 64 65 73 public boolean acceptAction(Object action) { 74 assert (action instanceof String ) : "action must be a String"; 75 assert (!StringTools.isEmpty((String ) action)) : "action can not be null or empty"; 76 77 Matcher matcher = regex.matcher((String ) action); 78 return matcher.matches(); 79 } 80 81 84 public String toString() { 85 StringBuffer buf = new StringBuffer (); 86 buf.append(getOrigin().getName()).append(" --(").append(regex); 87 buf.append(")--> ").append(getDestination().getName()); 88 return buf.toString(); 89 } 90 } 91 92 | Popular Tags |