Source Code Cross Referenced for WrapperBuilderImpl.java in  » ESB » open-esb » com » sun » jbi » wsdl11wrapper » impl » 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 » open esb » com.sun.jbi.wsdl11wrapper.impl 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * BEGIN_HEADER - DO NOT EDIT
003:         *
004:         * The contents of this file are subject to the terms
005:         * of the Common Development and Distribution License
006:         * (the "License").  You may not use this file except
007:         * in compliance with the License.
008:         *
009:         * You can obtain a copy of the license at
010:         * https://open-esb.dev.java.net/public/CDDLv1.0.html.
011:         * See the License for the specific language governing
012:         * permissions and limitations under the License.
013:         *
014:         * When distributing Covered Code, include this CDDL
015:         * HEADER in each file and include the License file at
016:         * https://open-esb.dev.java.net/public/CDDLv1.0.html.
017:         * If applicable add the following below this CDDL HEADER,
018:         * with the fields enclosed by brackets "[]" replaced with
019:         * your own identifying information: Portions Copyright
020:         * [year] [name of copyright owner]
021:         */
022:
023:        /*
024:         * @(#)WrapperBuilderImpl.java
025:         * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
026:         *
027:         * END_HEADER - DO NOT EDIT
028:         */
029:        package com.sun.jbi.wsdl11wrapper.impl;
030:
031:        import com.sun.jbi.wsdl11wrapper.HelperFactory;
032:        import com.sun.jbi.wsdl11wrapper.WrapperBuilder;
033:        import com.sun.jbi.wsdl11wrapper.WrapperProcessingException;
034:        import com.sun.jbi.wsdl11wrapper.util.WrapperUtil;
035:
036:        import java.util.Map;
037:        import java.util.HashMap;
038:        import java.util.List;
039:        import java.util.Iterator;
040:        import javax.wsdl.Definition;
041:        import javax.wsdl.Message;
042:        import javax.wsdl.Part;
043:        import javax.wsdl.WSDLException;
044:        import javax.wsdl.factory.WSDLFactory;
045:        import javax.xml.namespace.QName;
046:        import org.w3c.dom.Element;
047:        import org.w3c.dom.Node;
048:        import org.w3c.dom.NodeList;
049:        import org.w3c.dom.Document;
050:
051:        import javax.xml.parsers.DocumentBuilder;
052:        import javax.xml.parsers.DocumentBuilderFactory;
053:        import javax.xml.parsers.ParserConfigurationException;
054:
055:        /**
056:         * Assists in building the WSDL 1.1 wrapper for normalized messages specified by JBI
057:         *
058:         * Usage sequence:
059:         * initialize()
060:         * addParts() or multiple addPart() calls
061:         * getResult()
062:         *
063:         * The same instance should not be used by multiple threads concurrently as it is
064:         * not guaranteed to be thread safe - and maintains state
065:         *
066:         * The re-use of the same instance however is encouraged.
067:         *
068:         * @author aegloff
069:         */
070:        public class WrapperBuilderImpl implements  WrapperBuilder {
071:
072:            DocumentBuilder mBuilder;
073:            Document normalDoc;
074:            Element jbiMessageWrapper;
075:            Message messageDefinition;
076:            WSDLInfo info;
077:            boolean isResultPrepared;
078:            Map mPartNameToPartNodes;
079:
080:            /**
081:             * Creates a new instance
082:             *
083:             * The preferred way to create and use this builder implementation is to use
084:             * the <code>HelperFactory</code> instead.
085:             */
086:            public WrapperBuilderImpl() throws WrapperProcessingException {
087:            }
088:
089:            /**
090:             * Re-sets the result document, sets the WSDL message definition of the message to normalize
091:             */
092:            public void initialize(Document docToPopulate,
093:                    Message wsdlMessageDefinition,
094:                    String operationBindingMessageName)
095:                    throws WrapperProcessingException {
096:                isResultPrepared = false;
097:                mPartNameToPartNodes = null;
098:                this .normalDoc = docToPopulate;
099:                this .messageDefinition = wsdlMessageDefinition;
100:                if (docToPopulate == null) {
101:                    try {
102:                        normalDoc = newDocument();
103:                    } catch (ParserConfigurationException ex) {
104:                        throw new WrapperProcessingException(
105:                                "Failed to create an empty target document for building the wrapped normalized message: "
106:                                        + ex.getMessage(), ex);
107:                    }
108:                }
109:
110:                info = WSDLInfo.getInstance(wsdlMessageDefinition);
111:
112:                // Add a message wrapper
113:                jbiMessageWrapper = WrapperUtil.createJBIMessageWrapper(
114:                        normalDoc, info.getMessageType(),
115:                        operationBindingMessageName);
116:                normalDoc.appendChild(jbiMessageWrapper);
117:            }
118:
119:            /**
120:             * Add a part in the right position (wrapped in a JBI part wrapper) to the JBI message wrapper element
121:             * @param partName the name of the message part
122:             * @param partNode the part node (payload)
123:             * The part node does not have to be associated with the normalDoc yet, it will be imported
124:             */
125:            public void addPart(String partName, org.w3c.dom.NodeList partNodes)
126:                    throws WrapperProcessingException {
127:                List partsOrder = info.getPartsOrder();
128:                int partPos = partsOrder.indexOf(partName);
129:                if (partPos > -1) {
130:                    if (mPartNameToPartNodes == null) {
131:                        mPartNameToPartNodes = new HashMap();
132:                    }
133:                    mPartNameToPartNodes.put(partName, partNodes);
134:                } else {
135:                    throw new WrapperProcessingException(
136:                            "Unknown part "
137:                                    + partName
138:                                    + " is not defined in the WSDL message definition for "
139:                                    + info.getMessageType()
140:                                    + ". Cannot add part to normalized message.");
141:                }
142:            }
143:
144:            /**
145:             * Add a part in the right position (wrapped in a JBI part wrapper) to the JBI message wrapper element
146:             * @param partName the name of the message part
147:             * @param partNode the part node (payload)
148:             * The part node does not have to be associated with the normalDoc yet, it will be imported
149:             */
150:            public void addPart(String partName, Element partNode)
151:                    throws WrapperProcessingException {
152:                addPart(partName, new NodeListImpl(partNode));
153:                /*
154:                 List partsOrder = info.getPartsOrder();
155:                 int partPos = partsOrder.indexOf(partName);
156:                 if (partPos > -1) {
157:                 if (mPartNameToPartNodes == null) {
158:                 mPartNameToPartNodes = new HashMap();
159:                 }
160:                 mPartNameToPartNodes.put(partName, partNode);
161:                 } else {
162:                 throw new WrapperProcessingException("Unknown part " + partName + " is not defined in the WSDL message definition for " + info.getMessageType() + ". Cannot add part to normalized message.");
163:                 }
164:                 */
165:            }
166:
167:            /**
168:             * Add parts in the right order (each wrapped in a JBI part wrapper) to the passed in JBI message wrapper element
169:             * The jbiMessageWrapper must be a node of the normalDoc.
170:             * @param normalDoc The target document of the normalization
171:             * @param jbiMessageWrapper The message wrapper element to add the jbi part wrappers and part payload to
172:             * @param messageDefinintion the WSDL message definition
173:             * @param partNameToPartNodes a mapping from the part name to the part NodeList (payload).
174:             * The part node does not have to be associated with the normalDoc yet, it will be imported
175:             */
176:            public void addParts(Map partNameToPartNodes) {
177:                mPartNameToPartNodes = partNameToPartNodes;
178:            }
179:
180:            /**
181:             * Retrieve the Normalized Message with the parts added (addPart(s)) since the initialize() call
182:             * Make sure to only retrieve the result after all desired parts have been added.
183:             *
184:             * Parts added after the result of a build squence has been retrieved already
185:             * (meaning without starting a new build squence by calling initialize) will NOT be included
186:             * in subsequent retrievals of Result
187:             */
188:            public Document getResult() throws WrapperProcessingException {
189:                if (!isResultPrepared) {
190:                    Iterator partsIter = info.getOrderedMessageParts()
191:                            .iterator();
192:                    while (partsIter.hasNext()) {
193:                        Part aPart = (Part) partsIter.next();
194:                        String partName = aPart.getName();
195:                        NodeList nodes = null;
196:                        if (mPartNameToPartNodes != null) {
197:                            Object payload = mPartNameToPartNodes.get(partName);
198:                            if (payload instanceof  NodeList) {
199:                                nodes = (NodeList) payload;
200:                            } else {
201:                                throw new WrapperProcessingException(
202:                                        "Part payload added is not a NodeList: "
203:                                                + (payload == null ? "payload is null"
204:                                                        : payload.getClass()
205:                                                                .getName()));
206:                            }
207:                        }
208:                        Element wrapperElem = WrapperUtil.importJBIWrappedPart(
209:                                normalDoc, nodes);
210:                        jbiMessageWrapper.appendChild(wrapperElem);
211:                    }
212:                    isResultPrepared = true;
213:                }
214:                return normalDoc;
215:            }
216:
217:            public Message getStatusMessage() throws WrapperProcessingException {
218:                Message msg = null;
219:
220:                try {
221:                    WSDLFactory factory = javax.wsdl.factory.WSDLFactory
222:                            .newInstance();
223:                    Definition def = factory.newDefinition();
224:                    msg = def.createMessage();
225:                    msg.setQName(new QName(WrapperBuilder.STATUS_TAG));
226:                    Part part = def.createPart();
227:                    part.setName(WrapperBuilder.RESULT_TAG);
228:                    msg.addPart(part);
229:                } catch (WSDLException ex) {
230:                    throw new WrapperProcessingException(ex);
231:                }
232:
233:                return msg;
234:            }
235:
236:            public Document getStatusDocument(String statusMessage)
237:                    throws WrapperProcessingException {
238:                Document res = null;
239:                try {
240:                    Document doc = DocumentBuilderFactory.newInstance()
241:                            .newDocumentBuilder().newDocument();
242:
243:                    WrapperBuilder builder = HelperFactory.createBuilder();
244:                    builder.initialize(doc, getStatusMessage(), null);
245:                    // add the "wrapper" elements for "normalizing" doc/lit
246:                    Element statusElem = doc
247:                            .createElement(WrapperBuilder.STATUS_TAG);
248:                    statusElem.appendChild(doc.createTextNode(statusMessage));
249:                    builder.addPart(WrapperBuilder.RESULT_TAG, statusElem);
250:                    res = builder.getResult();
251:                } catch (ParserConfigurationException ex) {
252:                    throw new WrapperProcessingException(ex);
253:                }
254:
255:                return res;
256:            }
257:
258:            private Document newDocument() throws ParserConfigurationException {
259:                if (mBuilder == null) {
260:                    DocumentBuilderFactory factory = DocumentBuilderFactory
261:                            .newInstance();
262:                    mBuilder = factory.newDocumentBuilder();
263:                }
264:                return mBuilder.newDocument();
265:            }
266:
267:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.