1 18 package org.apache.tools.ant.types; 19 20 import org.apache.tools.ant.Project; 21 import org.apache.tools.ant.util.regexp.Regexp; 22 import org.apache.tools.ant.util.regexp.RegexpFactory; 23 24 59 public class RegularExpression extends DataType { 60 61 public static final String DATA_TYPE_NAME = "regexp"; 62 private boolean alreadyInit = false; 63 64 private static final RegexpFactory FACTORY = new RegexpFactory(); 66 67 private Regexp regexp = null; 68 private String myPattern; 70 private boolean setPatternPending = false; 71 72 75 public RegularExpression() { 76 } 77 78 private void init(Project p) { 79 if (!alreadyInit) { 80 this.regexp = FACTORY.newRegexp(p); 81 alreadyInit = true; 82 } 83 } 84 private void setPattern() { 85 if (setPatternPending) { 86 regexp.setPattern(myPattern); 87 setPatternPending = false; 88 } 89 } 90 94 public void setPattern(String pattern) { 95 if (regexp == null) { 96 myPattern = pattern; 97 setPatternPending = true; 98 } else { 99 regexp.setPattern(pattern); 100 } 101 } 102 103 109 public String getPattern(Project p) { 110 init(p); 111 if (isReference()) { 112 return getRef(p).getPattern(p); 113 } 114 setPattern(); 115 return regexp.getPattern(); 116 } 117 118 123 public Regexp getRegexp(Project p) { 124 init(p); 125 if (isReference()) { 126 return getRef(p).getRegexp(p); 127 } 128 setPattern(); 129 return this.regexp; 130 } 131 132 138 public RegularExpression getRef(Project p) { 139 return (RegularExpression) getCheckedRef(p); 140 } 141 } 142 | Popular Tags |