01: package org.apache.ojb.broker.util;
02:
03: /* Copyright 2003-2005 The Apache Software Foundation
04: *
05: * Licensed under the Apache License, Version 2.0 (the "License");
06: * you may not use this file except in compliance with the License.
07: * You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17:
18: import java.util.Map;
19:
20: public final class IdentityMapFactory {
21: private static boolean HAS_JDK_IDENTITY_MAP = true;
22: private static final String CLASS_NAME = "java.util.IdentityHashMap";
23: private static Class JDK_IDENTITY_MAP;
24:
25: static {
26: try {
27: JDK_IDENTITY_MAP = ClassHelper.getClassLoader().loadClass(
28: CLASS_NAME);
29: } catch (ClassNotFoundException e) {
30: HAS_JDK_IDENTITY_MAP = false;
31: }
32: }
33:
34: private IdentityMapFactory() {
35: }
36:
37: public static Map getIdentityMap() {
38: Map retval = null;
39: if (HAS_JDK_IDENTITY_MAP) {
40: try {
41: retval = (Map) JDK_IDENTITY_MAP.newInstance();
42: } catch (InstantiationException e) {
43: HAS_JDK_IDENTITY_MAP = false;
44: } catch (IllegalAccessException e) {
45: HAS_JDK_IDENTITY_MAP = false;
46: }
47: }
48: if (!HAS_JDK_IDENTITY_MAP) {
49: retval = new org.apache.ojb.broker.util.IdentityHashMap();
50: }
51: return retval;
52: }
53: }
|