1 16 package scriptella.configuration; 17 18 import scriptella.spi.DialectIdentifier; 19 import scriptella.spi.Resource; 20 21 import java.util.Arrays ; 22 import java.util.Collections ; 23 import java.util.LinkedHashSet ; 24 import java.util.Set ; 25 import java.util.regex.Pattern ; 26 27 33 public class OnErrorEl extends XmlConfigurableBase { 34 private static final Pattern CODES_SEPARATOR = Pattern.compile("\\s*\\,\\s*"); 35 private Pattern type; 36 private Pattern message; 37 private Set <String > codes; 38 private boolean retry; 39 protected DialectBasedContentEl content; 40 41 public OnErrorEl() { 42 } 43 44 public OnErrorEl(final XmlElement element) { 45 configure(element); 46 } 47 48 public void configure(final XmlElement element) { 49 setPatternProperty(element, "type"); 50 setPatternProperty(element, "message"); 51 String codestr = element.getAttribute("codes"); 52 if (codestr == null) { 53 codes = Collections.emptySet(); 54 } else { 55 codes = new LinkedHashSet <String >(Arrays.asList(CODES_SEPARATOR.split(codestr))); 56 } 57 retry = element.getBooleanAttribute("retry", false); 58 content = new DialectBasedContentEl(element); 59 } 60 61 64 public Pattern getType() { 65 return type; 66 } 67 68 public void setType(Pattern type) { 69 this.type = type; 70 } 71 72 75 public Pattern getMessage() { 76 return message; 77 } 78 79 public void setMessage(Pattern message) { 80 this.message = message; 81 } 82 83 86 public Set <String > getCodes() { 87 return codes; 88 } 89 90 public void setCodes(Set <String > codes) { 91 this.codes = codes; 92 } 93 94 97 public boolean isRetry() { 98 return retry; 99 } 100 101 public void setRetry(boolean retry) { 102 this.retry = retry; 103 } 104 105 public Resource getContent(DialectIdentifier id) { 106 Resource r = content.getContent(id); 107 if (r==null) { 108 return ContentEl.NULL_CONTENT; 109 } else { 110 return r; 111 } 112 } 113 114 115 public String toString() { 116 StringBuilder res = new StringBuilder ("OnError{"); 117 if (type!=null) { 118 res.append("type=").append(type).append(", "); 119 } 120 if (message!=null) { 121 res.append("message=").append(message).append(", "); 122 } 123 if (codes!=null) { 124 res.append("codes=").append(codes).append(", "); 125 } 126 127 res.append("retry=").append(retry).append('}'); 128 return res.toString(); 129 } 130 } 131 | Popular Tags |