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


001:        /*
002:         * ChainBuilder ESB
003:         *          Visual Enterprise Integration
004:         * 
005:         * Copyright (C) 2006 Bostech Corporation
006:         * 
007:         * This program is free software; you can redistribute it and/or modify it 
008:         * under the terms of the GNU General Public License as published by the 
009:         * Free Software Foundation; either version 2 of the License, or (at your option) 
010:         * any later version.
011:         *
012:         * This program is distributed in the hope that it will be useful, 
013:         * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
014:         * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 
015:         * for more details.
016:         * 
017:         * You should have received a copy of the GNU General Public License along with 
018:         * this program; if not, write to the Free Software Foundation, Inc., 
019:         * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020:         *
021:         *
022:         * $Id$
023:         */
024:        package com.bostechcorp.cbesb.runtime.cbr;
025:
026:        import javax.xml.transform.dom.DOMSource;
027:        import javax.xml.xpath.XPath;
028:        import javax.xml.xpath.XPathExpressionException;
029:        import javax.xml.xpath.XPathFactory;
030:
031:        import javax.jbi.messaging.MessageExchange;
032:
033:        import org.apache.commons.lang.StringUtils;
034:        import org.apache.commons.logging.Log;
035:        import org.apache.commons.logging.LogFactory;
036:        import org.w3c.dom.Document;
037:
038:        import com.bostechcorp.cbesb.common.runtime.CbesbException;
039:        import com.bostechcorp.cbesb.common.runtime.ConfigurationException;
040:        import com.bostechcorp.cbesb.common.util.Dom;
041:        import com.bostechcorp.cbesb.runtime.ccsl.lib.CcslUpoc;
042:        import com.bostechcorp.cbesb.runtime.ccsl.lib.CcslUtil;
043:
044:        public class TrxIDHandler {
045:            protected transient Log logger = LogFactory
046:                    .getLog(TrxIDHandler.class);
047:
048:            private static TrxIDHandler _instance;
049:
050:            public static synchronized TrxIDHandler instance() {
051:                if (_instance == null) {
052:
053:                    _instance = new TrxIDHandler();
054:
055:                }
056:                return _instance;
057:            }
058:
059:            public String processFixed(String inMessage, int offset, int length) {
060:
061:                return StringUtils.mid(inMessage, offset, length);
062:            }
063:
064:            public String processCSV(String inMessage, String delimiter,
065:                    int index) throws CBRException {
066:
067:                String[] strings = StringUtils.split(inMessage, delimiter);
068:                try {
069:                    return strings[index - 1];
070:                } catch (Exception e) {
071:                    //			
072:                    // logger.error("Exception in processCSV(): " + e.getMessage());
073:                    // if (logger.isDebugEnabled()) {
074:                    // logger.debug("Exception in processCSV():", e);
075:                    // }
076:                    throw new CBRException(
077:                            "Exception occurred while obtaining TrxId for CSV type - "
078:                                    + e.getMessage(),
079:                            "Make sure the message is in the correct format and the delimiter is correct.",
080:                            e);
081:                }
082:            }
083:
084:            public String processX12(String inMessage) throws CBRException {
085:                String startSeg = StringUtils.left(inMessage, 2);
086:                if ("ST".equals(startSeg)) {
087:                    try {
088:                        String separator = StringUtils.mid(inMessage, 2, 1);
089:                        String[] strings = StringUtils.split(inMessage,
090:                                separator);
091:
092:                        return strings[1];
093:                    } catch (Exception e) {
094:                        throw new CBRException(
095:                                "Exception occurred while obtaining TrxId for X12 type - "
096:                                        + e.getMessage(),
097:                                "Make sure the message is in X12 format.", e);
098:                    }
099:                } else {
100:                    throw new CBRException(
101:                            "Failed to obtain X12 TrxId. X12 message starts with invalid segment '"
102:                                    + startSeg + "'.",
103:                            "Make sure the message is in X12 format.");
104:                }
105:            }
106:
107:            public String processHL7(String inMessage) throws CBRException {
108:
109:                int firstCr = inMessage.indexOf(13);
110:                String mshTag = StringUtils.left(inMessage, 3);
111:                if (firstCr > 2 && "MSH".equals(mshTag)) {
112:                    String fieldSep = inMessage.substring(3, 4);
113:                    String[] mshFields = StringUtils.splitPreserveAllTokens(
114:                            inMessage.substring(0, firstCr), fieldSep);
115:
116:                    if (mshFields.length < 12) {
117:                        throw new CBRException(
118:                                "Failed to obtain HL7 TrxId. Invalid number of subfields in MSH segment: "
119:                                        + mshFields.length,
120:                                "Make sure that MSH segment contains 12 fields.");
121:                    }
122:                    return StringUtils.replace(mshFields[8], "^", "_");
123:
124:                } else {
125:                    throw new CBRException(
126:                            "Failed to obtain HL7 TrxId. HL7 message starts with invalid segment '"
127:                                    + mshTag + "'.",
128:                            "Make sure the message is in HL7 format.");
129:                }
130:            }
131:
132:            public String processXPATH(String expression, String inMessage)
133:                    throws CBRException {
134:
135:                if (expression == null
136:                        || (StringUtils.strip(expression)).equals("")) {
137:                    return "";
138:                } else {
139:                    XPath xpath = XPathFactory.newInstance().newXPath();
140:                    Document dom = Dom.createDocumentFromString(inMessage);
141:
142:                    try {
143:                        return xpath.evaluate(expression, dom);
144:                    } catch (XPathExpressionException e) {
145:                        throw new CBRException(
146:                                "Failed to obtain TrxId using XPath expression '"
147:                                        + expression + "'.",
148:                                "Make sure the message is in XML format and the XPath expression is valid.",
149:                                e);
150:                    }
151:                }
152:            }
153:
154:            public String processXPATH(String expression, DOMSource src)
155:                    throws CBRException {
156:                if (expression == null
157:                        || (StringUtils.strip(expression)).equals("")) {
158:                    return "";
159:                } else {
160:                    XPath xpath = XPathFactory.newInstance().newXPath();
161:                    Document dom = src.getNode().getOwnerDocument();
162:                    try {
163:                        return xpath.evaluate(expression, dom);
164:                    } catch (XPathExpressionException e) {
165:                        throw new CBRException(
166:                                "Failed to obtain TrxId using XPath expression '"
167:                                        + expression + "'.",
168:                                "Make sure the message is in XML format and XPath expression is valid.",
169:                                e);
170:                    }
171:                }
172:            }
173:
174:            public String processScript(MessageExchange exchange,
175:                    String scriptEngine, String scriptClass,
176:                    String scriptMethod, String suRootPath)
177:                    throws CbesbException {
178:                try {
179:
180:                    Object[] calledArgs = { logger, exchange };
181:
182:                    String rootDir = "";
183:
184:                    try {
185:                        String[] result = CcslUtil.getRootScriptPath(
186:                                suRootPath, scriptClass);
187:                        rootDir = result[0];
188:                        scriptClass = result[1];
189:                    } catch (Exception e) {
190:                        throw new ConfigurationException(
191:                                "Failed to obtain TrxID using Script method because script file'"
192:                                        + scriptClass + "' is not found.",
193:                                "Make sure the file exists in the 'src/scripts' folder.",
194:                                e);
195:                    }
196:
197:                    Object result = CcslUpoc.runScript(rootDir, scriptEngine,
198:                            scriptClass, scriptMethod, calledArgs, this );
199:
200:                    return result.toString();
201:
202:                } catch (CbesbException e) {
203:                    throw new CBRException(
204:                            "Failed to obtain TrxId using script method '"
205:                                    + scriptMethod + "' in class '"
206:                                    + scriptClass + "'.",
207:                            "Check TrxId script.", e);
208:                }
209:
210:            }
211:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.