Source Code Cross Referenced for EjbCompClient.java in  » J2EE » JOnAS-4.8.6 » jms » 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 » jms 
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): ____________________________________.
022:         * Contributor(s): Fran?ois Exertier
023:         *
024:         * --------------------------------------------------------------------------
025:         * $Id: EjbCompClient.java 4618 2004-04-19 06:39:30Z benoitf $
026:         * --------------------------------------------------------------------------
027:         */package jms;
028:
029:        import javax.naming.Context;
030:        import javax.naming.InitialContext;
031:        import javax.naming.NamingException;
032:        import javax.rmi.PortableRemoteObject;
033:        import javax.transaction.UserTransaction;
034:
035:        import eb.Account;
036:        import eb.AccountHome;
037:
038:        /**
039:         *
040:         */
041:        public class EjbCompClient {
042:
043:            private static Context initialContext = null;
044:
045:            private static EjbCompHome home1 = null;
046:
047:            private static AccountHome home2 = null;
048:
049:            private static UserTransaction utx = null;
050:
051:            public static void main(String[] arg) {
052:
053:                // Get InitialContext
054:                try {
055:                    initialContext = new InitialContext();
056:                } catch (NamingException e) {
057:                    e.printStackTrace();
058:                    System.exit(2);
059:                }
060:
061:                // For starting transactions from client: get UserTransaction
062:                System.out
063:                        .println("Getting a UserTransaction object from JNDI");
064:                try {
065:                    utx = (UserTransaction) initialContext
066:                            .lookup("javax.transaction.UserTransaction");
067:                } catch (Exception e) {
068:                    System.err.println("Cannot lookup UserTransaction: " + e);
069:                    System.exit(2);
070:                }
071:
072:                // Lookup EjbComp bean home
073:                try {
074:                    home1 = (EjbCompHome) PortableRemoteObject.narrow(
075:                            initialContext.lookup("EjbCompHome"),
076:                            EjbCompHome.class);
077:                } catch (Exception e) {
078:                    System.err.println("Cannot lookup EjbCompHome: " + e);
079:                    System.exit(2);
080:                }
081:
082:                // Lookup Account bean home
083:                try {
084:                    home2 = (AccountHome) PortableRemoteObject.narrow(
085:                            initialContext.lookup("AccountImplHome"),
086:                            AccountHome.class);
087:                } catch (Exception e) {
088:                    System.err.println("Cannot lookup AccountImplHome: " + e);
089:                    // no entity bean to use for running the jms sample
090:                    System.out
091:                            .println("Sample will work without entity bean Account");
092:                    home2 = null;
093:                }
094:
095:                // Delete account that may have been created by a previous run
096:                try {
097:                    if (home2 != null) { // use entity bean account in the sample
098:                        Account b = home2.findByNumber(222);
099:                        b.remove();
100:                    }
101:                } catch (Exception e) {
102:                }
103:
104:                // EjbComp creation
105:                EjbComp aJmsBean = null;
106:                try {
107:                    System.out.println("Creating an EjbComp bean");
108:                    aJmsBean = home1.create();
109:                } catch (Exception e) {
110:                    System.err.println("Cannot create EjbComp: " + e);
111:                    System.exit(2);
112:                }
113:
114:                // Calling EjbComp method that sends a message and eventually creating
115:                // the corresponding account (i.e. in the database), in a
116:                // transaction that succeeds !
117:                Account aDataBean = null;
118:                try {
119:                    utx.begin();
120:                    System.out.println("Sending a message (will be commited)");
121:                    aJmsBean.sendMsg("Hello commit");
122:                    if (home2 != null) {
123:                        System.out
124:                                .println("Creating an Account bean (will be commited)");
125:                        aDataBean = home2.create(222, "JMS Sample OK", 0);
126:                    }
127:                    utx.commit();
128:                } catch (Exception e) {
129:                    System.err.println("Exception .... : " + e);
130:                    e.printStackTrace();
131:                    System.exit(2);
132:                }
133:
134:                // Calling EjbComp method that sends a message and eventually creating
135:                // the corresponding account (i.e. in the database), in a
136:                // transaction that fails !
137:                try {
138:                    utx.begin();
139:                    System.out
140:                            .println("Sending a message (will be rolled back)");
141:                    aJmsBean.sendMsg("Hello rollback");
142:                    if (home2 != null) {
143:                        System.out
144:                                .println("Creating a Account bean (will be rolled back)");
145:                        aDataBean = home2.create(223, "JMS Sample KO", 0);
146:                    }
147:                    utx.rollback();
148:                } catch (Exception e) {
149:                    System.err.println("Exception .... : " + e);
150:                    System.exit(2);
151:                }
152:
153:                System.out.println("If your JMS MsgReceptor windows prints");
154:                System.out
155:                        .println("      received message ======> Hello commit");
156:                System.out.println("this test is successful.");
157:                System.out
158:                        .println("You may also check that the record 222 has been");
159:                System.out
160:                        .println("created in the database in the table accountsample");
161:                System.out
162:                        .println("(if the sample was working with the entity bean Account).");
163:            }
164:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.