1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.xbean.spring.context.impl;
18
19 import org.springframework.beans.factory.BeanDefinitionStoreException;
20 import org.springframework.beans.factory.support.AbstractBeanDefinition;
21 import org.w3c.dom.Element;
22
23 import java.beans.PropertyDescriptor;
24 import java.lang.reflect.Method;
25
26
27
28
29
30
31
32 public class QNameReflectionHelper {
33
34 protected static Method coerceMethod;
35 protected static Method createMethod;
36
37 public static void coerceNamespaceAwarePropertyValues(AbstractBeanDefinition beanDefinition, Element element,
38 PropertyDescriptor[] descriptors, int index) {
39 QNameReflectionParams params = new QNameReflectionParams(beanDefinition, element, descriptors, index);
40 if (coerceMethod == null) {
41 coerceMethod = findMethod("coerceQNamePropertyValues");
42 }
43 if (coerceMethod != null) {
44 try {
45 coerceMethod.invoke(null, new Object[] { params });
46 }
47 catch (Exception e) {
48 throw new BeanDefinitionStoreException("Failed to invoke method: " + coerceMethod + " via reflection: " + e,
49 e);
50 }
51 }
52 }
53
54 public static Object createQName(Element element, String text) {
55 if (createMethod == null) {
56 createMethod = findMethod("createQName");
57 }
58 if (createMethod != null) {
59 try {
60 return createMethod.invoke(null, new Object[] { element, text });
61 }
62 catch (Exception e) {
63 throw new BeanDefinitionStoreException("Failed to invoke method: " + createMethod + " via reflection: " + e,
64 e);
65 }
66 }
67 return null;
68 }
69
70 protected static Method findMethod(String name) {
71 try {
72 Class type = PropertyEditorHelper.loadClass("org.apache.xbean.spring.context.impl.QNameHelper");
73 if (type != null) {
74 Method[] methods = type.getMethods();
75 for (int i = 0; i < methods.length; i++) {
76 Method method = methods[i];
77 if (method.getName().equals(name)) {
78 return method;
79 }
80 }
81 }
82 } catch (Throwable t) {
83
84 }
85 return null;
86 }
87
88 }