1 /*
2 * Copyright 2007 Joachim Grueneis
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package org.exolab.castor.xml.util.resolvers;
17
18 import java.util.HashMap;
19 import java.util.Map;
20
21 import org.apache.commons.logging.Log;
22 import org.apache.commons.logging.LogFactory;
23 import org.exolab.castor.mapping.MappingLoader;
24 import org.exolab.castor.xml.ResolverException;
25 import org.exolab.castor.xml.XMLClassDescriptor;
26 import org.exolab.castor.xml.util.ResolverStrategy;
27
28 /**
29 * How to sought a descriptor for a class in a specified mapping loader.
30 *
31 * @author <a href="mailto:jgrueneis AT gmail DOT com">Joachim Grueneis</a>
32 * @author <a href="mailto:stevendolg AT gxm DOT at">Steven Dolg</a>
33 * @version $Revision$ $Date$
34 * @since 1.2
35 */
36 public class ByMappingLoader extends AbstractResolverClassCommand {
37 private static final Log LOG = LogFactory.getLog(ByMappingLoader.class);
38
39 /**
40 * No specific stuff needed.
41 */
42 public ByMappingLoader() {
43 super();
44 }
45
46 /**
47 * If a mapping loader is set in the configuration the descriptor for the given
48 * class / className is taken from the mapping loader and put into the cache.
49 * <br>
50 * {@inheritDoc}
51 */
52 protected Map internalResolve(final String className, final ClassLoader classLoader,
53 final Map properties) throws ResolverException {
54
55 MappingLoader mappingLoader = (MappingLoader)properties.get(ResolverStrategy.PROPERTY_MAPPING_LOADER);
56 HashMap results = new HashMap();
57 if (mappingLoader == null) {
58 LOG.debug("No mapping loader specified");
59 return results;
60 }
61
62 XMLClassDescriptor descriptor = (XMLClassDescriptor) mappingLoader.getDescriptor(className);
63 if (descriptor != null) {
64 if (LOG.isDebugEnabled()) {
65 LOG.debug("Found descriptor: " + descriptor);
66 }
67 results.put(className, descriptor);
68 }
69 return results;
70 }
71 }