Source Code Cross Referenced for RuntimeCASLR.java in  » J2EE » JOnAS-4.8.6 » org » objectweb » jonas » jtests » beans » jca15 » 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.jonas.jtests.beans.jca15 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        // RuntimeCASLR.java
002:        // Stateless Session bean
003:
004:        package org.objectweb.jonas.jtests.beans.jca15;
005:
006:        import java.rmi.RemoteException;
007:        import javax.ejb.CreateException;
008:        import javax.ejb.EJBException;
009:        import javax.ejb.RemoveException;
010:        import javax.ejb.EJBObject;
011:        import javax.ejb.SessionBean;
012:        import javax.ejb.SessionContext;
013:        import javax.naming.Context;
014:        import javax.naming.InitialContext;
015:        import javax.naming.NamingException;
016:        import javax.resource.cci.Connection;
017:        import javax.resource.spi.ManagedConnection;
018:        import javax.resource.spi.ConnectionManager;
019:        import ersatz.resourceadapter.*;
020:        import javax.resource.spi.ConnectionEvent;
021:
022:        /*
023:         */
024:        public class RuntimeCASLR implements  SessionBean {
025:
026:            SessionContext ejbContext;
027:            private ManagedConnectionFactoryImpl mcf = null; //Managed Connection Factory
028:            private ConnectionFactoryImpl cccf = null; //Common Client Connection Factory
029:            private ConnectionImpl conn = null;
030:            private ConnectionSpecImpl csp = null; //ConnectionSpec
031:            private ConnectionRequestInfoImpl crii = null;
032:            InitialContext ic = null;
033:            private String res_auth = "";
034:            String cName = "RuntimeCASLR";
035:
036:            // ------------------------------------------------------------------
037:            // SessionBean implementation
038:            // ------------------------------------------------------------------
039:
040:            public void setSessionContext(SessionContext ctx) {
041:                Utility.log(cName + ".setSessionContext");
042:                ejbContext = ctx;
043:            }
044:
045:            public void ejbRemove() {
046:                Utility.log(cName + ".ejbRemove");
047:            }
048:
049:            public void ejbCreate() throws CreateException {
050:                Utility.log(cName + ".ejbCreate");
051:            }
052:
053:            public void ejbPassivate() {
054:                Utility.log(cName + ".ejbPassivate");
055:            }
056:
057:            public void ejbActivate() {
058:                Utility.log(cName + ".ejbActivate");
059:            }
060:
061:            // ------------------------------------------------------------------
062:            // Runtime implementation
063:            // ------------------------------------------------------------------
064:            public void setResAuth(String ra) {
065:                res_auth = ra; // set to Application or Container
066:            }
067:
068:            /**
069:             * method1
070:             */
071:            public void method1(String rar_jndi_name, String testName)
072:                    throws Exception {
073:                Utility.log("============================ " + testName);
074:                Utility.log(cName + ".method1 : lookup " + rar_jndi_name);
075:                try {
076:                    ic = new InitialContext();
077:                } catch (Exception e1) {
078:                    Utility
079:                            .log(cName
080:                                    + ".method1 error: InitialContext failed");
081:                    throw e1;
082:                }
083:                try {
084:                    cccf = (ConnectionFactoryImpl) ic.lookup(rar_jndi_name);
085:                    Utility.log(cName + ".method1 : found " + rar_jndi_name);
086:                } catch (Exception e2) {
087:                    Utility.log(cName + ".method1 error: lookup failed for "
088:                            + rar_jndi_name);
089:                    throw e2;
090:                }
091:
092:                //
093:                // Component-managed sign-on when file "runtime.xml" contains line below
094:                //
095:                //  <res-auth>Application</res-auth>
096:                //
097:                try {
098:                    csp = new ConnectionSpecImpl(); // get a new ConnectionSpecImpl
099:                    csp.setUserName("Ersatz_User_Name");
100:                    csp.setPassword("__Jtest_Pass_word__");
101:                    Utility
102:                            .log(cName
103:                                    + ".method1 : ConnectionSpecImpl + Ersatz_User_Name,__Jtest_Pass_word__");
104:                } catch (Exception e3) {
105:                    Utility
106:                            .log(cName
107:                                    + ".method1 : new connection spec failed");
108:                    throw e3;
109:                }
110:                try {
111:                    conn = (ConnectionImpl) cccf.getConnection();
112:                    if (conn == null) {
113:                        Utility
114:                                .log(cName
115:                                        + ".method1 error: getConnection returned null connection.");
116:                        throw new Exception("");
117:                    }
118:                } catch (Exception e4) {
119:                    Utility.log(cName + ".method1 error: getConnection failed "
120:                            + e4.toString());
121:                    throw e4;
122:                }
123:            }
124:
125:            /**
126:             * closeUp
127:             */
128:            public void closeUp(int w) {
129:                try {
130:                    if (w > 0) {
131:                        // The CONNECTION_ERROR_OCCURRED indicates that the associated 
132:                        // ManagedConnectionImpl instance is now invalid and unusable.
133:                        conn.close(ConnectionEvent.CONNECTION_ERROR_OCCURRED);
134:                        Utility.log(cName
135:                                + ".closeUp : closed physical connection");
136:                    } else {
137:                        // The CONNECTION_CLOSED indicates that connection handle
138:                        // is closed, but physical connection still exists
139:                        conn.close();
140:                        Utility.log(cName + ".closeUp : closed connection");
141:                    }
142:                } catch (Exception e) {
143:                    Utility
144:                            .log(cName
145:                                    + ".closeUp error: close handle/physical connection failed");
146:                }
147:            }
148:
149:            /**
150:             * JUnit tests
151:             */
152:            public int getMCF_Pwriter() {
153:                int here = 2;
154:                mcf = cccf.getMcf(); // ManagedConnectionFactory    
155:                try {
156:                    if (mcf.getLogWriter() == null) { // PrintWriter is null
157:                        Utility
158:                                .log(cName
159:                                        + ".getMCF_Pwriter No PrintWriter registered in "
160:                                        + "ManagedConnectionFactoryImpl");
161:                        here = 0;
162:                    } else {
163:                        Utility.log(cName
164:                                + ".getMCF_Pwriter PrintWriter is o.k.in "
165:                                + "ManagedConnectionFactoryImpl");
166:                        here = 1;
167:                    }
168:                } catch (Exception e) {
169:                    Utility.log(cName + ".getMCF_Pwriter error: "
170:                            + e.toString());
171:                }
172:                return here;
173:            }
174:
175:            public int getMC_Pwriter() {
176:                int here = 2;
177:                try {
178:                    ManagedConnectionImpl mc = conn.getMC();
179:                    if (mc.getLogWriter() == null) { // PrintWriter not null
180:                        Utility
181:                                .log(cName
182:                                        + ".getMC_Pwriter No PrintWriter registered in ManagedConnectionImpl");
183:                        here = 0;
184:                    } else {
185:                        Utility
186:                                .log(cName
187:                                        + ".getMC_Pwriter PrintWriter in ManagedConnectionImpl is o.k.");
188:                        here = 1;
189:                    }
190:                } catch (Exception e) {
191:                    Utility
192:                            .log(cName + ".getMC_Pwriter error: "
193:                                    + e.toString());
194:                }
195:                return here;
196:            }
197:
198:            public String getResAuth() {
199:                try {
200:                    ManagedConnectionImpl mc = conn.getMC();
201:                    String ra = mc.res_auth; // get real "Application" or "Container"
202:                    Utility.log(cName + ".getResAuth " + "<res-auth>" + ra
203:                            + "</res-auth>");
204:                    if (ra == null || ra.length() == 0)
205:                        throw new Exception("");
206:                    return ra;
207:                } catch (Exception e) {
208:                    Utility.log(cName
209:                            + ".getResAuth error: failed to find <res-auth> "
210:                            + "in ManagedConnectionImpl");
211:                    return "";
212:                }
213:            }
214:
215:            public String getSecurityPassword() {
216:                crii = conn.crii; // look at ConnectionRequestInfoImpl
217:                try {
218:                    ManagedConnectionImpl mc = conn.getMC();
219:                    String pw = crii.getPassword();
220:                    Utility.log(cName + ".getSecurityPassword (" + mc.res_auth
221:                            + ")password=" + pw);
222:                    if (pw == null || pw.length() == 0)
223:                        throw new Exception("");
224:                    return pw;
225:                } catch (Exception e) {
226:                    mcf = cccf.getMcf();
227:                    String pw = mcf.defaultPassword; // find default
228:                    Utility
229:                            .log(cName
230:                                    + ".getSecurityPassword error: failed to find ConnectionRequestInfoImpl "
231:                                    + "instance containing password. Using default="
232:                                    + pw);
233:                    return pw;
234:                }
235:            }
236:
237:            public String getSecurityUserName() {
238:                crii = conn.crii; // look at ConnectionRequestInfoImpl
239:                try {
240:                    ManagedConnectionImpl mc = conn.getMC();
241:                    String u = crii.getUserName();
242:                    Utility.log(cName + ".getSecurityUserName ("
243:                            + mcf.getRes_Auth() + ")userName=" + u);
244:                    if (u == null || u.length() == 0)
245:                        throw new Exception("");
246:                    return u;
247:                } catch (Exception e) {
248:                    mcf = cccf.getMcf();
249:                    String u = mcf.defaultUserName; // find default
250:                    Utility
251:                            .log(cName
252:                                    + ".getSecurityUserName error: failed to find ConnectionRequestInfoImpl "
253:                                    + "instance containing userName. Using default="
254:                                    + u);
255:                    return u;
256:                }
257:            }
258:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.