Source Code Cross Referenced for ParametersCallbackMap.java in  » Scripting » scriptella » scriptella » driver » 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 » Scripting » scriptella » scriptella.driver.script 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2006-2007 The Scriptella Project Team.
003:         *
004:         * Licensed under the Apache License, Version 2.0 (the "License");
005:         * you may not use this file except in compliance with the License.
006:         * You may obtain a copy of the License at
007:         *
008:         *      http://www.apache.org/licenses/LICENSE-2.0
009:         *
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS,
012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         * See the License for the specific language governing permissions and
014:         * limitations under the License.
015:         */
016:        package scriptella.driver.script;
017:
018:        import scriptella.spi.ParametersCallback;
019:        import scriptella.spi.QueryCallback;
020:
021:        import java.util.Collection;
022:        import java.util.HashMap;
023:        import java.util.Map;
024:        import java.util.Set;
025:
026:        /**
027:         * {@link java.util.Map} implementation of {@link ParametersCallback} for
028:         * integration into Scriptella execution environment.
029:         * <p/>
030:         * This class allows local variables to be set via {@link #put(String,Object)} method.
031:         * <br>{@link #getParameter(String)} allows reading variables.
032:         * <p>In query mode, a virtual variable <code>query</code> is available and exposes a method
033:         * {@link #next()} to populate result set.
034:         * </p>
035:         * <p><em>Note:</em> current implementation does not distinguish if a vairable is absent
036:         * or has a value of null.
037:         *
038:         * @author Fyodor Kupolov
039:         * @version 1.0
040:         */
041:        public class ParametersCallbackMap implements  ParametersCallback,
042:                Map<String, Object> {
043:            private Map<String, Object> localVariables;
044:            private ParametersCallback parentParameters;
045:            private QueryCallback queryCallback;
046:
047:            /**
048:             * Initializes instance and set parent parameters to use in {@link #getParameter(String)}.
049:             *
050:             * @param parentParameters parent parameters.
051:             */
052:            public ParametersCallbackMap(ParametersCallback parentParameters) {
053:                this .parentParameters = parentParameters;
054:            }
055:
056:            /**
057:             * Initializes parameters callback for query element.
058:             * @param parentParameters parent parameters.
059:             * @param queryCallback callback to notify on row iteration. 
060:             */
061:            public ParametersCallbackMap(ParametersCallback parentParameters,
062:                    QueryCallback queryCallback) {
063:                this .parentParameters = parentParameters;
064:                setQueryCallback(queryCallback);
065:            }
066:
067:            /**
068:             * Returns specified variable value.
069:             * <p>The local variables set by {@link #put(String,Object)} method
070:             * take priority of variables in parentParameters object.
071:             *
072:             * @param name variable name
073:             * @return value of variable or null if variable not found.
074:             */
075:            public Object getParameter(final String name) {
076:                Object v = localVariables == null ? null : localVariables
077:                        .get(name);
078:                if (v != null) {
079:                    return v;
080:                }
081:                return parentParameters.getParameter(name);
082:            }
083:
084:            /**
085:             * Use {@link #getParameter(String)}.
086:             *
087:             * @param key variable name.
088:             * @return value of variable.
089:             */
090:            public Object get(Object key) {
091:                return (key instanceof  String) ? getParameter((String) key)
092:                        : null;
093:            }
094:
095:            public boolean containsKey(Object key) {
096:                return (localVariables != null && localVariables
097:                        .containsKey(key))
098:                        || (parentParameters.getParameter((String) key) != null);
099:            }
100:
101:            /**
102:             * Sets local variable.
103:             *
104:             * @param key   variable name.
105:             * @param value variable value.
106:             * @return previous variable value.
107:             */
108:            public Object put(String key, Object value) {
109:                if (localVariables == null) {
110:                    localVariables = new HashMap<String, Object>();
111:                }
112:                return localVariables.put(key, value);
113:            }
114:
115:            /**
116:             * Removes local variable.
117:             *
118:             * @param key variable name.
119:             * @return previous value.
120:             */
121:            public Object remove(Object key) {
122:                return localVariables == null ? null : localVariables
123:                        .remove(key);
124:            }
125:
126:            /**
127:             * Registers local variables.
128:             *
129:             * @param t local variables map.
130:             */
131:            public void putAll(Map<? extends String, ?> t) {
132:                if (localVariables == null) {
133:                    localVariables = new HashMap<String, Object>();
134:                }
135:                localVariables.putAll(t);
136:            }
137:
138:            /**
139:             * Clears local variables.
140:             */
141:            public void clear() {
142:                if (localVariables != null) {
143:                    localVariables.clear();
144:                }
145:            }
146:
147:            /**
148:             * Sets query callback and enables the query mode, i.e. query variable is exposed.
149:             * @param queryCallback query callback.
150:             */
151:            public void setQueryCallback(QueryCallback queryCallback) {
152:                this .queryCallback = queryCallback;
153:                put("query", this );
154:            }
155:
156:            /**
157:             * Executes nested elements and exposes local variables set by the current query.
158:             */
159:            public void next() {
160:                queryCallback.processRow(this );
161:            }
162:
163:            //Unsupported operations
164:
165:            public int size() {
166:                throw new UnsupportedOperationException("size");
167:            }
168:
169:            public boolean isEmpty() {
170:                throw new UnsupportedOperationException("isEmpty");
171:            }
172:
173:            public boolean containsValue(Object value) {
174:                throw new UnsupportedOperationException("containsValue");
175:            }
176:
177:            public Set<String> keySet() {
178:                throw new UnsupportedOperationException("keySet");
179:            }
180:
181:            public Collection<Object> values() {
182:                throw new UnsupportedOperationException("values");
183:            }
184:
185:            public Set<Map.Entry<String, Object>> entrySet() {
186:                throw new UnsupportedOperationException("entrySet");
187:            }
188:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.