Source Code Cross Referenced for TSHandler.java in  » Database-JDBC-Connection-Pool » jotm-2.0.10 » org » objectweb » jotm » jta » jeremie » 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 » Database JDBC Connection Pool » jotm 2.0.10 » org.objectweb.jotm.jta.jeremie 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * @(#) TSHandler
003:         *
004:         * JOTM: Java Open Transaction Manager
005:         * 
006:         * This module was originally developed by 
007:         *  - INRIA inside the ObjectWeb Consortium(http://www.objectweb.org)
008:         *    
009:         * The original code and portions created by INRIA are 
010:         * Copyright (C) 2002 - INRIA (www.inria.fr)
011:         * All rights reserved.
012:         *
013:         * Redistribution and use in source and binary forms, with or without 
014:         * modification, are permitted provided that the following conditions are met:
015:         *
016:         * -Redistributions of source code must retain the above copyright notice, this
017:         * list of conditions and the following disclaimer. 
018:         *
019:         * -Redistributions in binary form must reproduce the above copyright notice, 
020:         * this list of conditions and the following disclaimer in the documentation 
021:         * and/or other materials provided with the distribution. 
022:         *
023:         * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
024:         * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
025:         * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
026:         * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
027:         * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
028:         * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
029:         * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
030:         * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
031:         * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
032:         * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
033:         * POSSIBILITY OF SUCH DAMAGE.
034:         * 
035:         * --------------------------------------------------------------------------
036:         * $Id: TSHandler.java,v 1.3 2004/05/14 17:49:12 tonyortiz Exp $
037:         * --------------------------------------------------------------------------
038:         */
039:        package org.objectweb.jotm.jta.jeremie;
040:
041:        import org.objectweb.jeremie.services.handler.api.Service;
042:        import org.objectweb.jotm.TransactionContext;
043:        import org.objectweb.jonathan.apis.kernel.Context;
044:        import org.objectweb.jonathan.apis.kernel.JonathanException;
045:        import org.objectweb.jonathan.presentation.api.MarshallerFactory;
046:        import org.objectweb.jonathan.presentation.api.Marshaller;
047:        import org.objectweb.jonathan.presentation.api.UnMarshaller;
048:        import org.objectweb.jonathan.resources.api.Chunk;
049:        import org.objectweb.jonathan.helpers.MessageHelpers;
050:        import org.omg.IOP.ServiceContext;
051:
052:        public class TSHandler implements  Service {
053:
054:            private JotmTransactionSender sender = null;
055:            private JotmTransactionReceiver receiver = null;
056:            private MarshallerFactory mf;
057:            private int service_id = 0;
058:
059:            /** 
060:             * Builds a new Jeremie transaction service handler instance.
061:             * @param c unused
062:             * @param used_components the components used to initialize the new TSHandler.
063:             * @exception JonathanException if something goes wrong.
064:             */
065:            public TSHandler(Context c, Object[] used_components)
066:                    throws JonathanException {
067:                int sid = ((Integer) used_components[0]).intValue();
068:                if (sid != Integer.MAX_VALUE) {
069:                    service_id = sid;
070:                }
071:                try {
072:                    sender = (JotmTransactionSender) used_components[1];
073:                    receiver = (JotmTransactionReceiver) used_components[2];
074:                    mf = (MarshallerFactory) used_components[3];
075:                } catch (Exception e) {
076:                    throw new JonathanException(e);
077:                }
078:            }
079:
080:            /** 
081:             * Returns a request context.
082:             * @return                  a service context.
083:             */
084:            public ServiceContext getRequestContext(int id, boolean r,
085:                    byte[] key, Context k) {
086:                if (sender == null) {
087:                    return null;
088:                }
089:                TransactionContext ctx = sender.sending_request();
090:                return encodeContext(ctx);
091:            }
092:
093:            /** 
094:             * Returns a reply context.
095:             * @return           a service context.
096:             */
097:            public ServiceContext getReplyContext(int id, Context k) {
098:                if (receiver == null) {
099:                    return null;
100:                }
101:                TransactionContext ctx = receiver.sending_reply();
102:                return encodeContext(ctx);
103:            }
104:
105:            /** 
106:             * This method is called by the services handler to let the operations 
107:             * related to the target service be performed on request arrival.
108:             * @param context            the service context of the request;
109:             */
110:            public void handleRequestContext(ServiceContext context, int id,
111:                    boolean r, byte[] key, Context k) {
112:                if (receiver == null || context == null) {
113:                    return;
114:                }
115:                TransactionContext ctx = decodeContext(context);
116:                if (ctx != null) {
117:                    receiver.received_request(ctx);
118:                }
119:            }
120:
121:            /** 
122:             * This method is called by the services handler to let the operations 
123:             * related to the target service be performed on reply arrival.
124:             * @param context     the service context of the reply;
125:             */
126:            public void handleReplyContext(ServiceContext context, int id,
127:                    Context k) {
128:                if (sender == null || context == null) {
129:                    return;
130:                }
131:                TransactionContext ctx = decodeContext(context);
132:                if (ctx != null) {
133:                    sender.received_reply(ctx);
134:                }
135:            }
136:
137:            /**
138:             * Encodes a Transaction Service propagation context into an IOP service
139:             * context.
140:             * @param ctx the propagation context to be encoded.
141:             * @return the resulting IOP service context.
142:             */
143:            private ServiceContext encodeContext(TransactionContext ctx) {
144:                if (ctx == null) {
145:                    return null;
146:                }
147:                Marshaller marshaller = mf.newMarshaller();
148:                byte[] byteArray = null;
149:                try {
150:                    marshaller.writeValue(ctx);
151:                    byteArray = MessageHelpers.copy(marshaller);
152:                    marshaller.close();
153:                } catch (Exception e) {
154:                    System.err.println("TSHandler.encodeContext: exception");
155:                }
156:                return new ServiceContext(service_id, byteArray);
157:            }
158:
159:            /**
160:             * Decodes a Transaction Service propagation context from an IOP service
161:             * context.
162:             *
163:             * @param ctx the IOP service context containing the encoded propagation
164:             *    context.
165:             * @return the decoded propagation context.
166:             */
167:            private TransactionContext decodeContext(ServiceContext sc) {
168:                if (sc == null || sc.context_data == null
169:                        || sc.context_data.length == 0) {
170:                    return null;
171:                }
172:                TransactionContext ctx = null;
173:                byte[] byteArray = sc.context_data;
174:                UnMarshaller unmarshaller = mf.newUnMarshaller(new Chunk(
175:                        byteArray, 0, byteArray.length), 0);
176:                try {
177:                    ctx = (TransactionContext) unmarshaller.readValue();
178:                    unmarshaller.close();
179:                } catch (Exception e) {
180:                    System.err.println("TSHandler.decodeContext: exception");
181:                    System.err.println(e.toString() + "\n");
182:                }
183:                return ctx;
184:            }
185:
186:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.