Source Code Cross Referenced for SourceType.java in  » Web-Services-apache-cxf-2.0.1 » databinding » org » apache » cxf » aegis » type » xml » 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 » Web Services apache cxf 2.0.1 » databinding » org.apache.cxf.aegis.type.xml 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * Licensed to the Apache Software Foundation (ASF) under one
003:         * or more contributor license agreements. See the NOTICE file
004:         * distributed with this work for additional information
005:         * regarding copyright ownership. The ASF licenses this file
006:         * to you under the Apache License, Version 2.0 (the
007:         * "License"); you may not use this file except in compliance
008:         * with the License. You may obtain a copy of the License at
009:         *
010:         * http://www.apache.org/licenses/LICENSE-2.0
011:         *
012:         * Unless required by applicable law or agreed to in writing,
013:         * software distributed under the License is distributed on an
014:         * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015:         * KIND, either express or implied. See the License for the
016:         * specific language governing permissions and limitations
017:         * under the License.
018:         */package org.apache.cxf.aegis.type.xml;
019:
020:        import javax.xml.stream.FactoryConfigurationError;
021:        import javax.xml.stream.XMLStreamException;
022:        import javax.xml.stream.XMLStreamReader;
023:        import javax.xml.stream.XMLStreamWriter;
024:        import javax.xml.transform.Source;
025:        import javax.xml.transform.dom.DOMSource;
026:        import javax.xml.transform.sax.SAXSource;
027:        import javax.xml.transform.stream.StreamSource;
028:
029:        import org.w3c.dom.Document;
030:        import org.w3c.dom.Element;
031:
032:        import org.xml.sax.SAXException;
033:        import org.xml.sax.XMLReader;
034:        import org.xml.sax.helpers.XMLReaderFactory;
035:
036:        import javanet.staxutils.ContentHandlerToXMLStreamWriter;
037:
038:        import org.apache.cxf.aegis.Context;
039:        import org.apache.cxf.aegis.DatabindingException;
040:        import org.apache.cxf.aegis.type.Type;
041:        import org.apache.cxf.aegis.xml.MessageReader;
042:        import org.apache.cxf.aegis.xml.MessageWriter;
043:        import org.apache.cxf.aegis.xml.stax.ElementWriter;
044:        import org.apache.cxf.staxutils.StaxUtils;
045:
046:        /**
047:         * Reads and writes <code>javax.xml.transform.Source</code> types.
048:         * <p>
049:         * The XML stream is converted DOMSource and sent off.
050:         * 
051:         * @author <a href="mailto:dan@envoisolutions.com">Dan Diephouse</a>
052:         * @see javanet.staxutils.StAXSource
053:         * @see javax.xml.stream.XMLInputFactory
054:         * @see org.apache.cxf.aegis.util.STAXUtils
055:         */
056:        public class SourceType extends Type {
057:            public SourceType() {
058:                setTypeClass(Source.class);
059:                setWriteOuter(false);
060:            }
061:
062:            @Override
063:            public Object readObject(MessageReader mreader, Context context)
064:                    throws DatabindingException {
065:                DocumentType dt = (DocumentType) getTypeMapping().getType(
066:                        Document.class);
067:
068:                return new DOMSource((Document) dt.readObject(mreader, context));
069:            }
070:
071:            @Override
072:            public void writeObject(Object object, MessageWriter writer,
073:                    Context context) throws DatabindingException {
074:                try {
075:                    if (object == null) {
076:                        return;
077:                    }
078:
079:                    write((Source) object, ((ElementWriter) writer)
080:                            .getXMLStreamWriter());
081:                } catch (XMLStreamException e) {
082:                    throw new DatabindingException("Could not write xml.", e);
083:                }
084:            }
085:
086:            protected void write(Source object, XMLStreamWriter writer)
087:                    throws FactoryConfigurationError, XMLStreamException,
088:                    DatabindingException {
089:                if (object == null) {
090:                    return;
091:                }
092:
093:                if (object instanceof  DOMSource) {
094:                    DOMSource ds = (DOMSource) object;
095:
096:                    Element element = null;
097:                    if (ds.getNode() instanceof  Element) {
098:                        element = (Element) ds.getNode();
099:                    } else if (ds.getNode() instanceof  Document) {
100:                        element = ((Document) ds.getNode())
101:                                .getDocumentElement();
102:                    } else {
103:                        throw new DatabindingException("Node type "
104:                                + ds.getNode().getClass()
105:                                + " was not understood.");
106:                    }
107:
108:                    StaxUtils.writeElement(element, writer, false);
109:                } else if (object instanceof  SAXSource) {
110:                    SAXSource source = (SAXSource) object;
111:
112:                    try {
113:                        XMLReader xmlReader = source.getXMLReader();
114:                        if (xmlReader == null) {
115:                            xmlReader = createXMLReader();
116:                        }
117:
118:                        xmlReader
119:                                .setContentHandler(new FilteringContentHandlerToXMLStreamWriter(
120:                                        writer));
121:
122:                        xmlReader.parse(source.getInputSource());
123:                    } catch (Exception e) {
124:                        throw new DatabindingException("Could not send xml.", e);
125:                    }
126:                } else if (object instanceof  StreamSource) {
127:                    StreamSource ss = (StreamSource) object;
128:                    XMLStreamReader reader = StaxUtils.createXMLStreamReader(ss
129:                            .getInputStream(), null);
130:                    StaxUtils.copy(reader, writer);
131:                }
132:            }
133:
134:            protected XMLReader createXMLReader() throws SAXException {
135:                // In JDK 1.4, the xml reader factory does not look for META-INF
136:                // services
137:                // If the org.xml.sax.driver system property is not defined, and
138:                // exception will be thrown.
139:                // In these cases, default to xerces parser
140:                try {
141:                    return XMLReaderFactory.createXMLReader();
142:                } catch (Exception e) {
143:                    return XMLReaderFactory
144:                            .createXMLReader("org.apache.xerces.parsers.SAXParser");
145:                }
146:            }
147:
148:            class FilteringContentHandlerToXMLStreamWriter extends
149:                    ContentHandlerToXMLStreamWriter {
150:                public FilteringContentHandlerToXMLStreamWriter(
151:                        XMLStreamWriter xmlStreamWriter) {
152:                    super (xmlStreamWriter);
153:                }
154:
155:                @Override
156:                public void startDocument() throws SAXException {
157:                }
158:
159:                @Override
160:                public void endDocument() throws SAXException {
161:                }
162:            }
163:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.