Source Code Cross Referenced for CallBsh.java in  » ERP-CRM-Financial » ofbiz » org » ofbiz » minilang » method » callops » 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.callops 
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.callops;
019:
020:        import java.io.*;
021:        import java.util.*;
022:
023:        import org.w3c.dom.*;
024:        import org.ofbiz.base.util.*;
025:        import org.ofbiz.minilang.*;
026:        import org.ofbiz.minilang.method.*;
027:
028:        import bsh.*;
029:
030:        /**
031:         * Simple class to wrap messages that come either from a straight string or a properties file
032:         */
033:        public class CallBsh extends MethodOperation {
034:
035:            public static final String module = CallBsh.class.getName();
036:
037:            public static final int bufferLength = 4096;
038:
039:            String inline = null;
040:            String resource = null;
041:            ContextAccessor errorListAcsr;
042:
043:            public CallBsh(Element element, SimpleMethod simpleMethod) {
044:                super (element, simpleMethod);
045:                inline = UtilXml.elementValue(element);
046:                resource = element.getAttribute("resource");
047:                errorListAcsr = new ContextAccessor(element
048:                        .getAttribute("error-list-name"), "error_list");
049:
050:                if (inline != null && inline.length() > 0) {// pre-parse/compile inlined bsh, only accessed here
051:                }
052:            }
053:
054:            public boolean exec(MethodContext methodContext) {
055:                List messages = (List) errorListAcsr.get(methodContext);
056:
057:                if (messages == null) {
058:                    messages = new LinkedList();
059:                    errorListAcsr.put(methodContext, messages);
060:                }
061:
062:                Interpreter bsh = new Interpreter();
063:                bsh.setClassLoader(methodContext.getLoader());
064:
065:                try {
066:                    // setup environment
067:                    Iterator envEntries = methodContext.getEnvEntryIterator();
068:
069:                    while (envEntries.hasNext()) {
070:                        Map.Entry entry = (Map.Entry) envEntries.next();
071:                        bsh.set((String) entry.getKey(), entry.getValue());
072:                    }
073:
074:                    // run external, from resource, first if resource specified
075:                    if (resource != null && resource.length() > 0) {
076:                        String resource = methodContext
077:                                .expandString(this .resource);
078:                        InputStream is = methodContext.getLoader()
079:                                .getResourceAsStream(resource);
080:
081:                        if (is == null) {
082:                            messages.add("Could not find bsh resource: "
083:                                    + resource);
084:                        } else {
085:                            try {
086:                                BufferedReader reader = new BufferedReader(
087:                                        new InputStreamReader(is));
088:                                StringBuffer outSb = new StringBuffer();
089:
090:                                String tempStr = null;
091:
092:                                while ((tempStr = reader.readLine()) != null) {
093:                                    outSb.append(tempStr);
094:                                    outSb.append('\n');
095:                                }
096:
097:                                Object resourceResult = bsh.eval(outSb
098:                                        .toString());
099:
100:                                // if map is returned, copy values into env
101:                                if ((resourceResult != null)
102:                                        && (resourceResult instanceof  Map)) {
103:                                    methodContext
104:                                            .putAllEnv((Map) resourceResult);
105:                                }
106:                            } catch (IOException e) {
107:                                messages.add("IO error loading bsh resource: "
108:                                        + e.getMessage());
109:                            }
110:                        }
111:                    }
112:
113:                    if (Debug.verboseOn())
114:                        Debug.logVerbose(
115:                                "Running inline BSH script: " + inline, module);
116:                    // run inlined second to it can override the one from the property
117:                    Object inlineResult = bsh.eval(inline);
118:                    if (Debug.verboseOn())
119:                        Debug.logVerbose("Result of inline BSH script: "
120:                                + inlineResult, module);
121:
122:                    // if map is returned, copy values into env
123:                    if ((inlineResult != null) && (inlineResult instanceof  Map)) {
124:                        methodContext.putAllEnv((Map) inlineResult);
125:                    }
126:                } catch (EvalError e) {
127:                    Debug.logError(e, "BeanShell execution caused an error",
128:                            module);
129:                    messages.add("BeanShell execution caused an error: "
130:                            + e.getMessage());
131:                }
132:
133:                // always return true, error messages just go on the error list
134:                return true;
135:            }
136:
137:            public String rawString() {
138:                // TODO: something more than the empty tag
139:                return "<call-bsh/>";
140:            }
141:
142:            public String expandedString(MethodContext methodContext) {
143:                // TODO: something more than a stub/dummy
144:                return this.rawString();
145:            }
146:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.