1
2
3
4
5
6
7
8
9
10
11
12
13
14 package org.exolab.castor.xml.util.resolvers;
15
16 import java.util.HashMap;
17 import java.util.Map;
18
19 import org.apache.commons.logging.Log;
20 import org.apache.commons.logging.LogFactory;
21 import org.exolab.castor.xml.Introspector;
22 import org.exolab.castor.xml.MarshalException;
23 import org.exolab.castor.xml.ResolverException;
24 import org.exolab.castor.xml.XMLClassDescriptor;
25 import org.exolab.castor.xml.util.ResolverStrategy;
26
27
28
29
30
31
32
33
34
35
36 public class ByIntrospection extends AbstractResolverClassCommand {
37
38
39
40 private static final Log LOG = LogFactory.getLog(ByIntrospection.class);
41
42
43
44
45 public ByIntrospection() {
46 super();
47 }
48
49
50
51
52
53
54
55
56
57
58 protected Map internalResolve(final String className, final ClassLoader classLoader,
59 final Map properties) throws ResolverException {
60
61 Boolean useIntrospector = (Boolean) properties.get(ResolverStrategy.PROPERTY_USE_INTROSPECTION);
62 HashMap results = new HashMap();
63 if (classLoader == null) {
64 LOG.debug("No class loader available.");
65 return results;
66 }
67
68 if ((useIntrospector != null) && (!useIntrospector.booleanValue())) {
69
70
71 LOG.debug("Introspection is disabled!");
72 return results;
73 }
74
75 Introspector introspector =
76 (Introspector) properties.get(ResolverStrategy.PROPERTY_INTROSPECTOR);
77 if (introspector == null) {
78 String message = "No Introspector defined in properties!";
79 LOG.warn(message);
80 throw new IllegalStateException(message);
81 }
82 Class clazz = ResolveHelpers.loadClass(classLoader, className);
83 if (clazz != null) {
84 try {
85 XMLClassDescriptor descriptor = introspector.generateClassDescriptor(clazz);
86 if (descriptor != null) {
87 if (LOG.isDebugEnabled()) {
88 LOG.debug("Found descriptor: " + descriptor);
89 }
90 results.put(clazz.getName(), descriptor);
91 }
92 } catch (MarshalException e) {
93 String message =
94 "Failed to generate class descriptor for: " + clazz + " with exception: " + e;
95 LOG.warn(message);
96 throw new ResolverException(message);
97 }
98 }
99 return results;
100 }
101 }