1 19 20 package org.apache.cayenne.exp.parser; 21 22 import java.util.regex.Pattern ; 23 24 import org.apache.cayenne.util.Util; 25 26 33 public abstract class PatternMatchNode extends ConditionNode { 34 35 protected Pattern pattern; 36 protected boolean patternCompiled; 37 protected boolean ignoringCase; 38 39 PatternMatchNode(int i, boolean ignoringCase) { 40 super(i); 41 this.ignoringCase = ignoringCase; 42 } 43 44 protected boolean matchPattern(String string) { 45 return (string != null) ? getPattern().matcher(string).find() : false; 46 } 47 48 protected Pattern getPattern() { 49 if (!patternCompiled) { 51 52 synchronized (this) { 53 54 if (!patternCompiled) { 55 pattern = null; 56 57 if (jjtGetNumChildren() < 2) { 58 patternCompiled = true; 59 return null; 60 } 61 62 ASTScalar patternNode = (ASTScalar) jjtGetChild(1); 64 if (patternNode == null) { 65 patternCompiled = true; 66 return null; 67 } 68 69 String srcPattern = (String ) patternNode.getValue(); 70 if (srcPattern == null) { 71 patternCompiled = true; 72 return null; 73 } 74 75 pattern = Util.sqlPatternToPattern(srcPattern, ignoringCase); 76 patternCompiled = true; 77 } 78 } 79 } 80 81 return pattern; 82 } 83 84 public void jjtAddChild(Node n, int i) { 85 if (i == 1) { 87 patternCompiled = false; 88 } 89 90 super.jjtAddChild(n, i); 91 } 92 } 93 | Popular Tags |