Source Code Cross Referenced for ExpressionEvaluatorImpl.java in  » Library » Apache-beehive-1.0.2-src » org » apache » beehive » netui » script » el » 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.el 
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.el;
020:
021:        import javax.servlet.jsp.el.VariableResolver;
022:
023:        import org.apache.beehive.netui.script.Expression;
024:        import org.apache.beehive.netui.script.ExpressionEvaluator;
025:        import org.apache.beehive.netui.script.ExpressionEvaluationException;
026:        import org.apache.beehive.netui.script.ExpressionUpdateException;
027:        import org.apache.beehive.netui.script.IllegalExpressionException;
028:        import org.apache.beehive.netui.script.el.util.ParseUtils;
029:        import org.apache.beehive.netui.util.logging.Logger;
030:
031:        /**
032:         *
033:         */
034:        public class ExpressionEvaluatorImpl implements  ExpressionEvaluator {
035:
036:            private static final Logger LOGGER = Logger
037:                    .getInstance(ExpressionEvaluatorImpl.class);
038:            private static final boolean TRACE_ENABLED = LOGGER
039:                    .isTraceEnabled();
040:
041:            /**
042:             * Factory that creates an instance of an {@link ExpressionEvaluator} for this expression language.
043:             */
044:            public static class NetUIELEngineFactory extends
045:                    org.apache.beehive.netui.script.ExpressionEngineFactory {
046:
047:                public ExpressionEvaluator getInstance() {
048:                    return new ExpressionEvaluatorImpl();
049:                }
050:            }
051:
052:            public Object evaluateStrict(String expression,
053:                    VariableResolver variableResolver)
054:                    throws ExpressionEvaluationException {
055:
056:                assert variableResolver instanceof  NetUIReadVariableResolver;
057:
058:                NetUIReadVariableResolver netuiVariableResolver = (NetUIReadVariableResolver) variableResolver;
059:                try {
060:                    return ParseUtils.evaluate(expression,
061:                            netuiVariableResolver);
062:                } catch (Exception e) {
063:                    String contextStr = ParseUtils
064:                            .getContextString(netuiVariableResolver
065:                                    .getAvailableVariables());
066:                    String msg = "Caught exception when evaluating expression \""
067:                            + expression
068:                            + "\" with available binding contexts "
069:                            + contextStr
070:                            + ". Root cause: "
071:                            + ParseUtils.getRootCause(e).toString();
072:                    LOGGER.error(msg, e);
073:                    throw new ExpressionEvaluationException(msg, expression, e);
074:                }
075:            }
076:
077:            public void update(String expression, Object value,
078:                    VariableResolver variableResolver, boolean requestParameter)
079:                    throws ExpressionUpdateException {
080:
081:                assert variableResolver instanceof  NetUIVariableResolver;
082:                NetUIVariableResolver vr = (NetUIVariableResolver) variableResolver;
083:
084:                try {
085:                    if (TRACE_ENABLED)
086:                        LOGGER
087:                                .trace("Update expression \"" + expression
088:                                        + "\"");
089:
090:                    ParseUtils.update(expression, value, vr);
091:                } catch (Exception e) {
092:                    String contextStr = ParseUtils.getContextString(vr
093:                            .getAvailableVariables());
094:                    String msg = "Exception when attempting to update the expression \""
095:                            + expression
096:                            + "\" with available binding contexts "
097:                            + contextStr
098:                            + ". Root cause: "
099:                            + ParseUtils.getRootCause(e).toString();
100:
101:                    LOGGER.error(msg, e);
102:                    ExpressionUpdateException eee = new ExpressionUpdateException(
103:                            msg, expression, e);
104:                    eee.setLocalizedMessage(msg);
105:                    throw eee;
106:                }
107:            }
108:
109:            public String changeContext(String expression, String oldContext,
110:                    String newContext, int lookupIndex)
111:                    throws ExpressionEvaluationException {
112:
113:                try {
114:                    ParsedExpression pe = ParseUtils.parse(expression);
115:                    return pe.changeContext(oldContext, newContext,
116:                            new Integer(lookupIndex));
117:                } catch (Exception e) {
118:                    String msg = "Error when trying to replace old context '"
119:                            + oldContext + "' with new context '" + newContext
120:                            + "' and index '" + lookupIndex + "': "
121:                            + ParseUtils.getRootCause(e).toString();
122:
123:                    LOGGER.error(msg, e);
124:                    throw new ExpressionEvaluationException(msg, e);
125:                }
126:            }
127:
128:            public String qualify(String contextName, String expression)
129:                    throws ExpressionEvaluationException {
130:                try {
131:                    ParsedExpression pe = ParseUtils.parse(expression);
132:                    return pe.qualify(contextName);
133:                } catch (Exception e) {
134:                    String msg = "Error when trying to create an expression in namespace \""
135:                            + contextName
136:                            + "\" with fragment \""
137:                            + expression
138:                            + "\".  Root cause: "
139:                            + ParseUtils.getRootCause(e).toString();
140:
141:                    throw new ExpressionEvaluationException(msg, e);
142:                }
143:            }
144:
145:            public boolean isExpression(String expression) {
146:                try {
147:                    ParsedExpression pe = ParseUtils.parse(expression);
148:                    return pe.isExpression();
149:                } catch (Exception e) {
150:                    LOGGER.error("Exception parsing expression \"" + expression
151:                            + "\".  Cause: "
152:                            + ParseUtils.getRootCause(e).toString(), e);
153:
154:                    if (e instanceof  IllegalExpressionException)
155:                        throw (IllegalExpressionException) e;
156:                    else if (e instanceof  ExpressionParseException)
157:                        throw new IllegalExpressionException(e);
158:                    else
159:                        return false;
160:                }
161:            }
162:
163:            public boolean containsExpression(String expression) {
164:                if (expression == null)
165:                    return false;
166:
167:                try {
168:                    ParsedExpression pe = ParseUtils.parse(expression);
169:                    assert pe != null;
170:                    return pe.containsExpression();
171:                } catch (Exception e) {
172:                    LOGGER.error("Exception checking for expressions in \""
173:                            + expression + "\"", e);
174:                    return false;
175:                }
176:            }
177:
178:            public Expression parseExpression(String expression) {
179:                if (isExpression(expression)) {
180:                    ParsedExpression pe = ParseUtils.parse(expression);
181:                    assert pe != null;
182:                    return pe.getAtomicExpressionTerm();
183:                } else
184:                    throw new IllegalExpressionException(
185:                            "The expression \""
186:                                    + expression
187:                                    + "\" can not be parsed as it is not an atomic expression.");
188:            }
189:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.