Source Code Cross Referenced for RequestCallbackAdapter.java in  » Ajax » GWT » com » google » gwt » user » client » rpc » 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 » Ajax » GWT » com.google.gwt.user.client.rpc.impl 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2007 Google Inc.
003:         * 
004:         * Licensed under the Apache License, Version 2.0 (the "License"); you may not
005:         * use this file except in compliance with the License. You may obtain a copy of
006:         * the License at
007:         * 
008:         * http://www.apache.org/licenses/LICENSE-2.0
009:         * 
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
012:         * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
013:         * License for the specific language governing permissions and limitations under
014:         * the License.
015:         */
016:        package com.google.gwt.user.client.rpc.impl;
017:
018:        import com.google.gwt.http.client.Request;
019:        import com.google.gwt.http.client.RequestCallback;
020:        import com.google.gwt.http.client.Response;
021:        import com.google.gwt.user.client.rpc.AsyncCallback;
022:        import com.google.gwt.user.client.rpc.IncompatibleRemoteServiceException;
023:        import com.google.gwt.user.client.rpc.InvocationException;
024:        import com.google.gwt.user.client.rpc.SerializationException;
025:        import com.google.gwt.user.client.rpc.SerializationStreamFactory;
026:        import com.google.gwt.user.client.rpc.SerializationStreamReader;
027:
028:        /**
029:         * Adapter from a {@link RequestCallback} interface to an {@link AsyncCallback}
030:         * interface.
031:         * 
032:         * For internal use only.
033:         * 
034:         * @param <T> the type parameter for the {@link AsyncCallback}
035:         */
036:        public class RequestCallbackAdapter<T> implements  RequestCallback {
037:            /**
038:             * Enumeration used to read specific return types out of a
039:             * {@link SerializationStreamReader}.
040:             */
041:            public enum ResponseReader {
042:                BOOLEAN {
043:                    @Override
044:                    public Object read(SerializationStreamReader streamReader)
045:                            throws SerializationException {
046:                        return streamReader.readBoolean();
047:                    }
048:                },
049:
050:                BYTE {
051:                    @Override
052:                    public Object read(SerializationStreamReader streamReader)
053:                            throws SerializationException {
054:                        return streamReader.readByte();
055:                    }
056:                },
057:
058:                CHAR {
059:                    @Override
060:                    public Object read(SerializationStreamReader streamReader)
061:                            throws SerializationException {
062:                        return streamReader.readChar();
063:                    }
064:                },
065:
066:                DOUBLE {
067:                    @Override
068:                    public Object read(SerializationStreamReader streamReader)
069:                            throws SerializationException {
070:                        return streamReader.readDouble();
071:                    }
072:                },
073:
074:                FLOAT {
075:                    @Override
076:                    public Object read(SerializationStreamReader streamReader)
077:                            throws SerializationException {
078:                        return streamReader.readFloat();
079:                    }
080:                },
081:
082:                INT {
083:                    @Override
084:                    public Object read(SerializationStreamReader streamReader)
085:                            throws SerializationException {
086:                        return streamReader.readInt();
087:                    }
088:                },
089:
090:                LONG {
091:                    @Override
092:                    public Object read(SerializationStreamReader streamReader)
093:                            throws SerializationException {
094:                        return streamReader.readLong();
095:                    }
096:                },
097:
098:                OBJECT {
099:                    @Override
100:                    public Object read(SerializationStreamReader streamReader)
101:                            throws SerializationException {
102:                        return streamReader.readObject();
103:                    }
104:                },
105:
106:                SHORT {
107:                    @Override
108:                    public Object read(SerializationStreamReader streamReader)
109:                            throws SerializationException {
110:                        return streamReader.readShort();
111:                    }
112:                },
113:
114:                STRING {
115:                    @Override
116:                    public Object read(SerializationStreamReader streamReader)
117:                            throws SerializationException {
118:                        return streamReader.readString();
119:                    }
120:                },
121:
122:                VOID {
123:                    @Override
124:                    public Object read(SerializationStreamReader streamReader) {
125:                        return null;
126:                    }
127:                };
128:
129:                public abstract Object read(
130:                        SerializationStreamReader streamReader)
131:                        throws SerializationException;
132:            }
133:
134:            /**
135:             * {@link AsyncCallback} to notify or success or failure.
136:             */
137:            private final AsyncCallback<T> callback;
138:
139:            /**
140:             * Instance which will read the expected return type out of the
141:             * {@link SerializationStreamReader}.
142:             */
143:            private final ResponseReader responseReader;
144:
145:            /**
146:             * {@link SerializationStreamFactory} for creating
147:             * {@link SerializationStreamReader}s.
148:             */
149:            private final SerializationStreamFactory streamFactory;
150:
151:            public RequestCallbackAdapter(
152:                    SerializationStreamFactory streamFactory,
153:                    AsyncCallback<T> callback, ResponseReader responseReader) {
154:                assert (streamFactory != null);
155:                assert (callback != null);
156:                assert (responseReader != null);
157:
158:                this .streamFactory = streamFactory;
159:                this .callback = callback;
160:                this .responseReader = responseReader;
161:            }
162:
163:            public void onError(Request request, Throwable exception) {
164:                callback.onFailure(exception);
165:            }
166:
167:            @SuppressWarnings("unchecked")
168:            public void onResponseReceived(Request request, Response response) {
169:                T result = null;
170:                Throwable caught = null;
171:                try {
172:                    String encodedResponse = response.getText();
173:
174:                    if (RemoteServiceProxy.isReturnValue(encodedResponse)) {
175:                        result = (T) responseReader.read(streamFactory
176:                                .createStreamReader(encodedResponse));
177:                    } else if (RemoteServiceProxy
178:                            .isThrownException(encodedResponse)) {
179:                        caught = (Throwable) streamFactory.createStreamReader(
180:                                encodedResponse).readObject();
181:                    } else {
182:                        caught = new InvocationException(encodedResponse);
183:                    }
184:                } catch (com.google.gwt.user.client.rpc.SerializationException e) {
185:                    caught = new IncompatibleRemoteServiceException();
186:                } catch (Throwable e) {
187:                    caught = e;
188:                }
189:
190:                if (caught == null) {
191:                    callback.onSuccess(result);
192:                } else {
193:                    callback.onFailure(caught);
194:                }
195:            }
196:        }
w__w___w_.___j_a__v__a_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.