01: /**********************************************************************
02: Copyright (c) 2006 Andy Jefferson and others. All rights reserved.
03: Licensed under the Apache License, Version 2.0 (the "License");
04: you may not use this file except in compliance with the License.
05: You may obtain a copy of the License at
06:
07: http://www.apache.org/licenses/LICENSE-2.0
08:
09: Unless required by applicable law or agreed to in writing, software
10: distributed under the License is distributed on an "AS IS" BASIS,
11: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12: See the License for the specific language governing permissions and
13: limitations under the License.
14:
15: Contributors:
16: ...
17: **********************************************************************/package org.jpox.util;
18:
19: import java.lang.reflect.InvocationTargetException;
20: import java.util.HashMap;
21: import java.util.Map;
22:
23: import org.jpox.plugin.PluginManager;
24: import org.xml.sax.EntityResolver;
25:
26: /**
27: * Factory for Entity Resolvers.
28: * This factory holds a cache of resolvers, so we only ever have one of each type.
29: * @version $Revision: 1.4 $
30: */
31: public class EntityResolverFactory {
32: private static Map resolvers = new HashMap();
33:
34: private EntityResolverFactory() {
35: // Private constructor to prevent instantiation
36: }
37:
38: /**
39: * Factory method for EntityResolver instances
40: * @param pluginManager the pluginManager
41: * @param handlerName the handler name
42: * @return The EntityResolver instance for this handler name
43: * @throws InvocationTargetException
44: * @throws IllegalAccessException
45: * @throws InstantiationException
46: * @throws NoSuchMethodException
47: * @throws ClassNotFoundException
48: * @throws IllegalArgumentException
49: * @throws SecurityException
50: */
51: public static EntityResolver getInstance(
52: PluginManager pluginManager, String handlerName)
53: throws SecurityException, IllegalArgumentException,
54: ClassNotFoundException, NoSuchMethodException,
55: InstantiationException, IllegalAccessException,
56: InvocationTargetException {
57: EntityResolver resolver = (EntityResolver) resolvers
58: .get(handlerName);
59: if (resolver == null) {
60: resolver = (EntityResolver) pluginManager
61: .createExecutableExtension(
62: "org.jpox.metadata_handler", "name",
63: handlerName, "entity-resolver", null, null);
64: resolvers.put(handlerName, resolver);
65: }
66: return resolver;
67: }
68: }
|