01: /*
02: * Copyright 2004-2007 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package org.springframework.webflow.conversation.impl;
17:
18: import org.apache.commons.logging.Log;
19: import org.apache.commons.logging.LogFactory;
20: import org.springframework.core.JdkVersion;
21:
22: /**
23: * Simple utility class for creating conversation lock instances based on the
24: * current execution environment.
25: *
26: * @author Keith Donald
27: * @author Rob Harrop
28: */
29: public class ConversationLockFactory {
30:
31: private static final Log logger = LogFactory
32: .getLog(ConversationLockFactory.class);
33:
34: private static boolean utilConcurrentPresent;
35:
36: static {
37: try {
38: Class
39: .forName("EDU.oswego.cs.dl.util.concurrent.ReentrantLock");
40: utilConcurrentPresent = true;
41: } catch (ClassNotFoundException ex) {
42: utilConcurrentPresent = false;
43: }
44: }
45:
46: /**
47: * When running on Java 1.5+, returns a jdk5 concurrent lock. When running on older JDKs with
48: * the 'util.concurrent' package available, returns a util concurrent lock.
49: * In all other cases a "no-op" lock is returned.
50: */
51: public static ConversationLock createLock() {
52: if (JdkVersion.getMajorJavaVersion() >= JdkVersion.JAVA_15) {
53: return new JdkConcurrentConversationLock();
54: } else if (utilConcurrentPresent) {
55: return new UtilConcurrentConversationLock();
56: } else {
57: logger
58: .warn("Unable to enable conversation locking. Switch to Java 5 or above, "
59: + "or put the 'util.concurrent' package on the classpath "
60: + "to enable locking in your environment.");
61: return NoOpConversationLock.INSTANCE;
62: }
63: }
64: }
|