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


001:        /*
002:         * ChainBuilder ESB
003:         * 		Visual Enterprise Integration
004:         * 
005:         * Copyright (C) 2007 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: JbiWrapperHandler.java 9472 2007-10-09 15:24:17Z elu $
023:         */
024:        package com.bostechcorp.cbesb.runtime.ccsl.messages;
025:
026:        import java.util.HashMap;
027:        import java.util.Iterator;
028:        import java.util.List;
029:        import java.util.Vector;
030:
031:        import javax.xml.namespace.QName;
032:        import javax.xml.transform.Source;
033:        import javax.xml.transform.Transformer;
034:        import javax.xml.transform.TransformerFactory;
035:        import javax.xml.transform.dom.DOMResult;
036:        import javax.xml.transform.dom.DOMSource;
037:
038:        import org.apache.commons.logging.Log;
039:        import org.apache.commons.logging.LogFactory;
040:        import org.jdom.Attribute;
041:        import org.jdom.Document;
042:        import org.jdom.Element;
043:        import org.jdom.Namespace;
044:        import org.jdom.input.DOMBuilder;
045:        import org.jdom.output.DOMOutputter;
046:
047:        /**
048:         * This one is not used.
049:         * 
050:         * @deprecated
051:         * 
052:         * @author elu
053:         *
054:         */
055:        public class JbiWrapperHandler {
056:
057:            public static final String JBI_WRAPPER_NS = "http://java.sun.com/xml/ns/jbi/wsdl-11-wrapper";
058:            public static final String JBI_MESSAGE = "message";
059:            public static final String JBI_VERSION = "version";
060:            public static final String JBI_TYPE = "type";
061:            public static final String JBI_NAME = "name";
062:            public static final String JBI_PART = "part";
063:
064:            protected transient Log log = LogFactory.getLog(getClass());
065:
066:            private QName type;
067:            private String name;
068:            private Vector<Source> parts;
069:
070:            private Namespace jbiNamespace;
071:            private HashMap<String, Namespace> namespaceUriMap;
072:            private HashMap<String, Namespace> namespacePrefixMap;
073:            private int namespaceCounter;
074:
075:            public JbiWrapperHandler() {
076:                type = null;
077:                name = null;
078:                parts = new Vector<Source>();
079:                namespaceUriMap = new HashMap<String, Namespace>();
080:                namespacePrefixMap = new HashMap<String, Namespace>();
081:                jbiNamespace = Namespace.getNamespace("jbi", JBI_WRAPPER_NS);
082:            }
083:
084:            /**
085:             * @return the name
086:             */
087:            public String getName() {
088:                return name;
089:            }
090:
091:            /**
092:             * @param name the name to set
093:             */
094:            public void setName(String name) {
095:                this .name = name;
096:            }
097:
098:            /**
099:             * @return the type
100:             */
101:            public QName getType() {
102:                return type;
103:            }
104:
105:            /**
106:             * @param type the type to set
107:             */
108:            public void setType(QName type) {
109:                this .type = type;
110:            }
111:
112:            public void appendPart(Source src) {
113:                parts.add(src);
114:            }
115:
116:            public int getPartCount() {
117:                return parts.size();
118:            }
119:
120:            public Source getPartAtIndex(int index) {
121:                return parts.elementAt(index);
122:            }
123:
124:            public static JbiWrapperHandler createFromSource(Source src)
125:                    throws Exception {
126:                JbiWrapperHandler jbiWrapper = null;
127:                DOMBuilder domBuilder = new DOMBuilder();
128:                Document jdomDoc = domBuilder.build(getDocFromSource(src));
129:                Element rootElement = jdomDoc.getRootElement();
130:
131:                if (!JBI_WRAPPER_NS.equals(rootElement.getNamespaceURI())
132:                        && !JBI_MESSAGE.equals(rootElement.getName())) {
133:                    throw new Exception("Unexpected root element: {"
134:                            + rootElement.getNamespaceURI() + "}"
135:                            + rootElement.getName() + " - should be: {"
136:                            + JBI_WRAPPER_NS + "}" + JBI_MESSAGE);
137:                }
138:                jbiWrapper = new JbiWrapperHandler();
139:
140:                List nsList = rootElement.getAdditionalNamespaces();
141:                for (Iterator iter = nsList.iterator(); iter.hasNext();) {
142:                    Namespace ns = (Namespace) iter.next();
143:                    jbiWrapper.addNamespaceToMaps(ns);
144:                }
145:
146:                List attrList = rootElement.getAttributes();
147:                for (Iterator iter = attrList.iterator(); iter.hasNext();) {
148:                    Attribute attr = (Attribute) iter.next();
149:                    if (JBI_TYPE.equals(attr.getName())) {
150:                        QName type = jbiWrapper.prefixedNameToQName(attr
151:                                .getValue());
152:                        jbiWrapper.setType(type);
153:                    } else if (JBI_NAME.equals(attr.getName())) {
154:                        jbiWrapper.setName(attr.getValue());
155:                    }
156:                }
157:
158:                List children = rootElement.getChildren(JBI_PART, Namespace
159:                        .getNamespace(JBI_WRAPPER_NS));
160:                for (Iterator iter = children.iterator(); iter.hasNext();) {
161:                    Element partElem = (Element) iter.next();
162:                    if (partElem.getChildren().size() > 0) {
163:                        Element child = (Element) partElem.getChildren().get(0);
164:                        Document partDoc = new Document((Element) child
165:                                .detach());
166:                        DOMOutputter domOut = new DOMOutputter();
167:                        org.w3c.dom.Document doc = domOut.output(partDoc);
168:                        DOMSource domSrc = new DOMSource(doc);
169:                        jbiWrapper.appendPart(domSrc);
170:                    }
171:                }
172:
173:                return jbiWrapper;
174:            }
175:
176:            public Source toSource() throws Exception {
177:                Element rootElement = new Element(JBI_MESSAGE, jbiNamespace);
178:                Document jdomDoc = new Document(rootElement);
179:                rootElement.setAttribute(JBI_VERSION, "1.0");
180:                rootElement.setAttribute(JBI_TYPE, QNameToPrefixedName(type));
181:                if (name != null) {
182:                    rootElement.setAttribute(JBI_NAME, name);
183:                }
184:                AddNamespaceDeclarationsToRoot(rootElement);
185:
186:                DOMBuilder domBuilder = new DOMBuilder();
187:                for (int i = 0; i < parts.size(); i++) {
188:                    Source src = parts.elementAt(i);
189:                    Document jdomPartDoc = domBuilder
190:                            .build(getDocFromSource(src));
191:                    Element partElem = new Element(JBI_PART, jbiNamespace);
192:                    rootElement.addContent(partElem);
193:                    partElem.addContent(jdomPartDoc.detachRootElement());
194:                }
195:                DOMOutputter domOut = new DOMOutputter();
196:                org.w3c.dom.Document doc = domOut.output(jdomDoc);
197:
198:                return new DOMSource(doc);
199:            }
200:
201:            protected QName prefixedNameToQName(String prefixedName) {
202:                String prefix;
203:                String localName;
204:                QName qname;
205:                int index = prefixedName.indexOf(':');
206:                if (index > 0) {
207:                    prefix = prefixedName.substring(0, index);
208:                    localName = prefixedName.substring(index + 1);
209:                } else {
210:                    prefix = null;
211:                    localName = prefixedName;
212:                }
213:                Namespace ns = namespacePrefixMap.get(prefix);
214:                if (ns != null) {
215:                    qname = new QName(ns.getURI(), localName);
216:                } else {
217:                    log.error("Unable to resolve namespace prefix " + prefix);
218:                    qname = null;
219:                }
220:                return qname;
221:            }
222:
223:            protected String QNameToPrefixedName(QName qname) {
224:                addNamespace(qname.getNamespaceURI());
225:                Namespace ns = namespaceUriMap.get(qname.getNamespaceURI());
226:                String prefix = ns.getPrefix();
227:                if (prefix == null || prefix.equals("")) {
228:                    return qname.getLocalPart();
229:                } else {
230:                    return prefix + ":" + qname.getLocalPart();
231:                }
232:
233:            }
234:
235:            protected void addNamespace(String NamespaceURI) {
236:                if (!namespaceUriMap.containsKey(NamespaceURI)) {
237:                    String prefix = "q" + namespaceCounter;
238:                    namespaceCounter++;
239:                    Namespace ns = Namespace.getNamespace(prefix, NamespaceURI);
240:                    addNamespaceToMaps(ns);
241:                }
242:            }
243:
244:            protected void AddNamespaceDeclarationsToRoot(Element root) {
245:                for (Iterator iter = namespaceUriMap.values().iterator(); iter
246:                        .hasNext();) {
247:                    root.addNamespaceDeclaration((Namespace) iter.next());
248:                }
249:            }
250:
251:            private void addNamespaceToMaps(Namespace ns) {
252:                namespaceUriMap.put(ns.getURI(), ns);
253:                namespacePrefixMap.put(ns.getPrefix(), ns);
254:            }
255:
256:            protected static org.w3c.dom.Document getDocFromSource(
257:                    Source originalSource) throws Exception {
258:                org.w3c.dom.Node domNode;
259:                if (originalSource instanceof  DOMSource) {
260:                    domNode = ((DOMSource) originalSource).getNode();
261:                } else {
262:                    DOMResult dr = new DOMResult();
263:                    TransformerFactory tf = TransformerFactory.newInstance();
264:                    Transformer t = tf.newTransformer();
265:                    t.transform(originalSource, dr);
266:                    domNode = dr.getNode();
267:                }
268:                if (domNode instanceof  org.w3c.dom.Document) {
269:                    return (org.w3c.dom.Document) domNode;
270:                } else {
271:                    return ((org.w3c.dom.Element) domNode).getOwnerDocument();
272:                }
273:            }
274:
275:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.