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