Source Code Cross Referenced for SimpleContext.java in  » Library » Apache-commons-scxml-0.6-src » org » apache » commons » scxml » env » 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 commons scxml 0.6 src » org.apache.commons.scxml.env 
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:        package org.apache.commons.scxml.env;
018:
019:        import java.io.Serializable;
020:        import java.util.HashMap;
021:        import java.util.Map;
022:
023:        import org.apache.commons.logging.Log;
024:        import org.apache.commons.logging.LogFactory;
025:        import org.apache.commons.scxml.Context;
026:
027:        /**
028:         * Simple Context wrapping a map of variables.
029:         *
030:         */
031:        public class SimpleContext implements  Context, Serializable {
032:
033:            /** Serial version UID. */
034:            private static final long serialVersionUID = 1L;
035:            /** Implementation independent log category. */
036:            private Log log = LogFactory.getLog(Context.class);
037:            /** The parent Context to this Context. */
038:            private Context parent;
039:            /** The Map of variables and their values in this Context. */
040:            private Map vars;
041:
042:            /**
043:             * Constructor.
044:             *
045:             */
046:            public SimpleContext() {
047:                this (null, null);
048:            }
049:
050:            /**
051:             * Constructor.
052:             *
053:             * @param parent A parent Context, can be null
054:             */
055:            public SimpleContext(final Context parent) {
056:                this (parent, null);
057:            }
058:
059:            /**
060:             * Constructor.
061:             *
062:             * @param initialVars A pre-populated initial variables map
063:             */
064:            public SimpleContext(final Map initialVars) {
065:                this (null, initialVars);
066:            }
067:
068:            /**
069:             * Constructor.
070:             *
071:             * @param parent A parent Context, can be null
072:             * @param initialVars A pre-populated initial variables map
073:             */
074:            public SimpleContext(final Context parent, final Map initialVars) {
075:                this .parent = parent;
076:                if (initialVars == null) {
077:                    this .vars = new HashMap();
078:                } else {
079:                    this .vars = initialVars;
080:                }
081:            }
082:
083:            /**
084:             * Assigns a new value to an existing variable or creates a new one.
085:             * The method searches the chain of parent Contexts for variable
086:             * existence.
087:             *
088:             * @param name The variable name
089:             * @param value The variable value
090:             * @see org.apache.commons.scxml.Context#set(String, Object)
091:             */
092:            public void set(final String name, final Object value) {
093:                if (vars.containsKey(name)) { //first try to override local
094:                    setLocal(name, value);
095:                } else if (parent != null && parent.has(name)) { //then check for global
096:                    parent.set(name, value);
097:                } else { //otherwise create a new local variable
098:                    setLocal(name, value);
099:                }
100:            }
101:
102:            /**
103:             * Get the value of this variable; delegating to parent.
104:             *
105:             * @param name The variable name
106:             * @return Object The variable value
107:             * @see org.apache.commons.scxml.Context#get(java.lang.String)
108:             */
109:            public Object get(final String name) {
110:                if (vars.containsKey(name)) {
111:                    return vars.get(name);
112:                } else if (parent != null) {
113:                    return parent.get(name);
114:                } else {
115:                    return null;
116:                }
117:            }
118:
119:            /**
120:             * Check if this variable exists, delegating to parent.
121:             *
122:             * @param name The variable name
123:             * @return boolean true if this variable exists
124:             * @see org.apache.commons.scxml.Context#has(java.lang.String)
125:             */
126:            public boolean has(final String name) {
127:                if (vars.containsKey(name)) {
128:                    return true;
129:                } else if (parent != null && parent.has(name)) {
130:                    return true;
131:                }
132:                return false;
133:            }
134:
135:            /**
136:             * Clear this Context.
137:             *
138:             * @see org.apache.commons.scxml.Context#reset()
139:             */
140:            public void reset() {
141:                vars.clear();
142:            }
143:
144:            /**
145:             * Get the parent Context, may be null.
146:             *
147:             * @return Context The parent Context
148:             * @see org.apache.commons.scxml.Context#getParent()
149:             */
150:            public Context getParent() {
151:                return parent;
152:            }
153:
154:            /**
155:             * Assigns a new value to an existing variable or creates a new one.
156:             * The method allows to shaddow a variable of the same name up the
157:             * Context chain.
158:             *
159:             * @param name The variable name
160:             * @param value The variable value
161:             * @see org.apache.commons.scxml.Context#setLocal(String, Object)
162:             */
163:            public void setLocal(final String name, final Object value) {
164:                vars.put(name, value);
165:                if (log.isDebugEnabled() && !name.equals("_ALL_STATES")) {
166:                    log.debug(name + " = " + String.valueOf(value));
167:                }
168:            }
169:
170:            /**
171:             * Set the variables map.
172:             *
173:             * @param vars The new Map of variables.
174:             */
175:            protected void setVars(final Map vars) {
176:                this .vars = vars;
177:            }
178:
179:            /**
180:             * Get the Map of all local variables in this Context.
181:             *
182:             * @return Returns the vars.
183:             */
184:            public Map getVars() {
185:                return vars;
186:            }
187:
188:            /**
189:             * Set the log used by this <code>Context</code> instance.
190:             *
191:             * @param log The new log.
192:             */
193:            protected void setLog(final Log log) {
194:                this .log = log;
195:            }
196:
197:            /**
198:             * Get the log used by this <code>Context</code> instance.
199:             *
200:             * @return Log The log being used.
201:             */
202:            protected Log getLog() {
203:                return log;
204:            }
205:
206:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.