001 package org.apache.ojb.broker.util;
002
003 /* Copyright 2003-2005 The Apache Software Foundation
004 *
005 * Licensed under the Apache License, Version 2.0 (the "License");
006 * you may not use this file except in compliance with the License.
007 * You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017
018 import java.util.Map;
019
020 public final class IdentityMapFactory
021 {
022 private static boolean HAS_JDK_IDENTITY_MAP = true;
023 private static final String CLASS_NAME = "java.util.IdentityHashMap";
024 private static Class JDK_IDENTITY_MAP;
025
026 static
027 {
028 try
029 {
030 JDK_IDENTITY_MAP = ClassHelper.getClassLoader().loadClass(CLASS_NAME);
031 }
032 catch (ClassNotFoundException e)
033 {
034 HAS_JDK_IDENTITY_MAP = false;
035 }
036 }
037
038 private IdentityMapFactory() {}
039
040 public static Map getIdentityMap()
041 {
042 Map retval = null;
043 if (HAS_JDK_IDENTITY_MAP)
044 {
045 try
046 {
047 retval = (Map) JDK_IDENTITY_MAP.newInstance();
048 }
049 catch (InstantiationException e)
050 {
051 HAS_JDK_IDENTITY_MAP = false;
052 }
053 catch (IllegalAccessException e)
054 {
055 HAS_JDK_IDENTITY_MAP = false;
056 }
057 }
058 if (!HAS_JDK_IDENTITY_MAP)
059 {
060 retval = new org.apache.ojb.broker.util.IdentityHashMap();
061 }
062 return retval;
063 }
064 }