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


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