Source Code Cross Referenced for RpcLitPayloadSerializer.java in  » 6.0-JDK-Modules-com.sun » xml » com » sun » xml » internal » ws » encoding » jaxb » 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 » 6.0 JDK Modules com.sun » xml » com.sun.xml.internal.ws.encoding.jaxb 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Portions Copyright 2006 Sun Microsystems, Inc.  All Rights Reserved.
003:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004:         *
005:         * This code is free software; you can redistribute it and/or modify it
006:         * under the terms of the GNU General Public License version 2 only, as
007:         * published by the Free Software Foundation.  Sun designates this
008:         * particular file as subject to the "Classpath" exception as provided
009:         * by Sun in the LICENSE file that accompanied this code.
010:         *
011:         * This code is distributed in the hope that it will be useful, but WITHOUT
012:         * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013:         * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
014:         * version 2 for more details (a copy is included in the LICENSE file that
015:         * accompanied this code).
016:         *
017:         * You should have received a copy of the GNU General Public License version
018:         * 2 along with this work; if not, write to the Free Software Foundation,
019:         * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020:         *
021:         * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022:         * CA 95054 USA or visit www.sun.com if you need additional information or
023:         * have any questions.
024:         */
025:
026:        package com.sun.xml.internal.ws.encoding.jaxb;
027:
028:        import com.sun.xml.internal.ws.pept.ept.MessageInfo;
029:        import com.sun.xml.internal.bind.api.BridgeContext;
030:        import static com.sun.xml.internal.ws.client.BindingProviderProperties.JAXB_OUTPUTSTREAM;
031:        import com.sun.xml.internal.ws.encoding.soap.DeserializationException;
032:        import com.sun.xml.internal.ws.encoding.soap.SerializationException;
033:        import com.sun.xml.internal.ws.streaming.XMLStreamReaderUtil;
034:
035:        import javax.xml.namespace.NamespaceContext;
036:        import javax.xml.namespace.QName;
037:        import javax.xml.stream.XMLStreamConstants;
038:        import javax.xml.stream.XMLStreamException;
039:        import javax.xml.stream.XMLStreamReader;
040:        import javax.xml.stream.XMLStreamWriter;
041:        import java.io.IOException;
042:        import java.io.OutputStream;
043:
044:        public class RpcLitPayloadSerializer {
045:
046:            /*
047:             * Uses BridgeContext to serialize the rpc/lit payload. First it writes
048:             * the operation, and then it serializes each parameter
049:             */
050:            public static void serialize(RpcLitPayload obj,
051:                    BridgeContext bridgeContext, MessageInfo messageInfo,
052:                    XMLStreamWriter writer) {
053:                try {
054:                    QName op = obj.getOperation();
055:                    String opURI = op.getNamespaceURI();
056:
057:                    writer.writeStartElement("ans", op.getLocalPart(), opURI);
058:                    writer.setPrefix("ans", opURI);
059:                    writer.writeNamespace("ans", opURI);
060:
061:                    // Pass output stream directly to JAXB when available
062:                    OutputStream os = (OutputStream) messageInfo
063:                            .getMetaData(JAXB_OUTPUTSTREAM);
064:                    if (os != null) {
065:                        /*
066:                         * Make sure that current element is closed before passing the
067:                         * output stream to JAXB. Using Zephyr, it suffices to write
068:                         * an empty string (TODO: other StAX impls?).
069:                         */
070:                        writer.writeCharacters("");
071:
072:                        // Flush output of StAX serializer
073:                        writer.flush();
074:
075:                        NamespaceContext nsc = writer.getNamespaceContext();
076:
077:                        // Let JAXB serialize each param to the output stream
078:                        for (JAXBBridgeInfo param : obj.getBridgeParameters()) {
079:                            param.serialize(bridgeContext, os, nsc);
080:                        }
081:                    } else {
082:                        // Otherwise, use a StAX writer
083:                        for (JAXBBridgeInfo param : obj.getBridgeParameters()) {
084:                            param.serialize(bridgeContext, writer);
085:                        }
086:                    }
087:
088:                    writer.writeEndElement(); // </ans:operation>
089:                } catch (XMLStreamException e) {
090:                    throw new SerializationException(e);
091:                }
092:            }
093:
094:            public static void serialize(RpcLitPayload obj,
095:                    BridgeContext bridgeContext, OutputStream writer) {
096:                QName op = obj.getOperation();
097:                String opURI = op.getNamespaceURI();
098:                String startElm = "<ans:" + op.getLocalPart() + " xmlns:ans=\""
099:                        + opURI + "\">";
100:                String endElm = "</ans:" + op.getLocalPart() + ">";
101:                try {
102:                    writer.write(startElm.getBytes());
103:                    for (JAXBBridgeInfo param : obj.getBridgeParameters()) {
104:                        param.serialize(bridgeContext, writer, null);
105:                    }
106:                    writer.write(endElm.getBytes());
107:                } catch (IOException e) {
108:                    throw new SerializationException(e);
109:                }
110:            }
111:
112:            /*
113:             * Uses BridgeContext to deserialize the rpc/lit payload. First it reads
114:             * the operation element, and then it deserializes each parameter. If the
115:             * expected parameter is not found, it throws an exception
116:             */
117:            public static void deserialize(XMLStreamReader reader,
118:                    RpcLitPayload payload, BridgeContext bridgeContext) {
119:                XMLStreamReaderUtil.nextElementContent(reader); // </operation> or <partName>
120:                for (JAXBBridgeInfo param : payload.getBridgeParameters()) {
121:                    // throw exception if the part accessor name is not what we expect
122:                    QName partName = reader.getName();
123:                    if (!partName.equals(param.getName())) {
124:                        throw new DeserializationException(
125:                                "xsd.unexpectedElementName", new Object[] {
126:                                        param.getName(), partName });
127:                    }
128:                    param.deserialize(reader, bridgeContext);
129:
130:                    // reader could be left on CHARS token rather than <partName>
131:                    if (reader.getEventType() == XMLStreamConstants.CHARACTERS
132:                            && reader.isWhiteSpace()) {
133:                        XMLStreamReaderUtil.nextContent(reader);
134:                    }
135:                }
136:                XMLStreamReaderUtil.nextElementContent(reader); // </env:body>
137:            }
138:        }
w__ww.__java_2_s.c___o__m___ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.