Source Code Cross Referenced for Client.java in  » J2EE » JOnAS-4.8.6 » org » objectweb » earsample » clients » 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 » J2EE » JOnAS 4.8.6 » org.objectweb.earsample.clients 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * JOnAS: Java(TM) Open Application Server
003:         * Copyright (C) 1999-2004 Bull S.A.
004:         * Contact: jonas-team@objectweb.org
005:         *
006:         * This library is free software; you can redistribute it and/or
007:         * modify it under the terms of the GNU Lesser General Public
008:         * License as published by the Free Software Foundation; either
009:         * version 2.1 of the License, or any later version.
010:         *
011:         * This library is distributed in the hope that it will be useful,
012:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
013:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014:         * Lesser General Public License for more details.
015:         *
016:         * You should have received a copy of the GNU Lesser General Public
017:         * License along with this library; if not, write to the Free Software
018:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
019:         * USA
020:         *
021:         * Initial developer: Florent Benoit
022:         *
023:         * --------------------------------------------------------------------------
024:         * $Id: Client.java 4618 2004-04-19 06:39:30Z benoitf $
025:         * --------------------------------------------------------------------------
026:         */package org.objectweb.earsample.clients;
027:
028:        import java.net.URL;
029:
030:        import javax.naming.Context;
031:        import javax.naming.InitialContext;
032:        import javax.transaction.UserTransaction;
033:        import javax.rmi.PortableRemoteObject;
034:
035:        import org.objectweb.earsample.beans.secusb.Op;
036:        import org.objectweb.earsample.beans.secusb.OpHome;
037:
038:        /**
039:         * Heavy client doing some operations on a bean
040:         * @author jonas team
041:         */
042:        public class Client {
043:
044:            /**
045:             * First amount to buy
046:             */
047:            private static final int FIRST_BUY_AMOUNT = 10;
048:
049:            /**
050:             * Second amount to buy
051:             */
052:            private static final int SECOND_BUY_AMOUNT = 20;
053:
054:            /**
055:             * Third amount to buy (will be rollback)
056:             */
057:            private static final int THIRD_BUY_AMOUNT = 50;
058:
059:            /**
060:             * Constructor. Hide constructor as it is an utility class
061:             */
062:            private Client() {
063:
064:            }
065:
066:            /**
067:             * Main method
068:             * @param args arguments of the client
069:             */
070:            public static void main(String[] args) {
071:
072:                Context initialContext = null;
073:                System.out.print("Building a new InitialContext...");
074:                try {
075:                    initialContext = new InitialContext();
076:                } catch (Exception e) {
077:                    System.err.println("Cannot get initial context for JNDI: "
078:                            + e);
079:                    System.exit(2);
080:                }
081:                System.out.println("done !");
082:
083:                System.out.print("Looking up java:comp/UserTransaction ...");
084:                // We want to start transactions from client: get UserTransaction
085:                UserTransaction utx = null;
086:                try {
087:                    utx = (UserTransaction) initialContext
088:                            .lookup("java:comp/UserTransaction");
089:                } catch (Exception e) {
090:                    System.err.println("Cannot lookup UserTransaction: " + e);
091:                    System.exit(2);
092:                }
093:                System.out.println("done !");
094:
095:                String envEntry = null;
096:                System.out.print("Looking up java:comp/env/envEntryString ...");
097:                try {
098:                    envEntry = (String) initialContext
099:                            .lookup("java:comp/env/envEntryString");
100:                } catch (Exception e) {
101:                    System.err.println("Cannot get env-entry on JNDI " + e);
102:                    System.exit(2);
103:                }
104:                System.out.println("done !");
105:                System.out.println("Env entry is : " + envEntry);
106:
107:                URL url = null;
108:                System.out.print("Looking up java:comp/env/url/jonas ...");
109:                try {
110:                    url = (URL) initialContext
111:                            .lookup("java:comp/env/url/jonas");
112:                } catch (Exception e) {
113:                    System.err.println("Cannot get URL on JNDI " + e);
114:                    System.exit(2);
115:                }
116:                System.out.println("done !");
117:                System.out.println("Web site of jonas is at :" + url);
118:
119:                System.out.print("Looking up java:comp/env/ejb/Op ...");
120:                // Connecting to OpHome thru JNDI
121:                OpHome home = null;
122:                try {
123:                    home = (OpHome) PortableRemoteObject.narrow(initialContext
124:                            .lookup("java:comp/env/ejb/Op"), OpHome.class);
125:                    System.out.println("done !");
126:                } catch (Exception e) {
127:                    e.printStackTrace();
128:                    System.err.println("Cannot lookup OpHome: " + e);
129:                    System.exit(2);
130:                }
131:
132:                // OpBean creation
133:                Op t1 = null;
134:                try {
135:                    System.out.println("Create a bean");
136:                    t1 = home.create("User1");
137:                } catch (Exception e) {
138:                    System.err.println("Cannot create OpBean: " + e);
139:                    System.exit(2);
140:                }
141:
142:                // First transaction (committed)
143:                try {
144:                    System.out.println("Start a first transaction");
145:                    utx.begin();
146:                    System.out.println("First request on the new bean");
147:                    t1.buy(FIRST_BUY_AMOUNT);
148:                    System.out.println("Second request on the bean");
149:                    t1.buy(SECOND_BUY_AMOUNT);
150:                    System.out.println("Commit the transaction");
151:                    utx.commit();
152:                } catch (Exception e) {
153:                    System.err.println("exception during 1st Tx: " + e);
154:                    System.exit(2);
155:                }
156:                // Start another transaction (rolled back)
157:                try {
158:                    System.out.println("Start a second transaction");
159:                    utx.begin();
160:                    t1.buy(THIRD_BUY_AMOUNT);
161:                    System.out.println("Rollback the transaction");
162:                    utx.rollback();
163:                } catch (Exception e) {
164:                    System.err.println("exception during 2nd Tx: " + e);
165:                    System.exit(2);
166:                }
167:
168:                // Get the total bought, outside the transaction
169:                int val = 0;
170:                try {
171:                    System.out.println("Request outside any transaction");
172:                    val = t1.read();
173:                } catch (Exception e) {
174:                    System.err.println("Cannot read value on t1 : " + e);
175:                    System.exit(2);
176:                }
177:                if (val != FIRST_BUY_AMOUNT + SECOND_BUY_AMOUNT) {
178:                    System.err.println("Bad value read: " + val);
179:                    System.exit(2);
180:                }
181:
182:                // Remove Session bean
183:                try {
184:                    t1.remove();
185:                } catch (Exception e) {
186:                    System.out.println("Exception on buy: " + e);
187:                    System.exit(2);
188:                }
189:                System.out.println("ClientOp OK. Exiting.");
190:            }
191:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.