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