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.Map;
17  
18  import org.apache.commons.logging.Log;
19  import org.apache.commons.logging.LogFactory;
20  import org.exolab.castor.xml.ResolverException;
21  import org.exolab.castor.xml.util.ResolverClassCommand;
22  import org.exolab.castor.xml.util.ResolverStrategy;
23  
24  /**
25   * The abstract resolver command provides the argument checking, writes a debug message and reads
26   * the class loader from the properties... All specific code is found in the extended classes.
27   * 
28   * @author Joachim Grueneis, jgrueneis AT gmail DOT com
29   * @version $Id$
30   * @since 1.2
31   */
32  public abstract class AbstractResolverClassCommand implements ResolverClassCommand {
33    private static final Log LOG = LogFactory.getLog(AbstractResolverClassCommand.class);
34  
35    /**
36     * {@inheritDoc}
37     */
38    public final Map resolve(final String className, final Map properties) throws ResolverException {
39      if ((className == null) || ("".equals(className))) {
40        String message = "No class to resolve specified";
41        LOG.warn(message);
42        throw new IllegalArgumentException(message);
43      }
44  
45      if (LOG.isDebugEnabled()) {
46        LOG.debug("Now in method: " + this.getClass().getName() + " resolving: " + className);
47      }
48  
49      ClassLoader classLoader = (ClassLoader) properties.get(ResolverStrategy.PROPERTY_CLASS_LOADER);
50      return this.internalResolve(className, classLoader, properties);
51    }
52  
53    /**
54     * The required parameter checks are in the public method and here we expect that the resolve
55     * logic itself is implemented.
56     * 
57     * @param className the name of the class to resolve
58     * @param classLoader the class loader to use
59     * @param props the resolve properties to use
60     * @return a Map of className and XMLClassDescriptor
61     * @throws ResolverException if unrecoverable problems in resolve occured
62     */
63    protected abstract Map internalResolve(String className, ClassLoader classLoader, Map props)
64        throws ResolverException;
65  }