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


001:        /*
002:         * $Id: SimpleMapProcessor.java,v 1.1 2003/08/17 06:06:13 ajzeneski Exp $
003:         *
004:         *  Copyright (c) 2001, 2002 The Open For Business Project - www.ofbiz.org
005:         *
006:         *  Permission is hereby granted, free of charge, to any person obtaining a
007:         *  copy of this software and associated documentation files (the "Software"),
008:         *  to deal in the Software without restriction, including without limitation
009:         *  the rights to use, copy, modify, merge, publish, distribute, sublicense,
010:         *  and/or sell copies of the Software, and to permit persons to whom the
011:         *  Software is furnished to do so, subject to the following conditions:
012:         *
013:         *  The above copyright notice and this permission notice shall be included
014:         *  in all copies or substantial portions of the Software.
015:         *
016:         *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
017:         *  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
018:         *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
019:         *  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
020:         *  CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
021:         *  OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
022:         *  THE USE OR OTHER DEALINGS IN THE SOFTWARE.
023:         */
024:        package org.ofbiz.minilang;
025:
026:        import java.net.URL;
027:        import java.util.HashMap;
028:        import java.util.Iterator;
029:        import java.util.List;
030:        import java.util.Locale;
031:        import java.util.Map;
032:
033:        import org.ofbiz.base.util.UtilCache;
034:        import org.ofbiz.base.util.UtilURL;
035:        import org.ofbiz.base.util.UtilXml;
036:        import org.ofbiz.minilang.operation.MapProcessor;
037:        import org.w3c.dom.Document;
038:        import org.w3c.dom.Element;
039:
040:        /**
041:         * SimpleMapProcessor Mini Language
042:         *
043:         * @author     <a href="mailto:jonesde@ofbiz.org">David E. Jones</a>
044:         * @version    $Revision: 1.1 $
045:         * @since      2.0
046:         */
047:        public class SimpleMapProcessor {
048:
049:            protected static UtilCache simpleMapProcessorsResourceCache = new UtilCache(
050:                    "minilang.SimpleMapProcessorsResource", 0, 0);
051:            protected static UtilCache simpleMapProcessorsURLCache = new UtilCache(
052:                    "minilang.SimpleMapProcessorsURL", 0, 0);
053:
054:            public static void runSimpleMapProcessor(String xmlResource,
055:                    String name, Map inMap, Map results, List messages,
056:                    Locale locale) throws MiniLangException {
057:                runSimpleMapProcessor(xmlResource, name, inMap, results,
058:                        messages, locale, null);
059:            }
060:
061:            public static void runSimpleMapProcessor(String xmlResource,
062:                    String name, Map inMap, Map results, List messages,
063:                    Locale locale, ClassLoader loader) throws MiniLangException {
064:                if (loader == null)
065:                    loader = Thread.currentThread().getContextClassLoader();
066:
067:                Map mapProcessors = getProcessors(xmlResource, name, loader);
068:                MapProcessor processor = (MapProcessor) mapProcessors.get(name);
069:
070:                if (processor == null) {
071:                    throw new MiniLangException(
072:                            "Could not find SimpleMapProcessor named " + name
073:                                    + " in XML document resource: "
074:                                    + xmlResource);
075:                }
076:
077:                if (processor != null)
078:                    processor.exec(inMap, results, messages, locale, loader);
079:            }
080:
081:            public static void runSimpleMapProcessor(URL xmlURL, String name,
082:                    Map inMap, Map results, List messages, Locale locale,
083:                    ClassLoader loader) throws MiniLangException {
084:                if (loader == null)
085:                    loader = Thread.currentThread().getContextClassLoader();
086:
087:                Map mapProcessors = getProcessors(xmlURL, name);
088:                MapProcessor processor = (MapProcessor) mapProcessors.get(name);
089:
090:                if (processor == null) {
091:                    throw new MiniLangException(
092:                            "Could not find SimpleMapProcessor named " + name
093:                                    + " in XML document: " + xmlURL.toString());
094:                }
095:
096:                if (processor != null)
097:                    processor.exec(inMap, results, messages, locale, loader);
098:            }
099:
100:            protected static Map getProcessors(String xmlResource, String name,
101:                    ClassLoader loader) throws MiniLangException {
102:                Map simpleMapProcessors = (Map) simpleMapProcessorsResourceCache
103:                        .get(xmlResource);
104:
105:                if (simpleMapProcessors == null) {
106:                    synchronized (SimpleMapProcessor.class) {
107:                        simpleMapProcessors = (Map) simpleMapProcessorsResourceCache
108:                                .get(xmlResource);
109:                        if (simpleMapProcessors == null) {
110:                            URL xmlURL = UtilURL.fromResource(xmlResource,
111:                                    loader);
112:
113:                            if (xmlURL == null) {
114:                                throw new MiniLangException(
115:                                        "Could not find SimpleMapProcessor XML document in resource: "
116:                                                + xmlResource);
117:                            }
118:                            simpleMapProcessors = getAllProcessors(xmlURL);
119:
120:                            // put it in the cache
121:                            simpleMapProcessorsResourceCache.put(xmlResource,
122:                                    simpleMapProcessors);
123:                        }
124:                    }
125:                }
126:
127:                return simpleMapProcessors;
128:            }
129:
130:            protected static Map getProcessors(URL xmlURL, String name)
131:                    throws MiniLangException {
132:                Map simpleMapProcessors = (Map) simpleMapProcessorsURLCache
133:                        .get(xmlURL);
134:
135:                if (simpleMapProcessors == null) {
136:                    synchronized (SimpleMapProcessor.class) {
137:                        simpleMapProcessors = (Map) simpleMapProcessorsURLCache
138:                                .get(xmlURL);
139:                        if (simpleMapProcessors == null) {
140:                            simpleMapProcessors = getAllProcessors(xmlURL);
141:
142:                            // put it in the cache
143:                            simpleMapProcessorsURLCache.put(xmlURL,
144:                                    simpleMapProcessors);
145:                        }
146:                    }
147:                }
148:
149:                return simpleMapProcessors;
150:            }
151:
152:            protected static Map getAllProcessors(URL xmlURL)
153:                    throws MiniLangException {
154:                Map mapProcessors = new HashMap();
155:
156:                // read in the file
157:                Document document = null;
158:
159:                try {
160:                    document = UtilXml.readXmlDocument(xmlURL, true);
161:                } catch (java.io.IOException e) {
162:                    throw new MiniLangException("Could not read XML file", e);
163:                } catch (org.xml.sax.SAXException e) {
164:                    throw new MiniLangException("Could not parse XML file", e);
165:                } catch (javax.xml.parsers.ParserConfigurationException e) {
166:                    throw new MiniLangException(
167:                            "XML parser not setup correctly", e);
168:                }
169:
170:                if (document == null) {
171:                    throw new MiniLangException(
172:                            "Could not find SimpleMapProcessor XML document: "
173:                                    + xmlURL.toString());
174:                }
175:
176:                Element rootElement = document.getDocumentElement();
177:                List simpleMapProcessorElements = UtilXml.childElementList(
178:                        rootElement, "simple-map-processor");
179:                Iterator strProcorIter = simpleMapProcessorElements.iterator();
180:
181:                while (strProcorIter.hasNext()) {
182:                    Element simpleMapProcessorElement = (Element) strProcorIter
183:                            .next();
184:                    MapProcessor processor = new MapProcessor(
185:                            simpleMapProcessorElement);
186:
187:                    mapProcessors.put(simpleMapProcessorElement
188:                            .getAttribute("name"), processor);
189:                }
190:
191:                return mapProcessors;
192:            }
193:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.