Hi all,
This commit fixes javax.management.ObjectName.apply()'s domain
matching when there are asterisks in the domain pattern. This
allows Tomcat to run with Classpath's javax.management. There
is a Mauve test which I'll be committing shortly.
Cheers,
Gary
Index: ChangeLog
===================================================================
RCS file: /cvsroot/classpath/classpath/ChangeLog,v
retrieving revision 1.9122
diff -u -r1.9122 ChangeLog
--- ChangeLog 19 Feb 2007 22:16:32 -0000 1.9122
+++ ChangeLog 20 Feb 2007 11:17:27 -0000
@@ -1,3 +1,9 @@
+2007-02-20 Gary Benson <[EMAIL PROTECTED]>
+
+ * javax/management/ObjectName.java
+ (domainMatches): New method.
+ (apply): Rearranged to use the above.
+
2007-02-19 Mark Wielaard <[EMAIL PROTECTED]>
* doc/.cvsignore: Add *.1.
Index: javax/management/ObjectName.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/management/ObjectName.java,v
retrieving revision 1.7
diff -u -r1.7 ObjectName.java
--- javax/management/ObjectName.java 19 Feb 2007 13:58:28 -0000 1.7
+++ javax/management/ObjectName.java 20 Feb 2007 11:17:27 -0000
@@ -303,70 +303,80 @@
{
if (name.isPattern())
return false;
- if (isPattern())
+
+ if (!isPattern())
+ return equals(name);
+
+ if (isDomainPattern())
+ {
+ if (!domainMatches(domain, 0, name.getDomain(), 0))
+ return false;
+ }
+ else
{
- boolean domainMatch, propMatch;
- if (isDomainPattern())
+ if (!domain.equals(name.getDomain()))
+ return false;
+ }
+
+ if (isPropertyPattern())
+ {
+ Hashtable oProps = name.getKeyPropertyList();
+ Iterator i = properties.entrySet().iterator();
+ while (i.hasNext())
{
- String oDomain = name.getDomain();
- int oLength = oDomain.length();
- for (int a = 0; a < domain.length(); ++a)
- {
- char n = domain.charAt(a);
- if (oLength == a && n != '*')
- return false;
- if (n == '?')
- continue;
- if (n == '*')
- if ((a + 1) < domain.length())
- {
- if (oLength == a)
- return false;
- char next;
- do
- {
- next = domain.charAt(a + 1);
- } while (next == '*');
- if (next == '?')
- continue;
- int pos = a;
- while (oDomain.charAt(pos) != next)
- {
- ++pos;
- if (pos == oLength)
- return false;
- }
- }
- if (n != oDomain.charAt(a))
- return false;
- }
- domainMatch = true;
+ Map.Entry entry = (Map.Entry) i.next();
+ String key = (String) entry.getKey();
+ if (!(oProps.containsKey(key)))
+ return false;
+ String val = (String) entry.getValue();
+ if (!(val.equals(oProps.get(key))))
+ return false;
}
- else
- domainMatch = domain.equals(name.getDomain());
- if (isPropertyPattern())
+ }
+ else
+ {
+ if (!getCanonicalKeyPropertyListString().equals
+ (name.getCanonicalKeyPropertyListString()))
+ return false;
+ }
+ return true;
+ }
+
+ /**
+ * Returns true if the domain matches the pattern.
+ *
+ * @param pattern the pattern to match against.
+ * @param patternindex the index into the pattern to start matching.
+ * @param domain the domain to match.
+ * @param domainindex the index into the domain to start matching.
+ * @return true if the domain matches the pattern.
+ */
+ private static boolean domainMatches(String pattern, int patternindex,
+ String domain, int domainindex)
+ {
+ while (patternindex < pattern.length())
+ {
+ char c = pattern.charAt(patternindex++);
+
+ if (c == '*')
{
- Hashtable oProps = name.getKeyPropertyList();
- Iterator i = properties.entrySet().iterator();
- while (i.hasNext())
+ for (int i = domain.length(); i >= domainindex; i--)
{
- Map.Entry entry = (Map.Entry) i.next();
- String key = (String) entry.getKey();
- if (!(oProps.containsKey(key)))
- return false;
- String val = (String) entry.getValue();
- if (!(val.equals(oProps.get(key))))
- return false;
+ if (domainMatches(pattern, patternindex, domain, i))
+ return true;
}
- propMatch = true;
+ return false;
}
- else
- propMatch =
- getCanonicalKeyPropertyListString().equals
- (name.getCanonicalKeyPropertyListString());
- return domainMatch && propMatch;
+
+ if (domainindex >= domain.length())
+ return false;
+
+ if (c != '?' && c != domain.charAt(domainindex))
+ return false;
+
+ domainindex++;
}
- return equals(name);
+ return true;
}
/**