1
2
3
4
5
6
7
8
9
10
11
12
13
14 package org.castor.mapping;
15
16 import org.apache.commons.logging.Log;
17 import org.apache.commons.logging.LogFactory;
18 import org.exolab.castor.mapping.MappingException;
19 import org.exolab.castor.mapping.MappingLoader;
20
21
22
23
24
25
26
27 public abstract class AbstractMappingLoaderFactory implements MappingLoaderFactory {
28
29
30
31
32
33 public static final Log LOG = LogFactory.getLog(AbstractMappingLoaderFactory.class);
34
35
36
37
38 private static final String SOURCE_TYPE = "CastorXmlMapping";
39
40
41
42
43
44 public final String getSourceType() {
45 return SOURCE_TYPE;
46 }
47
48
49
50
51
52
53 public abstract String getClassname();
54
55
56
57
58
59 public final MappingLoader getMappingLoader() throws MappingException {
60 MappingLoader mappingLoader = null;
61 try {
62 ClassLoader loader = getClass().getClassLoader();
63 Class cls = loader.loadClass(getClassname());
64 Class[] types = new Class[] {ClassLoader.class};
65 Object[] args = new Object[] {loader};
66 mappingLoader = (MappingLoader) cls.getConstructor(types).newInstance(args);
67 } catch (Exception ex) {
68 LOG.error("Problem instantiating mapping loader factory implementation: " + getClassname(),
69 ex);
70 }
71 return mappingLoader;
72 }
73
74 }