JMXLocationResolver implements LocationResolver<JMXNodeLocation> { @Override public String findWildcardMatch(JMXNodeLocation multiTargetLocation, JMXNodeLocation singleLocation) throws ProtocolException { if (multiTargetLocation == null) { throw new ProtocolException("multiTargetLocation is null"); } for (String multiTargetPathKey : multiTargetLocation.getCanonicalKeys()) { String multiTargetPathValue = multiTargetLocation.getObjectName().getKeyProperty(multiTargetPathKey); if ("*".equals(multiTargetPathValue)) { String singleLocationPathValue = singleLocation.getObjectName().getKeyProperty(multiTargetPathKey); if (singleLocationPathValue != null) { return singleLocationPathValue; } else { throw new ProtocolException(String.format("[%s] doesn't match the multi-target key in [%s]", singleLocation, multiTargetLocation)); } } } throw new ProtocolException(String.format("[%s] doesn't match the wildcard from [%s]", singleLocation, multiTargetLocation)); }  @Override JMXNodeLocation buildLocation(String path); @Override String findWildcardMatch(JMXNodeLocation multiTargetLocation, JMXNodeLocation singleLocation); @Override boolean isMultiTarget(JMXNodeLocation location); @Override JMXNodeLocation absolutize(JMXNodeLocation base, JMXNodeLocation location); @Override boolean isParent(JMXNodeLocation parent, JMXNodeLocation child); @Override boolean matches(JMXNodeLocation query, JMXNodeLocation location); @Override String applyTemplate(String nameTemplate, JMXNodeLocation location, String endpointName);  }
@Test public void testFindWildcardMatch() throws Exception { JMXLocationResolver resolver = new JMXLocationResolver(); String match = resolver.findWildcardMatch(new JMXNodeLocation("domain:one=1,two=*"), new JMXNodeLocation("domain:one=1,two=222")); Assert.assertEquals("222", match); try { match = resolver.findWildcardMatch(new JMXNodeLocation("domain:one=1"), new JMXNodeLocation("domain:one=111")); Assert.fail("Should not have matched: " + match); } catch (ProtocolException ok) { } try { match = resolver.findWildcardMatch(null, new JMXNodeLocation("domain:one=1")); Assert.fail("Should not have matched: " + match); } catch (ProtocolException ok) { } }