1 56 package org.objectstyle.cayenne.exp.parser; 57 58 import org.apache.oro.text.perl.Perl5Util; 59 import org.objectstyle.cayenne.util.Util; 60 61 68 public abstract class PatternMatchNode extends ConditionNode { 69 70 static final Perl5Util regexUtil = new Perl5Util(); 73 74 protected String pattern; 75 protected boolean patternCompiled; 76 protected boolean ignoringCase; 77 78 PatternMatchNode(int i, boolean ignoringCase) { 79 super(i); 80 this.ignoringCase = ignoringCase; 81 } 82 83 protected boolean matchPattern(String string) { 84 return (string != null) ? regexUtil.match(getPattern(), string) : false; 85 } 86 87 protected String getPattern() { 88 if (!patternCompiled) { 90 pattern = null; 91 patternCompiled = true; 92 93 if (jjtGetNumChildren() < 2) { 94 return null; 95 } 96 97 ASTScalar patternNode = (ASTScalar) jjtGetChild(1); 99 if (patternNode == null) { 100 return null; 101 } 102 103 String srcPattern = (String ) patternNode.getValue(); 104 if (srcPattern == null) { 105 return null; 106 } 107 108 pattern = Util.sqlPatternToRegex(srcPattern, ignoringCase); 109 } 110 111 return pattern; 112 } 113 114 public void jjtAddChild(Node n, int i) { 115 if (i == 1) { 117 patternCompiled = false; 118 } 119 120 super.jjtAddChild(n, i); 121 } 122 } 123 | Popular Tags |