Source Code Cross Referenced for ExValue.java in  » Ajax » zk » org » zkoss » zk » xel » 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 » Ajax » zk » org.zkoss.zk.xel 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* ExValue.java
002:
003:        {{IS_NOTE
004:        	Purpose:
005:        		
006:        	Description:
007:        		
008:        	History:
009:        		Fri Aug 31 10:19:38     2007, Created by tomyeh
010:        }}IS_NOTE
011:
012:        Copyright (C) 2007 Potix Corporation. All Rights Reserved.
013:
014:        {{IS_RIGHT
015:        	This program is distributed under GPL Version 2.0 in the hope that
016:        	it will be useful, but WITHOUT ANY WARRANTY.
017:        }}IS_RIGHT
018:         */
019:        package org.zkoss.zk.xel;
020:
021:        import org.zkoss.lang.Classes;
022:        import org.zkoss.xel.Expression;
023:        import org.zkoss.xel.Expressions;
024:        import org.zkoss.xel.XelException;
025:
026:        import org.zkoss.lang.Objects;
027:        import org.zkoss.zk.ui.Page;
028:        import org.zkoss.zk.ui.Component;
029:
030:        /**
031:         * A string value that might carries an expression.
032:         * It is serializable and the expression is parsed by demand.
033:         *
034:         * @author tomyeh
035:         * @since 3.0.0
036:         */
037:        public class ExValue implements  java.io.Serializable {
038:            private String _value;
039:            private Class _expected;
040:            /** Coerced value. Used only if _expr is DUMMY_EXPRESSION. */
041:            private transient Object _coercedVal = Objects.UNKNOWN;
042:            private transient Expression _expr;
043:
044:            /** Constructor.
045:             * @param value the value. It can be null.
046:             */
047:            public ExValue(String value, Class expectedType) {
048:                if (expectedType == null)
049:                    throw new IllegalArgumentException();
050:                _value = value;
051:                _expected = expectedType;
052:            }
053:
054:            /** Tests whether it is an expression.
055:             * Note: it is a wild guess. In other words, it returns false
056:             * only if 100% not an expression.
057:             */
058:            public boolean isExpression() {
059:                return _expr == null ? _value != null
060:                        && _value.indexOf("${") >= 0
061:                        : _expr != Expressions.DUMMY_EXPRESSION;
062:            }
063:
064:            /** Returns the raw value.
065:             * The raw value is the value passed to the constructor.
066:             * That is, it might contain EL expressions.
067:             */
068:            public final String getRawValue() {
069:                return _value;
070:            }
071:
072:            /** Sets the raw value.
073:             * @param value the value. It can be null.
074:             */
075:            public void setRawValue(String value) {
076:                if (!Objects.equals(value, _value)) {
077:                    _value = value;
078:                    _expr = null;
079:                    _coercedVal = Objects.UNKNOWN;
080:                }
081:            }
082:
083:            /** Returns the expected type.
084:             */
085:            public final Class getExpectedType() {
086:                return _expected;
087:            }
088:
089:            /** Sets the expected type.
090:             */
091:            public final void setExpectedType(Class expectedType) {
092:                if (expectedType == null)
093:                    throw new IllegalArgumentException();
094:
095:                if (_expected != expectedType) {
096:                    _expected = expectedType;
097:                    if (_expr != Expressions.DUMMY_EXPRESSION)
098:                        _expr = null; //re-parse
099:                    _coercedVal = Objects.UNKNOWN;
100:                }
101:            }
102:
103:            /** Returns the value after evaluation.
104:             */
105:            public Object getValue(Evaluator eval, Page page)
106:                    throws XelException {
107:                if (_expr == null)
108:                    init(eval);
109:                return _expr == Expressions.DUMMY_EXPRESSION ? coerce() : eval
110:                        .evaluate(page, _expr);
111:            }
112:
113:            /** Returns the value after evaluation.
114:             */
115:            public Object getValue(Evaluator eval, Component comp)
116:                    throws XelException {
117:                if (_expr == null)
118:                    init(eval);
119:                return _expr == Expressions.DUMMY_EXPRESSION ? coerce() : eval
120:                        .evaluate(comp, _expr);
121:            }
122:
123:            private Object coerce() {
124:                if (_coercedVal == Objects.UNKNOWN)
125:                    _coercedVal = Classes.coerce(_expected, _value);
126:                return _coercedVal;
127:            }
128:
129:            private void init(Evaluator eval) throws XelException {
130:                if (_value != null && _value.indexOf("${") >= 0) {
131:                    _expr = eval.parseExpression(_value, _expected);
132:                } else {
133:                    _expr = Expressions.DUMMY_EXPRESSION; //to denote not-an-expr
134:                }
135:            }
136:
137:            private synchronized void readObject(java.io.ObjectInputStream s)
138:                    throws java.io.IOException, ClassNotFoundException {
139:                s.defaultReadObject();
140:                _coercedVal = Objects.UNKNOWN;
141:            }
142:
143:            public String toString() {
144:                return _value;
145:            }
146:
147:            public int hashCode() {
148:                return Objects.hashCode(_value);
149:            }
150:
151:            public boolean equals(Object o) {
152:                if (o instanceof  ExValue) {
153:                    final ExValue val = (ExValue) o;
154:                    return Objects.equals(val._value, _value)
155:                            && Objects.equals(val._expected, _expected);
156:                }
157:                return false;
158:            }
159:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.