NamespaceUtils { public static NamespaceContext getNamespaceContext(Method method) { Assert.notNull(method, "'method' must not be null"); SimpleNamespaceContext namespaceContext = new SimpleNamespaceContext(); Class<?> endpointClass = method.getDeclaringClass(); Package endpointPackage = endpointClass.getPackage(); if (endpointPackage != null) { addNamespaceAnnotations(endpointPackage, namespaceContext); } addNamespaceAnnotations(endpointClass, namespaceContext); addNamespaceAnnotations(method, namespaceContext); return namespaceContext; } private  NamespaceUtils(); static NamespaceContext getNamespaceContext(Method method);  }
@Test public void getNamespaceContextMethod() throws NoSuchMethodException { Method method = getClass().getMethod("method"); NamespaceContext namespaceContext = NamespaceUtils.getNamespaceContext(method); assertEquals("method1", namespaceContext.getNamespaceURI("prefix1")); assertEquals("method2", namespaceContext.getNamespaceURI(XMLConstants.DEFAULT_NS_PREFIX)); }
@Test public void getNamespaceContextClass() throws NoSuchMethodException { Method method = getClass().getMethod("getNamespaceContextClass"); NamespaceContext namespaceContext = NamespaceUtils.getNamespaceContext(method); assertEquals("class1", namespaceContext.getNamespaceURI("prefix1")); assertEquals("class2", namespaceContext.getNamespaceURI(XMLConstants.DEFAULT_NS_PREFIX)); }