KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > webflow > core > DefaultExpressionParserFactory


1 /*
2  * Copyright 2002-2006 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.core;
17
18 import org.springframework.binding.expression.ExpressionParser;
19
20 /**
21  * Static helper factory that creates instances of the default expression parser
22  * used by Spring Web Flow when requested. Marked final with a private
23  * constructor to prevent subclassing.
24  * <p>
25  * The default is an OGNL based expression parser. Also asserts that OGNL is in
26  * the classpath when this class is loaded.
27  *
28  * @author Keith Donald
29  */

30 public final class DefaultExpressionParserFactory {
31
32     /**
33      * The singleton instance.
34      */

35     private static ExpressionParser INSTANCE;
36
37     // static factory - not instantiable
38
private DefaultExpressionParserFactory() {
39     }
40
41     /**
42      * Returns the default expression parser. The returned expression parser is
43      * a thread-safe object.
44      * @return the expression parser
45      */

46     public static synchronized ExpressionParser getExpressionParser() {
47         if (INSTANCE == null) {
48             INSTANCE = createDefaultExpressionParser();
49         }
50         return INSTANCE;
51     }
52
53     /**
54      * Create the default expression parser.
55      * @return the default expression parser
56      */

57     private static ExpressionParser createDefaultExpressionParser() {
58         try {
59             Class.forName("ognl.Ognl");
60             return new WebFlowOgnlExpressionParser();
61         } catch (ClassNotFoundException JavaDoc e) {
62             throw new IllegalStateException JavaDoc(
63                     "Unable to load the default expression parser: OGNL could not be found in the classpath. "
64                     + "Please add OGNL 2.x to your classpath or set the default ExpressionParser instance to something that is in the classpath. "
65                     + "Details: " + e.getMessage());
66         } catch (NoClassDefFoundError JavaDoc e) {
67             throw new IllegalStateException JavaDoc(
68                     "Unable to construct the default expression parser: ognl.Ognl could not be instantiated. "
69                     + "Please add OGNL 2.x to your classpath or set the default ExpressionParser instance to something that is in the classpath. "
70                     + "Details: " + e);
71         }
72     }
73 }
Popular Tags