Source Code Cross Referenced for RoutingRulesHandler.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 java.io.File;
027:        import java.util.Vector;
028:
029:        import javax.xml.namespace.QName;
030:        import javax.xml.parsers.DocumentBuilder;
031:        import javax.xml.parsers.DocumentBuilderFactory;
032:
033:        import org.apache.commons.logging.Log;
034:        import org.apache.commons.logging.LogFactory;
035:        import org.w3c.dom.Document;
036:        import org.w3c.dom.Element;
037:        import org.w3c.dom.NamedNodeMap;
038:        import org.w3c.dom.Node;
039:
040:        import com.bostechcorp.cbesb.common.runtime.CbesbException;
041:        import com.bostechcorp.cbesb.common.runtime.ConfigurationException;
042:
043:        public class RoutingRulesHandler {
044:            protected final transient Log logger = LogFactory
045:                    .getLog(getClass());
046:
047:            public static final String ROUTINGRULES_NS_URI = "http://cbesb.bostechcorp.com/cbr/routingrules/1.0";
048:
049:            public static final String ROUTINGRULES = "routingRules";
050:
051:            public static final String ROUTINGRULE = "routingRule";
052:
053:            public static final String EXPRESSION = "expression";
054:
055:            public static final String TARGET = "target";
056:
057:            public static final String INTERFACE = "interface";
058:
059:            public static final String SERVICE = "service";
060:
061:            public static final String OPERATION = "operation";
062:
063:            public static final String TIMEOUT = "timeout";
064:
065:            private RoutingRuleElement routingRules[];
066:
067:            private int currentIndex;
068:
069:            public RoutingRulesHandler() {
070:            }
071:
072:            public int getCurrentIndex() {
073:                return currentIndex;
074:            }
075:
076:            public void setCurrentIndex(int currentIndex) {
077:                this .currentIndex = currentIndex;
078:            }
079:
080:            public int size() {
081:                if (routingRules == null) {
082:                    return 0;
083:                } else {
084:                    return routingRules.length;
085:                }
086:            }
087:
088:            public RoutingRuleElement getRoutingRuleAtIndex(int index) {
089:                RoutingRuleElement re = null;
090:
091:                if (routingRules != null) {
092:                    if (index >= 0 && index < routingRules.length) {
093:                        re = routingRules[index];
094:                    }
095:                }
096:
097:                return re;
098:            }
099:
100:            public static RoutingRulesHandler load(File sourceFile)
101:                    throws CbesbException {
102:                Log logger = LogFactory.getLog(RoutingRulesHandler.class);
103:
104:                Vector<RoutingRuleElement> tmpRules = new Vector<RoutingRuleElement>();
105:
106:                try {
107:                    DocumentBuilderFactory dbf = DocumentBuilderFactory
108:                            .newInstance();
109:                    dbf.setNamespaceAware(true);
110:                    DocumentBuilder db = dbf.newDocumentBuilder();
111:                    Document doc = db.parse(sourceFile);
112:                    Element root = doc.getDocumentElement();
113:                    if (root != null
114:                            && root.getNamespaceURI().equals(
115:                                    ROUTINGRULES_NS_URI)
116:                            && root.getLocalName().equals(ROUTINGRULES)) {
117:                        Node child = root.getFirstChild();
118:                        while (child != null) {
119:                            if (child.getNodeType() == Node.ELEMENT_NODE) {
120:                                if (child.getLocalName().equals(ROUTINGRULE)) {
121:                                    tmpRules.add(loadRoutingRule(doc,
122:                                            (Element) child));
123:                                }
124:                            }
125:                            child = child.getNextSibling();
126:                        }
127:                    }
128:                } catch (Exception e) {
129:
130:                    throw new ConfigurationException(
131:                            "Fail to load the CBR routing rule file '"
132:                                    + sourceFile + "'",
133:                            "Check the routing rule file", e);
134:                }
135:
136:                RoutingRulesHandler rr = new RoutingRulesHandler();
137:                rr.routingRules = new RoutingRuleElement[tmpRules.size()];
138:                for (int i = 0; i < tmpRules.size(); i++) {
139:                    rr.routingRules[i] = tmpRules.elementAt(i);
140:                }
141:                tmpRules.clear();
142:                return rr;
143:            }
144:
145:            private static RoutingRuleElement loadRoutingRule(Document doc,
146:                    Element routingRule) throws Exception {
147:
148:                RoutingRuleElement routingRuleElement = new RoutingRuleElement();
149:                Vector<TargetElement> tmpTargets = new Vector<TargetElement>();
150:
151:                Node child = routingRule.getFirstChild();
152:                while (child != null) {
153:                    if (child.getNodeType() == Node.ELEMENT_NODE) {
154:                        if (child.getLocalName().equals(EXPRESSION)) {
155:                            NamedNodeMap attrs = child.getAttributes();
156:                            String type = attrs.getNamedItem("type")
157:                                    .getNodeValue();
158:                            routingRuleElement.setExpressionType(type);
159:
160:                            String value = child.getTextContent();
161:                            routingRuleElement.setExpression(value);
162:                        } else if (child.getLocalName().equals(TARGET)) {
163:                            tmpTargets.add(loadTarget(doc, (Element) child));
164:                        }
165:                    }
166:                    child = child.getNextSibling();
167:                }
168:
169:                TargetElement[] targetArray = new TargetElement[tmpTargets
170:                        .size()];
171:                for (int i = 0; i < tmpTargets.size(); i++) {
172:                    targetArray[i] = tmpTargets.elementAt(i);
173:                }
174:                tmpTargets.clear();
175:                routingRuleElement.setTargets(targetArray);
176:
177:                return routingRuleElement;
178:            }
179:
180:            private static TargetElement loadTarget(Document doc, Element target)
181:                    throws Exception {
182:                TargetElement targetElement = new TargetElement();
183:                Node child = target.getFirstChild();
184:                while (child != null) {
185:                    if (child.getNodeType() == Node.ELEMENT_NODE) {
186:                        if (child.getLocalName().equals(INTERFACE)) {
187:                            String value = child.getTextContent();
188:                            targetElement.setInterface(getQNameFromString(doc,
189:                                    value));
190:                        } else if (child.getLocalName().equals(SERVICE)) {
191:                            String value = child.getTextContent();
192:                            targetElement.setService(getQNameFromString(doc,
193:                                    value));
194:                        } else if (child.getLocalName().equals(OPERATION)) {
195:                            String value = child.getTextContent();
196:                            targetElement.setOperation(getQNameFromString(doc,
197:                                    value));
198:                        } else if (child.getLocalName().equals(TIMEOUT)) {
199:                            String value = child.getTextContent();
200:                            int timeout = Integer.parseInt(value);
201:                            targetElement.setTimeout(timeout);
202:                        }
203:
204:                    }
205:                    child = child.getNextSibling();
206:                }
207:                return targetElement;
208:            }
209:
210:            private static QName getQNameFromString(Document doc, String value) {
211:                String prefix;
212:                String uri;
213:                String localName;
214:                int index = value.indexOf(':');
215:                if (index >= 0) {
216:                    // Namespace Prefix exists, lookup the Namespace URI
217:                    prefix = value.substring(0, index);
218:                    localName = value.substring(index + 1);
219:                    uri = doc.lookupNamespaceURI(prefix);
220:                } else {
221:                    // No Namespace Prefix, look for a default NS
222:                    uri = doc.lookupNamespaceURI(null);
223:                    localName = value;
224:                }
225:                return new QName(uri, localName);
226:            }
227:
228:            public String toString() {
229:                StringBuffer buffer = new StringBuffer();
230:                buffer.append("Count = " + size() + "\n");
231:                for (int i = 0; i < size(); i++) {
232:                    buffer.append("RoutingRuleElement " + i + ":\n");
233:                    buffer.append(routingRules[i].toString());
234:                }
235:                return buffer.toString();
236:            }
237:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.