Source Code Cross Referenced for ClientJAASOpContClientSwing.java in  » J2EE » JOnAS-4.8.6 » jaasclient » 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 » jaasclient 
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(s): jonas team
022:         *
023:         * --------------------------------------------------------------------------
024:         * $Id: ClientJAASOpContClientSwing.java 4618 2004-04-19 06:39:30Z benoitf $
025:         * --------------------------------------------------------------------------
026:         */package jaasclient;
027:
028:        import jaasclient.beans.secusb.JAASOp;
029:        import jaasclient.beans.secusb.JAASOpHome;
030:
031:        import java.awt.event.ActionEvent;
032:
033:        import javax.naming.Context;
034:        import javax.naming.InitialContext;
035:        import javax.rmi.PortableRemoteObject;
036:        import javax.swing.AbstractAction;
037:        import javax.swing.Action;
038:        import javax.swing.JButton;
039:        import javax.swing.JFrame;
040:        import javax.swing.WindowConstants;
041:        import javax.transaction.UserTransaction;
042:
043:        /**
044:         * Sample for Session Bean.
045:         * @author jonas team
046:         * @author Florent Benoit
047:         * @author Markus Karg : Add Swing interface
048:         */
049:        public class ClientJAASOpContClientSwing {
050:
051:            /**
052:             * First amount to buy
053:             */
054:            private static final int FIRST_BUY_AMOUNT = 10;
055:
056:            /**
057:             * Second amount to buy
058:             */
059:            private static final int SECOND_BUY_AMOUNT = 20;
060:
061:            /**
062:             * Third amount to buy (will be rollback)
063:             */
064:            private static final int THIRD_BUY_AMOUNT = 50;
065:
066:            /**
067:             * Constructor. Hide constructor as it is an utility class
068:             */
069:            private ClientJAASOpContClientSwing() {
070:
071:            }
072:
073:            /**
074:             * Main method
075:             * @param args the arguments
076:             */
077:            public static void main(String[] args) {
078:
079:                final JFrame jf = new JFrame("Test Application");
080:                jf.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
081:                final JButton jb = new JButton();
082:                final Action a = new AbstractAction("Click here to test!") {
083:                    public final void actionPerformed(final ActionEvent v) {
084:
085:                        Context initialContext = null;
086:                        try {
087:                            initialContext = new InitialContext();
088:                        } catch (Exception e) {
089:                            System.err
090:                                    .println("Cannot get initial context for JNDI: "
091:                                            + e);
092:                            System.exit(2);
093:                        }
094:
095:                        // We want to start transactions from client: get UserTransaction
096:                        UserTransaction utx = null;
097:                        try {
098:                            utx = (UserTransaction) initialContext
099:                                    .lookup("java:comp/UserTransaction");
100:                        } catch (Exception e) {
101:                            System.err
102:                                    .println("Cannot lookup java:comp/UserTransaction: "
103:                                            + e);
104:                            System.exit(2);
105:                        }
106:
107:                        // Connecting to JAASOpHome thru JNDI
108:                        JAASOpHome home = null;
109:                        try {
110:                            home = (JAASOpHome) PortableRemoteObject
111:                                    .narrow(
112:                                            initialContext
113:                                                    .lookup("java:comp/env/ejb/JAASOp"),
114:                                            JAASOpHome.class);
115:                        } catch (Exception e) {
116:                            System.err
117:                                    .println("Cannot lookup java:comp/env/ejb/JAASOp: "
118:                                            + e
119:                                            + ". Maybe you haven't do the 'jonas admin -a jaasop.jar'");
120:                            System.exit(2);
121:                        }
122:
123:                        // JAASOpBean creation
124:                        JAASOp t1 = null;
125:                        try {
126:                            System.out.println("Create a bean");
127:                            t1 = home.create("User1");
128:                        } catch (Exception e) {
129:                            System.err
130:                                    .println("Cannot create JAASOpBean: " + e);
131:                            System.exit(2);
132:                        }
133:
134:                        // First transaction (committed)
135:                        try {
136:                            System.out.println("Start a first transaction");
137:                            utx.begin();
138:                            System.out.println("First request on the new bean");
139:                            t1.buy(FIRST_BUY_AMOUNT);
140:                            System.out.println("Second request on the bean");
141:                            t1.buy(SECOND_BUY_AMOUNT);
142:                            System.out.println("Commit the transaction");
143:                            utx.commit();
144:                        } catch (Exception e) {
145:                            System.err.println("exception during 1st Tx: " + e);
146:                            System.exit(2);
147:                        }
148:                        // Start another transaction (rolled back)
149:                        try {
150:                            System.out.println("Start a second transaction");
151:                            utx.begin();
152:                            t1.buy(THIRD_BUY_AMOUNT);
153:                            System.out.println("Rollback the transaction");
154:                            utx.rollback();
155:                        } catch (Exception e) {
156:                            System.err.println("exception during 2nd Tx: " + e);
157:                            System.exit(2);
158:                        }
159:
160:                        // Get the total bought, outside the transaction
161:                        int val = 0;
162:                        try {
163:                            System.out
164:                                    .println("Request outside any transaction");
165:                            val = t1.read();
166:                        } catch (Exception e) {
167:                            System.err
168:                                    .println("Cannot read value on t1 : " + e);
169:                            System.exit(2);
170:                        }
171:                        if (val != FIRST_BUY_AMOUNT + SECOND_BUY_AMOUNT) {
172:                            System.err.println("Bad value read: " + val);
173:                            System.exit(2);
174:                        }
175:
176:                        // Remove Session bean
177:                        try {
178:                            t1.remove();
179:                        } catch (Exception e) {
180:                            System.out.println("Exception on buy: " + e);
181:                            System.exit(2);
182:                        }
183:                        System.out
184:                                .println("ClientJAASOpContClientSwing OK. Exiting.");
185:                        System.exit(0);
186:
187:                    }
188:                };
189:                jb.setAction(a);
190:                jf.getContentPane().add(jb);
191:                jf.pack();
192:                jf.setVisible(true);
193:            }
194:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.