Source Code Cross Referenced for ExpressionEvaluatorFactory.java in  » Library » Apache-beehive-1.0.2-src » org » apache » beehive » netui » script » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Library » Apache beehive 1.0.2 src » org.apache.beehive.netui.script 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  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:         * $Header:$
018:         */
019:        package org.apache.beehive.netui.script;
020:
021:        import java.util.HashMap;
022:        import java.util.Map;
023:
024:        import org.apache.beehive.netui.util.config.ConfigUtil;
025:        import org.apache.beehive.netui.util.config.bean.NetUIConfig;
026:        import org.apache.beehive.netui.util.config.bean.ExpressionLanguagesConfig;
027:        import org.apache.beehive.netui.util.config.bean.ExpressionLanguageConfig;
028:        import org.apache.beehive.netui.util.logging.Logger;
029:
030:        /**
031:         * Factory used to obtain {@link ExpressionEvaluator} instances.
032:         */
033:        public class ExpressionEvaluatorFactory {
034:
035:            private static final Logger LOGGER = Logger
036:                    .getInstance(ExpressionEvaluatorFactory.class);
037:
038:            /**
039:             * {@link Map} that maps String keys naming a type of {@link ExpressionEvaluator} to a
040:             * {@link ExpressionEngineFactory} that creates an instance of an {@link ExpressionEvaluator}.
041:             */
042:            private static final HashMap FACTORY_MAP = new HashMap();
043:            private static ExpressionEngineFactory DEFAULT_FACTORY;
044:
045:            static {
046:                /* todo: add default beahvrior */
047:                try {
048:                    DEFAULT_FACTORY = initialize(FACTORY_MAP);
049:                } catch (Exception e) {
050:                    DEFAULT_FACTORY = null;
051:                    LOGGER
052:                            .error(
053:                                    "An exception occurred loading the expression evaluator configuration.  Cause: "
054:                                            + e, e);
055:                }
056:            }
057:
058:            /**
059:             * Get the default instance of an expression evaluator.
060:             *
061:             * @return an {@link ExpressionEvaluator}
062:             */
063:            public static ExpressionEvaluator getInstance() {
064:                return getInstance(null);
065:            }
066:
067:            /**
068:             * Get an {@link ExpressionEvaluator} named <code>name</code>.
069:             *
070:             * @param name the name of the {@link ExpressionEvaluator} to obtain.
071:             * @return an {@link ExpressionEvaluator} matching the given name.
072:             * @throws IllegalArgumentException if an {@link ExpressionEvaluator} matching the name is not found
073:             */
074:            public static ExpressionEvaluator getInstance(String name) {
075:                assert DEFAULT_FACTORY != null;
076:                assert FACTORY_MAP != null;
077:
078:                if (name == null)
079:                    return DEFAULT_FACTORY.getInstance();
080:                else if (FACTORY_MAP.containsKey(name))
081:                    return ((ExpressionEngineFactory) FACTORY_MAP.get(name))
082:                            .getInstance();
083:
084:                String msg = "An ExpressionEvaluator named \"" + name
085:                        + "\" is not available.";
086:                LOGGER.error(msg);
087:                throw new IllegalArgumentException(msg);
088:            }
089:
090:            private static ExpressionEngineFactory initialize(Map factoryMap) {
091:                assert factoryMap != null;
092:
093:                NetUIConfig config = ConfigUtil.getConfig();
094:
095:                ExpressionLanguagesConfig elConfig = config
096:                        .getExpressionLanguages();
097:                assert elConfig != null;
098:
099:                ExpressionLanguageConfig[] els = elConfig
100:                        .getExpressionLanguages();
101:                assert els != null;
102:
103:                if (els != null) {
104:                    for (int i = 0; i < els.length; i++) {
105:                        String name = els[i].getName();
106:                        String className = els[i].getFactoryClass();
107:
108:                        ExpressionEngineFactory factory = null;
109:                        try {
110:                            Class type = Class.forName(className);
111:                            factory = (ExpressionEngineFactory) type
112:                                    .newInstance();
113:                        } catch (ClassNotFoundException cnf) {
114:                            LOGGER
115:                                    .warn("Could not create an ExpressionEngineFactory for type \""
116:                                            + className
117:                                            + "\" because the implementation class could not be found.");
118:                            continue;
119:                        } catch (Exception ex) {
120:                            assert ex instanceof  IllegalAccessException
121:                                    || ex instanceof  InstantiationException;
122:                            LOGGER
123:                                    .warn(
124:                                            "Could not create an ExpressionEngineFactory for type \""
125:                                                    + className
126:                                                    + "\" because an error occurred creating the factory.  Cause: "
127:                                                    + ex, ex);
128:                            continue;
129:                        }
130:
131:                        if (factoryMap.containsKey(name))
132:                            if (LOGGER.isWarnEnabled())
133:                                LOGGER
134:                                        .warn("Overwriting a previously defined ExpressionEngineFactory named \""
135:                                                + name
136:                                                + "\" with a new ExpressionEngineFactory of type \""
137:                                                + className + "\"");
138:                            else
139:                                LOGGER
140:                                        .info("Adding an ExpressionEngineFactory named \""
141:                                                + name
142:                                                + "\" with implementation \""
143:                                                + className + "\"");
144:
145:                        factoryMap.put(name, factory);
146:                    }
147:                }
148:
149:                ExpressionEngineFactory defaultEngineFactory = null;
150:                String defaultLanguage = elConfig.getDefaultLanguage();
151:
152:                if (defaultLanguage != null) {
153:                    defaultEngineFactory = (ExpressionEngineFactory) factoryMap
154:                            .get(defaultLanguage);
155:                    if (defaultEngineFactory != null) {
156:                        LOGGER
157:                                .info("Using a default expression evaluator of type \""
158:                                        + factoryMap.get(defaultLanguage)
159:                                                .getClass().getName() + "\"");
160:                    } else {
161:                        String msg = "The default ExpressionEvaluator named \""
162:                                + defaultLanguage
163:                                + "\" was specified, but the ExpressionEngineFactory could not be found.";
164:                        LOGGER.warn(msg);
165:
166:                        throw new RuntimeException(msg);
167:                    }
168:                } else {
169:                    String msg = "There is no default expression engine specified.";
170:                    LOGGER.error(msg);
171:                    throw new RuntimeException(msg);
172:                }
173:
174:                return defaultEngineFactory;
175:            }
176:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.