KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ojb > broker > util > IdentityMapFactory


1 package org.apache.ojb.broker.util;
2
3 /* Copyright 2003-2005 The Apache Software Foundation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * 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 JavaDoc;
19
20 public final class IdentityMapFactory
21 {
22     private static boolean HAS_JDK_IDENTITY_MAP = true;
23     private static final String JavaDoc CLASS_NAME = "java.util.IdentityHashMap";
24     private static Class JavaDoc JDK_IDENTITY_MAP;
25
26     static
27     {
28         try
29         {
30             JDK_IDENTITY_MAP = ClassHelper.getClassLoader().loadClass(CLASS_NAME);
31         }
32         catch (ClassNotFoundException JavaDoc e)
33         {
34             HAS_JDK_IDENTITY_MAP = false;
35         }
36     }
37     
38     private IdentityMapFactory() {}
39
40     public static Map JavaDoc getIdentityMap()
41     {
42         Map JavaDoc retval = null;
43         if (HAS_JDK_IDENTITY_MAP)
44         {
45             try
46             {
47                 retval = (Map JavaDoc) JDK_IDENTITY_MAP.newInstance();
48             }
49             catch (InstantiationException JavaDoc e)
50             {
51                 HAS_JDK_IDENTITY_MAP = false;
52             }
53             catch (IllegalAccessException JavaDoc e)
54             {
55                 HAS_JDK_IDENTITY_MAP = false;
56             }
57         }
58         if (!HAS_JDK_IDENTITY_MAP)
59         {
60             retval = new org.apache.ojb.broker.util.IdentityHashMap();
61         }
62         return retval;
63     }
64 }
65
Popular Tags