Methods Summary |
---|
public boolean | apply(javax.management.ObjectName name)Applies the MatchQueryExp on a MBean.
ValueExp val = exp.apply(name);
if (!(val instanceof StringValueExp)) {
return false;
}
return wildmatch(((StringValueExp)val).getValue(), pattern);
|
public javax.management.AttributeValueExp | getAttribute()Returns the attribute of the query.
return exp;
|
public java.lang.String | getPattern()Returns the pattern of the query.
return pattern;
|
private static java.lang.String | likeTranslate(java.lang.String s)
return s.replace('?", '_").replace('*", '%");
|
public java.lang.String | toString()Returns the string representing the object
return exp + " like " + new StringValueExp(likeTranslate(pattern));
|
private static boolean | wildmatch(java.lang.String s, java.lang.String p)
char c;
int si = 0, pi = 0;
int slen = s.length();
int plen = p.length();
while (pi < plen) { // While still string
c = p.charAt(pi++);
if (c == '?") {
if (++si > slen)
return false;
} else if (c == '[") { // Start of choice
if (si >= slen)
return false;
boolean wantit = true;
boolean seenit = false;
if (p.charAt(pi) == '!") {
wantit = false;
++pi;
}
while ((c = p.charAt(pi)) != ']" && ++pi < plen) {
if (p.charAt(pi) == '-" &&
pi+1 < plen &&
p.charAt(pi+1) != ']") {
if (s.charAt(si) >= p.charAt(pi-1) &&
s.charAt(si) <= p.charAt(pi+1)) {
seenit = true;
}
++pi;
} else {
if (c == s.charAt(si)) {
seenit = true;
}
}
}
if ((pi >= plen) || (wantit != seenit)) {
return false;
}
++pi;
++si;
} else if (c == '*") { // Wildcard
if (pi >= plen)
return true;
do {
if (wildmatch(s.substring(si), p.substring(pi)))
return true;
} while (++si < slen);
return false;
} else if (c == '\\") {
if (pi >= plen || si >= slen ||
p.charAt(pi++) != s.charAt(si++))
return false;
} else {
if (si >= slen || c != s.charAt(si++)) {
return false;
}
}
}
return (si == slen);
|