1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.castor.mapping;
17
18 import java.util.ArrayList;
19 import java.util.Collection;
20 import java.util.Collections;
21 import java.util.List;
22
23 import org.apache.commons.logging.Log;
24 import org.apache.commons.logging.LogFactory;
25 import org.castor.core.CoreProperties;
26 import org.castor.core.util.AbstractProperties;
27 import org.exolab.castor.mapping.MappingException;
28 import org.exolab.castor.mapping.MappingLoader;
29
30
31
32
33
34
35 public final class MappingLoaderRegistry {
36
37
38
39 private static final Log LOG = LogFactory.getLog(MappingLoaderRegistry.class);
40
41
42 private final List<MappingLoaderFactory> _mappingLoaderFactories = new ArrayList<MappingLoaderFactory>();
43
44
45 private final List<MappingLoader> _mappingLoaders = new ArrayList<MappingLoader>();
46
47
48
49
50
51
52 public MappingLoaderRegistry(final AbstractProperties properties) {
53 Object[] objects = properties.getObjectArray(CoreProperties.MAPPING_LOADER_FACTORIES, getClass().getClassLoader());
54 for (Object mappingLoaderFactory : objects) {
55 _mappingLoaderFactories.add((MappingLoaderFactory) mappingLoaderFactory);
56 }
57 }
58
59
60
61
62 public void clear() {
63 for (MappingLoader mappingLoader : _mappingLoaders) {
64 mappingLoader.clear();
65 }
66 }
67
68
69
70
71
72
73
74
75
76
77
78
79 public MappingLoader getMappingLoader(
80 final String sourceType,
81 final BindingType bindingType) throws MappingException {
82 for (MappingLoaderFactory mappingLoaderFactory : _mappingLoaderFactories) {
83 if (mappingLoaderFactory.getSourceType().equals(sourceType)
84 && (mappingLoaderFactory.getBindingType() == bindingType)) {
85 MappingLoader mappingLoader = mappingLoaderFactory.getMappingLoader();
86 _mappingLoaders.add(mappingLoader);
87 return mappingLoader;
88 }
89 }
90
91 String msg = "No mapping loader/factory for: " + "SourceType=" + sourceType
92 + " / BindingType=" + bindingType;
93 LOG.error(msg);
94 throw new MappingException(msg);
95 }
96
97
98
99
100
101 public Collection<MappingLoaderFactory> getMappingLoaderFactories() {
102 return Collections.unmodifiableCollection(_mappingLoaderFactories);
103 }
104
105 }