KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ojb > broker > locking > LockManagerHelper


1 package org.apache.ojb.broker.locking;
2
3 /* Copyright 2002-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 org.apache.ojb.broker.OJBRuntimeException;
19 import org.apache.ojb.broker.util.factory.ConfigurableFactory;
20
21 /**
22  * This factory class creates LockManager instances according
23  * to the setting in the OJB properties file.
24  */

25 public class LockManagerHelper
26 {
27     /**
28      * Get a {@link org.apache.ojb.odmg.locking.LockManager} instance. The implementation class is
29      * configured in the OJB properties file.
30      */

31     public static LockManager getLockManagerSpecifiedByConfiguration()
32     {
33         try
34         {
35             // create the kernel LockManager
36
LockManager lm = (new LockManagerFactory()).createNewLockManager();
37             lm.setLockTimeout(LockManager.DEFAULT_LOCK_TIMEOUT);
38             return lm;
39         }
40         catch(Exception JavaDoc e)
41         {
42             throw new OJBRuntimeException("Unexpected failure while start LockManager", e);
43         }
44     }
45
46     /**
47      * Factory to create kernel {@link LockManager} instances.
48      */

49     private static class LockManagerFactory extends ConfigurableFactory
50     {
51         protected String JavaDoc getConfigurationKey()
52         {
53             return "LockManagerClass";
54         }
55
56         LockManager createNewLockManager()
57         {
58             return (LockManager) this.createNewInstance();
59         }
60     }
61
62     /**
63      * Get a {@link org.apache.ojb.odmg.locking.LockManager} instance. The implementation class is
64      * configured in the OJB properties file.
65      */

66     public static LockManager getCommonsLockManager()
67     {
68         LockManager lm = new LockManagerCommonsImpl();
69         lm.setLockTimeout(LockManager.DEFAULT_LOCK_TIMEOUT);
70         return lm;
71     }
72 }
73
Popular Tags