DMRLocationResolver implements LocationResolver<DMRNodeLocation> { @Override public String findWildcardMatch(DMRNodeLocation multiTargetLocation, DMRNodeLocation singleLocation) throws ProtocolException { if (multiTargetLocation == null) { throw new ProtocolException("multiTargetLocation is null"); } PathAddress multiTargetPaths = multiTargetLocation.getPathAddress(); for (int i = 0; i < multiTargetPaths.size(); i++) { PathElement multiTargetPathElement = multiTargetPaths.getElement(i); if (multiTargetPathElement.isWildcard()) { PathElement singleLocationPathElement; try { singleLocationPathElement = singleLocation.getPathAddress().getElement(i); } catch (Exception e) { throw new ProtocolException(String.format("[%s] doesn't have the same path size as [%s]", singleLocation, multiTargetLocation)); } if (singleLocationPathElement.getKey().equals(multiTargetPathElement.getKey())) { return singleLocationPathElement.getValue(); } 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 DMRNodeLocation buildLocation(String path); @Override String findWildcardMatch(DMRNodeLocation multiTargetLocation, DMRNodeLocation singleLocation); @Override boolean isMultiTarget(DMRNodeLocation location); @Override DMRNodeLocation absolutize(DMRNodeLocation base, DMRNodeLocation location); @Override boolean isParent(DMRNodeLocation parent, DMRNodeLocation child); @Override boolean matches(DMRNodeLocation query, DMRNodeLocation location); @Override String applyTemplate(String nameTemplate, DMRNodeLocation location, String endpointName);  }
@Test public void testFindWildcardMatch() throws Exception { DMRLocationResolver resolver = new DMRLocationResolver(); String match = resolver.findWildcardMatch(DMRNodeLocation.of("/one=1/two=*"), DMRNodeLocation.of("/one=111/two=222")); Assert.assertEquals("222", match); try { match = resolver.findWildcardMatch(DMRNodeLocation.of("/one=1"), DMRNodeLocation.of("/one=111")); Assert.fail("Should not have matched: " + match); } catch (ProtocolException ok) { } try { match = resolver.findWildcardMatch(null, DMRNodeLocation.of("/one=111")); Assert.fail("Should not have matched: " + match); } catch (ProtocolException ok) { } }