Source Code Cross Referenced for MethodContext.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.HashMap;
021:        import java.util.Iterator;
022:        import java.util.Locale;
023:        import java.util.Map;
024:
025:        import javax.servlet.http.HttpServletRequest;
026:        import javax.servlet.http.HttpServletResponse;
027:
028:        import org.ofbiz.base.util.UtilHttp;
029:        import org.ofbiz.base.util.collections.FlexibleMapAccessor;
030:        import org.ofbiz.base.util.string.FlexibleStringExpander;
031:        import org.ofbiz.entity.GenericDelegator;
032:        import org.ofbiz.entity.GenericValue;
033:        import org.ofbiz.minilang.SimpleMethod;
034:        import org.ofbiz.security.Security;
035:        import org.ofbiz.service.DispatchContext;
036:        import org.ofbiz.service.LocalDispatcher;
037:
038:        /**
039:         * A single operation, does the specified operation on the given field
040:         */
041:        public class MethodContext {
042:
043:            public static final int EVENT = 1;
044:            public static final int SERVICE = 2;
045:
046:            protected int methodType;
047:
048:            protected Map env = new HashMap();
049:            protected Map parameters;
050:            protected Locale locale;
051:            protected ClassLoader loader;
052:            protected LocalDispatcher dispatcher;
053:            protected GenericDelegator delegator;
054:            protected Security security;
055:            protected GenericValue userLogin;
056:
057:            protected HttpServletRequest request = null;
058:            protected HttpServletResponse response = null;
059:
060:            protected Map results = null;
061:            protected DispatchContext ctx;
062:
063:            public MethodContext(HttpServletRequest request,
064:                    HttpServletResponse response, ClassLoader loader) {
065:                this .methodType = MethodContext.EVENT;
066:                this .parameters = UtilHttp.getParameterMap(request);
067:                this .loader = loader;
068:                this .request = request;
069:                this .response = response;
070:                this .locale = UtilHttp.getLocale(request);
071:                this .dispatcher = (LocalDispatcher) request
072:                        .getAttribute("dispatcher");
073:                this .delegator = (GenericDelegator) request
074:                        .getAttribute("delegator");
075:                this .security = (Security) request.getAttribute("security");
076:                this .userLogin = (GenericValue) request.getSession()
077:                        .getAttribute("userLogin");
078:
079:                if (this .loader == null) {
080:                    try {
081:                        this .loader = Thread.currentThread()
082:                                .getContextClassLoader();
083:                    } catch (SecurityException e) {
084:                        this .loader = this .getClass().getClassLoader();
085:                    }
086:                }
087:            }
088:
089:            public MethodContext(DispatchContext ctx, Map context,
090:                    ClassLoader loader) {
091:                this .methodType = MethodContext.SERVICE;
092:                this .parameters = context;
093:                this .loader = loader;
094:                this .locale = (Locale) context.get("locale");
095:                this .dispatcher = ctx.getDispatcher();
096:                this .delegator = ctx.getDelegator();
097:                this .security = ctx.getSecurity();
098:                this .results = new HashMap();
099:                this .userLogin = (GenericValue) context.get("userLogin");
100:
101:                if (this .loader == null) {
102:                    try {
103:                        this .loader = Thread.currentThread()
104:                                .getContextClassLoader();
105:                    } catch (SecurityException e) {
106:                        this .loader = this .getClass().getClassLoader();
107:                    }
108:                }
109:            }
110:
111:            /**
112:             * This is a very simple constructor which assumes the needed objects (dispatcher, 
113:             * delegator, security, request, response, etc) are in the context. 
114:             * Will result in calling method as a service or event, as specified.
115:             */
116:            public MethodContext(Map context, ClassLoader loader, int methodType) {
117:                this .methodType = methodType;
118:                this .parameters = context;
119:                this .loader = loader;
120:                this .locale = (Locale) context.get("locale");
121:                this .dispatcher = (LocalDispatcher) context.get("dispatcher");
122:                this .delegator = (GenericDelegator) context.get("delegator");
123:                this .security = (Security) context.get("security");
124:                this .userLogin = (GenericValue) context.get("userLogin");
125:
126:                if (methodType == MethodContext.EVENT) {
127:                    this .request = (HttpServletRequest) context.get("request");
128:                    this .response = (HttpServletResponse) context
129:                            .get("response");
130:                    if (this .locale == null)
131:                        this .locale = UtilHttp.getLocale(request);
132:
133:                    //make sure the delegator and other objects are in place, getting from 
134:                    // request if necessary; assumes this came through the ControlServlet
135:                    // or something similar
136:                    if (this .request != null) {
137:                        if (this .dispatcher == null)
138:                            this .dispatcher = (LocalDispatcher) this .request
139:                                    .getAttribute("dispatcher");
140:                        if (this .delegator == null)
141:                            this .delegator = (GenericDelegator) this .request
142:                                    .getAttribute("delegator");
143:                        if (this .security == null)
144:                            this .security = (Security) this .request
145:                                    .getAttribute("security");
146:                        if (this .userLogin == null)
147:                            this .userLogin = (GenericValue) this .request
148:                                    .getSession().getAttribute("userLogin");
149:                    }
150:                } else if (methodType == MethodContext.SERVICE) {
151:                    this .results = new HashMap();
152:                }
153:
154:                if (this .loader == null) {
155:                    try {
156:                        this .loader = Thread.currentThread()
157:                                .getContextClassLoader();
158:                    } catch (SecurityException e) {
159:                        this .loader = this .getClass().getClassLoader();
160:                    }
161:                }
162:            }
163:
164:            public void setErrorReturn(String errMsg, SimpleMethod simpleMethod) {
165:                if (getMethodType() == MethodContext.EVENT) {
166:                    putEnv(simpleMethod.getEventErrorMessageName(), errMsg);
167:                    putEnv(simpleMethod.getEventResponseCodeName(),
168:                            simpleMethod.getDefaultErrorCode());
169:                } else if (getMethodType() == MethodContext.SERVICE) {
170:                    putEnv(simpleMethod.getServiceErrorMessageName(), errMsg);
171:                    putEnv(simpleMethod.getServiceResponseMessageName(),
172:                            simpleMethod.getDefaultErrorCode());
173:                }
174:            }
175:
176:            public int getMethodType() {
177:                return this .methodType;
178:            }
179:
180:            public Map getEnvMap() {
181:                return this .env;
182:            }
183:
184:            /** Gets the named value from the environment. Supports the "." (dot) syntax to access Map members and the
185:             * "[]" (bracket) syntax to access List entries. This value is expanded, supporting the insertion of other 
186:             * environment values using the "${}" notation.
187:             * 
188:             * @param key The name of the environment value to get. Can contain "." and "[]" syntax elements as described above.
189:             * @return The environment value if found, otherwise null. 
190:             */
191:            public Object getEnv(String key) {
192:                String ekey = this .expandString(key);
193:                FlexibleMapAccessor fma = new FlexibleMapAccessor(ekey);
194:                return this .getEnv(fma);
195:            }
196:
197:            public Object getEnv(FlexibleMapAccessor fma) {
198:                return fma.get(this .env);
199:            }
200:
201:            /** Puts the named value in the environment. Supports the "." (dot) syntax to access Map members and the
202:             * "[]" (bracket) syntax to access List entries. 
203:             * If the brackets for a list are empty the value will be appended to end of the list,
204:             * otherwise the value will be set in the position of the number in the brackets.
205:             * If a "+" (plus sign) is included inside the square brackets before the index 
206:             * number the value will inserted/added at that index instead of set at that index.
207:             * This value is expanded, supporting the insertion of other 
208:             * environment values using the "${}" notation.
209:             * 
210:             * @param key The name of the environment value to get. Can contain "." syntax elements as described above.
211:             * @param value The value to set in the named environment location.
212:             */
213:            public void putEnv(String key, Object value) {
214:                String ekey = this .expandString(key);
215:                FlexibleMapAccessor fma = new FlexibleMapAccessor(ekey);
216:                this .putEnv(fma, value);
217:            }
218:
219:            public void putEnv(FlexibleMapAccessor fma, Object value) {
220:                fma.put(this .env, value);
221:            }
222:
223:            /** Calls putEnv for each entry in the Map, thus allowing for the additional flexibility in naming 
224:             * supported in that method. 
225:             */
226:            public void putAllEnv(Map values) {
227:                Iterator viter = values.entrySet().iterator();
228:                while (viter.hasNext()) {
229:                    Map.Entry entry = (Map.Entry) viter.next();
230:                    this .putEnv((String) entry.getKey(), entry.getValue());
231:                }
232:            }
233:
234:            /** Removes the named value from the environment. Supports the "." (dot) syntax to access Map members and the
235:             * "[]" (bracket) syntax to access List entries. This value is expanded, supporting the insertion of other 
236:             * environment values using the "${}" notation.
237:             * 
238:             * @param key The name of the environment value to get. Can contain "." syntax elements as described above.
239:             */
240:            public Object removeEnv(String key) {
241:                String ekey = this .expandString(key);
242:                FlexibleMapAccessor fma = new FlexibleMapAccessor(ekey);
243:                return this .removeEnv(fma);
244:            }
245:
246:            public Object removeEnv(FlexibleMapAccessor fma) {
247:                return fma.remove(this .env);
248:            }
249:
250:            public Iterator getEnvEntryIterator() {
251:                return this .env.entrySet().iterator();
252:            }
253:
254:            public Object getParameter(String key) {
255:                return this .parameters.get(key);
256:            }
257:
258:            public void putParameter(String key, Object value) {
259:                this .parameters.put(key, value);
260:            }
261:
262:            public Map getParameters() {
263:                return this .parameters;
264:            }
265:
266:            public ClassLoader getLoader() {
267:                return this .loader;
268:            }
269:
270:            public Locale getLocale() {
271:                return this .locale;
272:            }
273:
274:            public LocalDispatcher getDispatcher() {
275:                return this .dispatcher;
276:            }
277:
278:            public GenericDelegator getDelegator() {
279:                return this .delegator;
280:            }
281:
282:            public Security getSecurity() {
283:                return this .security;
284:            }
285:
286:            public HttpServletRequest getRequest() {
287:                return this .request;
288:            }
289:
290:            public HttpServletResponse getResponse() {
291:                return this .response;
292:            }
293:
294:            public GenericValue getUserLogin() {
295:                return this .userLogin;
296:            }
297:
298:            public void setUserLogin(GenericValue userLogin,
299:                    String userLoginEnvName) {
300:                this .userLogin = userLogin;
301:                this .putEnv(userLoginEnvName, userLogin);
302:            }
303:
304:            public Object getResult(String key) {
305:                return this .results.get(key);
306:            }
307:
308:            public void putResult(String key, Object value) {
309:                this .results.put(key, value);
310:            }
311:
312:            public Map getResults() {
313:                return this .results;
314:            }
315:
316:            /** Expands environment variables delimited with ${} */
317:            public String expandString(String original) {
318:                return FlexibleStringExpander.expandString(original, this .env);
319:            }
320:
321:            public String expandString(FlexibleStringExpander originalExdr) {
322:                return originalExdr.expandString(this.env);
323:            }
324:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.