Source Code Cross Referenced for ContextAccessor.java in  » ERP-CRM-Financial » ofbiz » org » ofbiz » minilang » method » 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 » ERP CRM Financial » ofbiz » org.ofbiz.minilang.method 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*******************************************************************************
002:         * Licensed to the Apache Software Foundation (ASF) under one
003:         * or more contributor license agreements.  See the NOTICE file
004:         * distributed with this work for additional information
005:         * regarding copyright ownership.  The ASF licenses this file
006:         * to you under the Apache License, Version 2.0 (the
007:         * "License"); you may not use this file except in compliance
008:         * with the License.  You may obtain a copy of the License at
009:         * 
010:         * http://www.apache.org/licenses/LICENSE-2.0
011:         * 
012:         * Unless required by applicable law or agreed to in writing,
013:         * software distributed under the License is distributed on an
014:         * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015:         * KIND, either express or implied.  See the License for the
016:         * specific language governing permissions and limitations
017:         * under the License.
018:         *******************************************************************************/package org.ofbiz.minilang.method;
019:
020:        import java.util.Map;
021:
022:        import org.ofbiz.base.util.collections.FlexibleMapAccessor;
023:
024:        /**
025:         * Used to flexibly access Map values, supporting the "." (dot) syntax for
026:         * accessing sub-map values and the "[]" (square bracket) syntax for accessing
027:         * list elements. See individual Map operations for more information.
028:         */
029:        public class ContextAccessor {
030:
031:            protected String name;
032:            protected FlexibleMapAccessor fma;
033:            protected boolean needsExpand;
034:            protected boolean empty;
035:
036:            public ContextAccessor(String name) {
037:                init(name);
038:            }
039:
040:            public ContextAccessor(String name, String defaultName) {
041:                if (name == null || name.length() == 0) {
042:                    init(defaultName);
043:                } else {
044:                    init(name);
045:                }
046:            }
047:
048:            protected void init(String name) {
049:                this .name = name;
050:                if (name == null || name.length() == 0) {
051:                    empty = true;
052:                    needsExpand = false;
053:                    fma = new FlexibleMapAccessor(name);
054:                } else {
055:                    empty = false;
056:                    int openPos = name.indexOf("${");
057:                    if (openPos != -1 && name.indexOf("}", openPos) != -1) {
058:                        fma = null;
059:                        needsExpand = true;
060:                    } else {
061:                        fma = new FlexibleMapAccessor(name);
062:                        needsExpand = false;
063:                    }
064:                }
065:            }
066:
067:            public boolean isEmpty() {
068:                return this .empty;
069:            }
070:
071:            /** Based on name get from Map or from List in Map */
072:            public Object get(MethodContext methodContext) {
073:                if (this .needsExpand) {
074:                    return methodContext.getEnv(name);
075:                } else {
076:                    return methodContext.getEnv(fma);
077:                }
078:            }
079:
080:            /** Based on name put in Map or from List in Map;
081:             * If the brackets for a list are empty the value will be appended to the list,
082:             * otherwise the value will be set in the position of the number in the brackets.
083:             * If a "+" (plus sign) is included inside the square brackets before the index 
084:             * number the value will inserted/added at that point instead of set at the point.
085:             */
086:            public void put(MethodContext methodContext, Object value) {
087:                if (this .needsExpand) {
088:                    methodContext.putEnv(name, value);
089:                } else {
090:                    methodContext.putEnv(fma, value);
091:                }
092:            }
093:
094:            /** Based on name remove from Map or from List in Map */
095:            public Object remove(MethodContext methodContext) {
096:                if (this .needsExpand) {
097:                    return methodContext.removeEnv(name);
098:                } else {
099:                    return methodContext.removeEnv(fma);
100:                }
101:            }
102:
103:            /** Based on name get from Map or from List in Map */
104:            public Object get(Map theMap, MethodContext methodContext) {
105:                if (this .needsExpand) {
106:                    FlexibleMapAccessor fma = new FlexibleMapAccessor(
107:                            methodContext.expandString(name));
108:                    return fma.get(theMap);
109:                } else {
110:                    return fma.get(theMap);
111:                }
112:            }
113:
114:            /** Based on name put in Map or from List in Map;
115:             * If the brackets for a list are empty the value will be appended to the list,
116:             * otherwise the value will be set in the position of the number in the brackets.
117:             * If a "+" (plus sign) is included inside the square brackets before the index 
118:             * number the value will inserted/added at that point instead of set at the point.
119:             */
120:            public void put(Map theMap, Object value,
121:                    MethodContext methodContext) {
122:                if (this .needsExpand) {
123:                    FlexibleMapAccessor fma = new FlexibleMapAccessor(
124:                            methodContext.expandString(name));
125:                    fma.put(theMap, value);
126:                } else {
127:                    fma.put(theMap, value);
128:                }
129:            }
130:
131:            /** Based on name remove from Map or from List in Map */
132:            public Object remove(Map theMap, MethodContext methodContext) {
133:                if (this .needsExpand) {
134:                    FlexibleMapAccessor fma = new FlexibleMapAccessor(
135:                            methodContext.expandString(name));
136:                    return fma.remove(theMap);
137:                } else {
138:                    return fma.remove(theMap);
139:                }
140:            }
141:
142:            /** The equals and hashCode methods are imnplemented just case this object is ever accidently used as a Map key */
143:            public int hashCode() {
144:                return this .name.hashCode();
145:            }
146:
147:            /** The equals and hashCode methods are imnplemented just case this object is ever accidently used as a Map key */
148:            public boolean equals(Object obj) {
149:                if (obj instanceof  ContextAccessor) {
150:                    ContextAccessor contextAccessor = (ContextAccessor) obj;
151:                    if (this .name == null) {
152:                        return contextAccessor.name == null;
153:                    }
154:                    return this .name.equals(contextAccessor.name);
155:                } else {
156:                    String str = (String) obj;
157:                    if (this .name == null) {
158:                        return str == null;
159:                    }
160:                    return this .name.equals(str);
161:                }
162:            }
163:
164:            /** To be used for a string representation of the accessor, returns the original name. */
165:            public String toString() {
166:                return this.name;
167:            }
168:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.