Source Code Cross Referenced for CallResultOutputter.java in  » Web-Services » xins » org » xins » server » 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 » xins » org.xins.server 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $Id: CallResultOutputter.java,v 1.51 2007/09/18 08:45:07 agoubard Exp $
003:         *
004:         * Copyright 2003-2007 Orange Nederland Breedband B.V.
005:         * See the COPYRIGHT file for redistribution and use restrictions.
006:         */
007:        package org.xins.server;
008:
009:        import java.io.IOException;
010:        import java.io.UnsupportedEncodingException;
011:        import java.io.Writer;
012:        import java.util.Iterator;
013:
014:        import org.xins.common.MandatoryArgumentChecker;
015:        import org.xins.common.collections.PropertyReader;
016:        import org.xins.common.xml.Element;
017:        import org.xins.common.xml.ElementSerializer;
018:        import org.xins.logdoc.ExceptionUtils;
019:
020:        import org.znerd.xmlenc.XMLEncoder;
021:        import org.znerd.xmlenc.XMLOutputter;
022:
023:        /**
024:         * Converter that can be used by calling conventions to generate responses
025:         * which are compatible with the XINS standard calling convention.
026:         *
027:         * <p>The result output is always in the UTF-8 encoding.
028:         *
029:         * @version $Revision: 1.51 $ $Date: 2007/09/18 08:45:07 $
030:         * @author <a href="mailto:ernst@ernstdehaan.com">Ernst de Haan</a>
031:         * @author <a href="mailto:anthony.goubard@japplis.com">Anthony Goubard</a>
032:         *
033:         * @since XINS 1.5.0
034:         */
035:        public final class CallResultOutputter {
036:
037:            /**
038:             * The first output for each output conversion. Never <code>null</code>.
039:             */
040:            private static final char[] DOCUMENT_PREFACE = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><result"
041:                    .toCharArray();
042:
043:            /**
044:             * The output for the new-style calling convention in case success is
045:             * false, just before the name of the error code.
046:             * Never <code>null</code>.
047:             */
048:            private static final char[] ERRORCODE_IS = " errorcode=\""
049:                    .toCharArray();
050:
051:            /**
052:             * The output just before a parameter name. Never <code>null</code>.
053:             */
054:            private static final char[] PARAM_PREFACE = "<param name=\""
055:                    .toCharArray();
056:
057:            /**
058:             * The output right after a parameter value. Never <code>null</code>.
059:             */
060:            private static final char[] PARAM_SUFFIX = "</param>".toCharArray();
061:
062:            /**
063:             * The final output for each output conversion. Never <code>null</code>.
064:             */
065:            private static final char[] DOCUMENT_SUFFIX = "</result>"
066:                    .toCharArray();
067:
068:            /**
069:             * An <code>XMLEncoder</code> for the UTF-8 encoding. Initialized by the
070:             * class initialized and then never <code>null</code>.
071:             */
072:            private static final XMLEncoder XML_ENCODER;
073:
074:            static {
075:                try {
076:                    XML_ENCODER = XMLEncoder.getEncoder("UTF-8");
077:                } catch (UnsupportedEncodingException exception) {
078:                    Error error = new Error();
079:                    ExceptionUtils.setCause(error, exception);
080:                    throw error;
081:                }
082:            }
083:
084:            /**
085:             * Constructs a new <code>CallResultOutputter</code> object.
086:             */
087:            private CallResultOutputter() {
088:                // empty
089:            }
090:
091:            /**
092:             * Generates XML for the specified call result. The XML is sent to the
093:             * specified output stream.
094:             *
095:             * @param out
096:             *    the output stream to send the XML to, cannot be <code>null</code>.
097:             *
098:             * @param result
099:             *    the call result to convert to XML, cannot be <code>null</code>.
100:             *
101:             * @throws IllegalArgumentException
102:             *    if <code>out      == null
103:             *          || result   == null</code>.
104:             *
105:             * @throws IOException
106:             *    if there was an I/O error while writing to the output stream.
107:             */
108:            public static void output(Writer out, FunctionResult result)
109:                    throws IllegalArgumentException, IOException {
110:
111:                // Check preconditions
112:                MandatoryArgumentChecker.check("out", out, "result", result);
113:
114:                // Output the declaration
115:                out.write(DOCUMENT_PREFACE);
116:
117:                // Output the start of the <result> element
118:                String code = result.getErrorCode();
119:                if (code == null) {
120:                    out.write('>');
121:                } else {
122:                    out.write(ERRORCODE_IS);
123:                    out.write(code);
124:                    out.write('"');
125:                    out.write('>');
126:                }
127:
128:                // Write the output parameters, if any
129:                PropertyReader params = result.getParameters();
130:                if (params != null) {
131:                    Iterator names = params.getNames();
132:                    while (names.hasNext()) {
133:                        String n = (String) names.next();
134:                        if (n != null && n.length() > 0) {
135:                            String v = params.get(n);
136:                            if (v != null && v.length() > 0) {
137:                                out.write(PARAM_PREFACE);
138:                                XML_ENCODER.text(out, n, true);
139:                                out.write('"');
140:                                out.write('>');
141:                                XML_ENCODER.text(out, v, true);
142:                                out.write(PARAM_SUFFIX);
143:                            }
144:                        }
145:                    }
146:                }
147:
148:                // Write the data element, if any
149:                Element dataElement = result.getDataElement();
150:                if (dataElement != null) {
151:                    ElementSerializer serializer = new ElementSerializer();
152:                    XMLOutputter xmlout = new XMLOutputter(out, "UTF-8");
153:                    serializer.output(xmlout, dataElement);
154:                }
155:
156:                // End the root element <result>
157:                out.write(DOCUMENT_SUFFIX);
158:            }
159:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.