summaryrefslogtreecommitdiff
path: root/javax/management
diff options
context:
space:
mode:
authorGary Benson <gbenson@redhat.com>2007-02-20 11:17:50 +0000
committerGary Benson <gbenson@redhat.com>2007-02-20 11:17:50 +0000
commit94b1db85132222c4d4874bacf7bc01e995c7c5d8 (patch)
tree92015a2605d6d95a5ca986a85c00dcfe0ef09d93 /javax/management
parent8ae040ef0b603890bccbcb2cd2a390acdc6fc756 (diff)
downloadclasspath-94b1db85132222c4d4874bacf7bc01e995c7c5d8.tar.gz
2007-02-20 Gary Benson <gbenson@redhat.com>
* javax/management/ObjectName.java (domainMatches): New method. (apply): Rearranged to use the above.
Diffstat (limited to 'javax/management')
-rw-r--r--javax/management/ObjectName.java122
1 files changed, 66 insertions, 56 deletions
diff --git a/javax/management/ObjectName.java b/javax/management/ObjectName.java
index 41bbfb677..8259eab02 100644
--- a/javax/management/ObjectName.java
+++ b/javax/management/ObjectName.java
@@ -303,70 +303,80 @@ public class ObjectName
{
if (name.isPattern())
return false;
- if (isPattern())
+
+ if (!isPattern())
+ return equals(name);
+
+ if (isDomainPattern())
{
- boolean domainMatch, propMatch;
- if (isDomainPattern())
+ if (!domainMatches(domain, 0, name.getDomain(), 0))
+ return false;
+ }
+ else
+ {
+ 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;
}
/**