Source Code Cross Referenced for SaveExchangeToFile.java in  » ESB » cbesb-1.2 » com » bostechcorp » cbesb » custom » 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 » ESB » cbesb 1.2 » com.bostechcorp.cbesb.custom 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.bostechcorp.cbesb.custom;
002:
003:        import java.io.File;
004:        import java.io.FileWriter;
005:        import java.io.IOException;
006:        import java.util.LinkedList;
007:        import java.util.Map;
008:
009:        import javax.jbi.component.ComponentContext;
010:        import javax.jbi.messaging.DeliveryChannel;
011:        import javax.jbi.messaging.MessageExchange;
012:        import javax.jbi.messaging.NormalizedMessage;
013:        import javax.xml.parsers.DocumentBuilder;
014:        import javax.xml.parsers.DocumentBuilderFactory;
015:        import javax.xml.transform.Source;
016:        import javax.xml.transform.Transformer;
017:        import javax.xml.transform.TransformerFactory;
018:        import javax.xml.transform.dom.DOMSource;
019:        import javax.xml.transform.stream.StreamResult;
020:
021:        import org.apache.commons.logging.Log;
022:        import org.w3c.dom.Document;
023:        import org.w3c.dom.Element;
024:        import org.w3c.dom.Node;
025:        import org.w3c.dom.Text;
026:
027:        import com.bostechcorp.cbesb.runtime.ccsl.lib.IUpocInterface;
028:        import com.bostechcorp.cbesb.runtime.ccsl.nmhandler.NormalizedMessageHandler;
029:        import com.bostechcorp.cbesb.runtime.ccsl.nmhandler.StringSource;
030:
031:        /*
032:         * This class saves message exchanges to a file using an xml format.
033:         */
034:
035:        public class SaveExchangeToFile implements  IUpocInterface {
036:            private boolean isInitialized;
037:            private File saveFile;
038:            protected static final String CBESB_HOME = "CBESB_HOME";
039:
040:            protected static final String CBESB_HOME_SYSPROP = "cbesb.home";
041:
042:            /**
043:             * @param logger - the loggger object
044:             * @param rootDir - the root direcory of the SU
045:             * @param componentContext - the componentContext object
046:             * @param channel - the delivery channel object
047:             * @param exchange - the MessageExchange object passed in
048:             * @param params - the user paramaters in name/value pair
049:             * @return - the LinkList containning one of many MessageExchange objects
050:             * @throws Exception
051:             */
052:            public LinkedList run(Log logger, String rootDir,
053:                    ComponentContext componentContext, DeliveryChannel channel,
054:                    MessageExchange exchange, Map<String, String> params)
055:                    throws Exception {
056:
057:                LinkedList<MessageExchange> sendList = new LinkedList<MessageExchange>();
058:
059:                if (!isInitialized)
060:                    initialize(logger, rootDir, exchange.getEndpoint()
061:                            .getEndpointName());
062:
063:                // Output exchange to a DOM tree
064:                DocumentBuilderFactory factory = DocumentBuilderFactory
065:                        .newInstance();
066:                DocumentBuilder parser = factory.newDocumentBuilder();
067:                Document doc = parser.newDocument();
068:                Element exchangeNode = doc.createElement("exchange");
069:                doc.appendChild(exchangeNode);
070:                Element exchangeId = doc.createElement("exchangeId");
071:                exchangeNode.appendChild(exchangeId);
072:                Text idValue = doc.createTextNode(exchange.getExchangeId());
073:                exchangeId.appendChild(idValue);
074:                Element contentNode = doc.createElement("content");
075:                exchangeNode.appendChild(contentNode);
076:                // Output content elements
077:                NormalizedMessage m = exchange.getMessage("in");
078:                NormalizedMessageHandler nmh = new NormalizedMessageHandler(m);
079:                for (int i = 0; i < nmh.getRecordCount(); i++) {
080:                    Source src = nmh.getRecordAtIndex(i);
081:                    if (src instanceof  StringSource) {
082:                        Element e = doc.createElement("string");
083:                        e.appendChild(doc.createTextNode(((StringSource) src)
084:                                .getText()));
085:                        contentNode.appendChild(e);
086:                    } else if (src instanceof  DOMSource) {
087:                        Element e = doc.createElement("xml");
088:                        Node n = ((DOMSource) src).getNode();
089:                        e.appendChild(n.cloneNode(true));
090:                        contentNode.appendChild(e);
091:
092:                    }
093:                }
094:                // transform to file
095:                StreamResult r = new StreamResult(
096:                        new FileWriter(saveFile, true));
097:                TransformerFactory tf = TransformerFactory.newInstance();
098:                Transformer t = tf.newTransformer();
099:                t.setOutputProperty("indent", "yes");
100:                t.setOutputProperty("omit-xml-declaration", "yes");
101:                t.transform(new DOMSource(doc), r);
102:                r.getWriter().close();
103:
104:                // send the exchange
105:                sendList.add(exchange);
106:                return sendList;
107:            }
108:
109:            private void initialize(Log log, String rootDir, String endpointName)
110:                    throws Exception {
111:                String fileName = getCbesbHomeDir() + File.separator + "save"
112:                        + File.separator + endpointName + ".sav";
113:                saveFile = new File(fileName);
114:                log.info(this .getClass().getName() + " initializing");
115:                log.info("save file=" + saveFile.getAbsolutePath());
116:                isInitialized = true;
117:            }
118:
119:            public String getCbesbHomeDir() {
120:                String esbHome = System.getenv(CBESB_HOME);
121:                String esbHomeProp = System.getProperty(CBESB_HOME_SYSPROP);
122:
123:                // Always to use the -D option to overwrite the system enviroment
124:                if (esbHomeProp != null)
125:                    esbHome = esbHomeProp;
126:                File file = new File(esbHome);
127:                try {
128:                    return file.getCanonicalPath();
129:                } catch (IOException e) {
130:                    //log.error("get cbesb home dir error:",e);
131:                }
132:
133:                return esbHome;
134:            }
135:
136:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.