Source Code Cross Referenced for PrettyPrintXMLStreamWriter.java in  » Web-Services-apache-cxf-2.0.1 » api » org » apache » cxf » wsdl » 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 » api » org.apache.cxf.wsdl 
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.wsdl;
019:
020:        import java.util.HashMap;
021:        import java.util.Map;
022:        import java.util.Stack;
023:
024:        import javax.wsdl.Binding;
025:        import javax.wsdl.BindingFault;
026:        import javax.wsdl.BindingInput;
027:        import javax.wsdl.BindingOperation;
028:        import javax.wsdl.BindingOutput;
029:        import javax.wsdl.Definition;
030:        import javax.wsdl.Message;
031:        import javax.wsdl.Operation;
032:        import javax.wsdl.Port;
033:        import javax.wsdl.Service;
034:        import javax.wsdl.Types;
035:        import javax.xml.namespace.NamespaceContext;
036:        import javax.xml.namespace.QName;
037:        import javax.xml.stream.XMLStreamException;
038:        import javax.xml.stream.XMLStreamWriter;
039:
040:        public class PrettyPrintXMLStreamWriter implements  XMLStreamWriter {
041:
042:            static final Map<Class<?>, Integer> WSDL_INDENT_MAP = new HashMap<Class<?>, Integer>();
043:            static final int DEFAULT_INDENT_LEVEL = 2;
044:
045:            XMLStreamWriter baseWriter;
046:
047:            int indent;
048:            Stack<CurrentElement> elems = new Stack<CurrentElement>();
049:            QName currElem;
050:            boolean nestedStartElement;
051:
052:            public PrettyPrintXMLStreamWriter(XMLStreamWriter writer,
053:                    Class<?> parent) {
054:                baseWriter = writer;
055:                indent = getIndentLevel(parent);
056:            }
057:
058:            public void writeSpaces() throws XMLStreamException {
059:                for (int i = 0; i < indent; i++) {
060:                    baseWriter.writeCharacters(" ");
061:                }
062:            }
063:
064:            public void indentWithSpaces() throws XMLStreamException {
065:                writeSpaces();
066:                indent();
067:            }
068:
069:            public void indent() {
070:                indent += DEFAULT_INDENT_LEVEL;
071:            }
072:
073:            public void unindent() {
074:                indent -= DEFAULT_INDENT_LEVEL;
075:            }
076:
077:            public void close() throws XMLStreamException {
078:                baseWriter.close();
079:            }
080:
081:            public void flush() throws XMLStreamException {
082:                baseWriter.flush();
083:            }
084:
085:            public NamespaceContext getNamespaceContext() {
086:                return baseWriter.getNamespaceContext();
087:            }
088:
089:            public java.lang.String getPrefix(java.lang.String uri)
090:                    throws XMLStreamException {
091:                return baseWriter.getPrefix(uri);
092:            }
093:
094:            public java.lang.Object getProperty(java.lang.String name)
095:                    throws IllegalArgumentException {
096:                return baseWriter.getProperty(name);
097:            }
098:
099:            public void setDefaultNamespace(java.lang.String uri)
100:                    throws XMLStreamException {
101:                baseWriter.setDefaultNamespace(uri);
102:            }
103:
104:            public void setNamespaceContext(NamespaceContext context)
105:                    throws XMLStreamException {
106:                baseWriter.setNamespaceContext(context);
107:            }
108:
109:            public void setPrefix(java.lang.String prefix, java.lang.String uri)
110:                    throws XMLStreamException {
111:                baseWriter.setPrefix(prefix, uri);
112:            }
113:
114:            public void writeAttribute(java.lang.String localName,
115:                    java.lang.String value) throws XMLStreamException {
116:                writeAttribute(null, localName, value);
117:            }
118:
119:            public void writeAttribute(java.lang.String namespaceURI,
120:                    java.lang.String localName, java.lang.String value)
121:                    throws XMLStreamException {
122:                writeAttribute(null, namespaceURI, localName, value);
123:            }
124:
125:            public void writeAttribute(java.lang.String prefix,
126:                    java.lang.String namespaceURI, java.lang.String localName,
127:                    java.lang.String value) throws XMLStreamException {
128:                baseWriter.writeAttribute(prefix, namespaceURI, localName,
129:                        value);
130:            }
131:
132:            public void writeCData(java.lang.String data)
133:                    throws XMLStreamException {
134:                baseWriter.writeCData(data);
135:            }
136:
137:            public void writeCharacters(char[] text, int start, int len)
138:                    throws XMLStreamException {
139:                baseWriter.writeCharacters(text, start, len);
140:            }
141:
142:            public void writeCharacters(java.lang.String text)
143:                    throws XMLStreamException {
144:                baseWriter.writeCharacters(text);
145:            }
146:
147:            public void writeComment(java.lang.String data)
148:                    throws XMLStreamException {
149:                baseWriter.writeComment(data);
150:            }
151:
152:            public void writeDefaultNamespace(java.lang.String namespaceURI)
153:                    throws XMLStreamException {
154:                baseWriter.writeDefaultNamespace(namespaceURI);
155:            }
156:
157:            public void writeDTD(java.lang.String dtd)
158:                    throws XMLStreamException {
159:                baseWriter.writeDTD(dtd);
160:            }
161:
162:            public void writeEmptyElement(java.lang.String localName)
163:                    throws XMLStreamException {
164:                baseWriter.writeEmptyElement(localName);
165:            }
166:
167:            public void writeEmptyElement(java.lang.String namespaceURI,
168:                    java.lang.String localName) throws XMLStreamException {
169:                writeEmptyElement(null, namespaceURI, localName);
170:            }
171:
172:            public void writeEmptyElement(java.lang.String prefix,
173:                    java.lang.String localName, java.lang.String namespaceURI)
174:                    throws XMLStreamException {
175:                baseWriter.writeEmptyElement(prefix, localName, namespaceURI);
176:            }
177:
178:            public void writeEndDocument() throws XMLStreamException {
179:                baseWriter.writeEndDocument();
180:            }
181:
182:            public void writeEndElement() throws XMLStreamException {
183:                CurrentElement elem = (CurrentElement) elems.pop();
184:                unindent();
185:                if (elem.hasChildElements()) {
186:                    baseWriter.writeCharacters("\n");
187:                    writeSpaces();
188:                }
189:                baseWriter.writeEndElement();
190:                if (elems.empty()) {
191:                    baseWriter.writeCharacters("\n");
192:                }
193:            }
194:
195:            public void writeEntityRef(java.lang.String name)
196:                    throws XMLStreamException {
197:                baseWriter.writeEntityRef(name);
198:            }
199:
200:            public void writeNamespace(java.lang.String prefix,
201:                    java.lang.String namespaceURI) throws XMLStreamException {
202:                baseWriter.writeNamespace(prefix, namespaceURI);
203:            }
204:
205:            public void writeProcessingInstruction(java.lang.String target)
206:                    throws XMLStreamException {
207:                baseWriter.writeProcessingInstruction(target);
208:            }
209:
210:            public void writeProcessingInstruction(java.lang.String target,
211:                    java.lang.String data) throws XMLStreamException {
212:                baseWriter.writeProcessingInstruction(target, data);
213:            }
214:
215:            public void writeStartDocument() throws XMLStreamException {
216:                baseWriter.writeStartDocument();
217:            }
218:
219:            public void writeStartDocument(java.lang.String version)
220:                    throws XMLStreamException {
221:                baseWriter.writeStartDocument(version);
222:            }
223:
224:            public void writeStartDocument(java.lang.String encoding,
225:                    java.lang.String version) throws XMLStreamException {
226:                baseWriter.writeStartDocument(encoding, version);
227:            }
228:
229:            public void writeStartElement(java.lang.String localName)
230:                    throws XMLStreamException {
231:                writeStartElement(null, null, localName);
232:            }
233:
234:            public void writeStartElement(java.lang.String namespaceURI,
235:                    java.lang.String localName) throws XMLStreamException {
236:                writeStartElement(null, namespaceURI, localName);
237:            }
238:
239:            public void writeStartElement(java.lang.String prefix,
240:                    java.lang.String localName, java.lang.String namespaceURI)
241:                    throws XMLStreamException {
242:                QName currElemName = new QName(namespaceURI, localName);
243:                if (elems.empty()) {
244:                    indentWithSpaces();
245:                } else {
246:                    baseWriter.writeCharacters("");
247:                    baseWriter.writeCharacters("\n");
248:                    indentWithSpaces();
249:                    CurrentElement elem = (CurrentElement) elems.peek();
250:                    elem.setChildElements(true);
251:                }
252:                baseWriter.writeStartElement(prefix, localName, namespaceURI);
253:                elems.push(new CurrentElement(currElemName));
254:            }
255:
256:            private int getIndentLevel(Class<?> parent) {
257:                Integer result = (Integer) WSDL_INDENT_MAP.get(parent);
258:                if (result == null) {
259:                    return DEFAULT_INDENT_LEVEL;
260:                }
261:                return result.intValue();
262:            }
263:
264:            static {
265:                WSDL_INDENT_MAP.put(Definition.class, new Integer(
266:                        DEFAULT_INDENT_LEVEL));
267:                WSDL_INDENT_MAP.put(Binding.class, new Integer(
268:                        DEFAULT_INDENT_LEVEL * 2));
269:                WSDL_INDENT_MAP.put(BindingFault.class, new Integer(
270:                        DEFAULT_INDENT_LEVEL * 3));
271:                WSDL_INDENT_MAP.put(BindingInput.class, new Integer(
272:                        DEFAULT_INDENT_LEVEL * 3));
273:                WSDL_INDENT_MAP.put(BindingOutput.class, new Integer(
274:                        DEFAULT_INDENT_LEVEL * 3));
275:                WSDL_INDENT_MAP.put(BindingOperation.class, new Integer(
276:                        DEFAULT_INDENT_LEVEL * 3));
277:                WSDL_INDENT_MAP.put(Message.class, new Integer(
278:                        DEFAULT_INDENT_LEVEL * 2));
279:                WSDL_INDENT_MAP.put(Operation.class, new Integer(
280:                        DEFAULT_INDENT_LEVEL * 3));
281:                WSDL_INDENT_MAP.put(Port.class, new Integer(
282:                        DEFAULT_INDENT_LEVEL * 3));
283:                WSDL_INDENT_MAP.put(Service.class, new Integer(
284:                        DEFAULT_INDENT_LEVEL * 2));
285:                WSDL_INDENT_MAP.put(Types.class, new Integer(
286:                        DEFAULT_INDENT_LEVEL * 2));
287:            }
288:
289:            class CurrentElement {
290:                private QName name;
291:                private boolean hasChildElements;
292:
293:                CurrentElement(QName qname) {
294:                    name = qname;
295:                }
296:
297:                public QName getQName() {
298:                    return name;
299:                }
300:
301:                public boolean hasChildElements() {
302:                    return hasChildElements;
303:                }
304:
305:                public void setChildElements(boolean childElements) {
306:                    hasChildElements = childElements;
307:                }
308:            }
309:
310:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.