1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.springframework.ws.server.endpoint.support;
18
19 import java.lang.reflect.AnnotatedElement;
20 import java.lang.reflect.Method;
21 import javax.xml.namespace.NamespaceContext;
22
23 import org.springframework.util.Assert;
24 import org.springframework.ws.server.endpoint.annotation.Namespace;
25 import org.springframework.ws.server.endpoint.annotation.Namespaces;
26 import org.springframework.xml.namespace.SimpleNamespaceContext;
27
28
29
30
31
32
33
34 public abstract class NamespaceUtils {
35
36 private NamespaceUtils() {
37 }
38
39
40
41
42
43
44
45
46
47
48
49
50 public static NamespaceContext getNamespaceContext(Method method) {
51 Assert.notNull(method, "'method' must not be null");
52 SimpleNamespaceContext namespaceContext = new SimpleNamespaceContext();
53 Class<?> endpointClass = method.getDeclaringClass();
54 Package endpointPackage = endpointClass.getPackage();
55 if (endpointPackage != null) {
56 addNamespaceAnnotations(endpointPackage, namespaceContext);
57 }
58 addNamespaceAnnotations(endpointClass, namespaceContext);
59 addNamespaceAnnotations(method, namespaceContext);
60 return namespaceContext;
61 }
62
63 private static void addNamespaceAnnotations(AnnotatedElement annotatedElement,
64 SimpleNamespaceContext namespaceContext) {
65 if (annotatedElement.isAnnotationPresent(Namespaces.class)) {
66 Namespaces namespacesAnn = annotatedElement.getAnnotation(Namespaces.class);
67 for (Namespace namespaceAnn : namespacesAnn.value()) {
68 namespaceContext.bindNamespaceUri(namespaceAnn.prefix(), namespaceAnn.uri());
69 }
70 }
71 if (annotatedElement.isAnnotationPresent(Namespace.class)) {
72 Namespace namespaceAnn = annotatedElement.getAnnotation(Namespace.class);
73 namespaceContext.bindNamespaceUri(namespaceAnn.prefix(), namespaceAnn.uri());
74 }
75 }
76
77 }