Source Code Cross Referenced for CommonClient.java in  » J2EE » JOnAS-4.8.6 » fictional » resourceadapter » 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 » fictional.resourceadapter 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Created on Jun 12, 2003
003:         *
004:         * CommonClient.java is used to test the J2EE Connector
005:         * as implemented by JOnAS. This class implements some the Common Client Interface
006:         * (cci) classes. Each cci method simulates actual functionality and returns test 
007:         * results to the caller which is a JUnit test program.
008:         * 
009:         */
010:        package fictional.resourceadapter;
011:
012:        import javax.naming.Reference;
013:        import javax.naming.NamingException;
014:        import javax.resource.ResourceException;
015:        import javax.resource.NotSupportedException;
016:        import javax.resource.spi.ConnectionManager;
017:        import javax.resource.spi.ManagedConnectionFactory;
018:        import javax.resource.spi.ConnectionRequestInfo; //  interfaces implemented in this class
019:        import javax.resource.cci.ConnectionFactory;
020:        import javax.resource.cci.Connection;
021:        import javax.resource.cci.ConnectionSpec; // j2ee 1.5
022:        import javax.resource.cci.RecordFactory;
023:        import javax.resource.cci.ResourceAdapterMetaData;
024:        import java.io.Serializable;
025:        import javax.resource.Referenceable; //  logger imports
026:        import org.objectweb.jonas.common.Log;
027:        import org.objectweb.util.monolog.api.Logger;
028:        import org.objectweb.util.monolog.api.BasicLevel;
029:
030:        /**
031:         * @author Bob Kruse
032:         *
033:         * used to test the J2EE Connector as implemented by JOnAS.
034:         *
035:         */
036:        public class CommonClient implements  ConnectionFactory, ConnectionSpec, // j2ee 1.5
037:                ResourceAdapterMetaData, Referenceable, Serializable
038:
039:        {
040:            Reference reference;
041:            private ConnectionManager cm;
042:            private ManagedConnectionFactory mcf; // used in cm.allocateConnection
043:            private CommonClient cs; // ConnectionSpec
044:            protected boolean managed = true;
045:            private Logger logger = null;
046:            private String userName = "";
047:            private String passWord = "";
048:            String cName = "";
049:
050:            public CommonClient() {
051:                if (logger == null) {
052:                    logger = Log.getLogger("fictional.resourceadapter");
053:                }
054:            }
055:
056:            //
057:            // *****************
058:            //  ConnectionSpec    methods
059:            // *****************
060:            //
061:            public void setUserName(String u) {
062:                userName = u;
063:                cName = "ConnectionSpec";
064:                logger.log(BasicLevel.DEBUG, cName + ".setUserName=" + u);
065:            }
066:
067:            public void setPassword(String p) {
068:                passWord = p;
069:                cName = "ConnectionSpec";
070:                logger.log(BasicLevel.DEBUG, cName + ".setPassword=" + p);
071:            }
072:
073:            public String getUserName() {
074:                cName = "ConnectionSpec";
075:                logger
076:                        .log(BasicLevel.DEBUG, cName + ".getUserName="
077:                                + userName);
078:                return userName;
079:            }
080:
081:            public String getPassword() {
082:                cName = "ConnectionSpec";
083:                logger
084:                        .log(BasicLevel.DEBUG, cName + ".getPassword="
085:                                + passWord);
086:                return passWord;
087:            }
088:
089:            //
090:            // *****************
091:            // ConnectionFactory    methods
092:            // *****************
093:            //
094:            // Referenced classes of package javax.resource.cci:
095:            //  Connection, ConnectionSpec, RecordFactory, ResourceAdapterMetaData
096:            //  (below is constructor for ConnectionFactory
097:            //
098:            //  ConnectionFactory instance created during lookup() by Application Server
099:            // 
100:            public CommonClient(ManagedConnectionFactory mcf,
101:                    ConnectionManager cm) {
102:                if (logger == null) {
103:                    logger = Log.getLogger("fictional.resourceadapter");
104:                }
105:                this .mcf = mcf;
106:                this .cm = cm;
107:
108:            }
109:
110:            private String impl(Object obj) {
111:                if (obj instanceof  ConnectionFactory) {
112:                    return "ConnectionFactory";
113:                } else if (obj instanceof  ConnectionSpec) {
114:                    return "ConnectionSpec";
115:                } else if (obj instanceof  ResourceAdapterMetaData) {
116:                    return "ResourceAdapterMetaData";
117:                } else
118:                    return "CommonClient. Is this an error";
119:
120:            }
121:
122:            //
123:            // Container Managed Sign-on calls getConnection() from the Application Component
124:            //
125:            // Container-managed sign-on when file "connector.xml / secured.jar" contains line below
126:            //
127:            //  <res-auth>Container</res-auth>
128:            //
129:            public Connection getConnection() throws ResourceException {
130:                cName = "ConnectionFactory";
131:                logger.log(BasicLevel.DEBUG, cName + ".getConnection"
132:                        + " (Container Managed Sign-on)");
133:                Connection conn = null;
134:                try {
135:                    conn = (Connection) getConnection(null);
136:                    return conn;
137:                } catch (ResourceException ex) {
138:                    throw ex;
139:                }
140:            }
141:
142:            //
143:            // Component Managed Sign-on calls getConnection(cs) directly from the Application Component
144:            //
145:            // Component-managed sign-on when file "connector.xml / secured.jar" contains line below
146:            //
147:            //  <res-auth>Application</res-auth>
148:            //
149:            public Connection getConnection(ConnectionSpec connectionspec)
150:                    throws ResourceException {
151:                cName = "ConnectionFactory";
152:                JtestResourceAdapter jmcf = (JtestResourceAdapter) mcf; // ManagedConnectionFactory
153:                Connection conn = null;
154:                CommonClient cs; // ConnectionSpec
155:                JtestResourceAdapter jcri = null; // ConnectionRequestInfo
156:
157:                if (connectionspec == null) {
158:                    jmcf.setRes_Auth("Container");
159:                    logger.log(BasicLevel.DEBUG, cName
160:                            + ".getConnection detected res-auth='"
161:                            + jmcf.getRes_Auth() + "'");
162:                    // TODO what now? anything?
163:                    // now pass null to cm.allocateConnection(mcf, null);
164:                } else {
165:                    jmcf.setRes_Auth("Application");
166:                    logger.log(BasicLevel.DEBUG, cName
167:                            + ".getConnection detected res-auth='"
168:                            + jmcf.getRes_Auth() + "'");
169:                    cs = (CommonClient) connectionspec;
170:                    // load user and password into ConnectionRequestInfo instance
171:                    jcri = new JtestResourceAdapter(); // ConnectionRequestInfo
172:                    jcri.setUserName(cs.getUserName());
173:                    jcri.setPassword(cs.getPassword());
174:
175:                }
176:                logger.log(BasicLevel.DEBUG, cName
177:                        + ".getConnection calling cm.allocateConnection");
178:                try {
179:                    ConnectionRequestInfo cri = (ConnectionRequestInfo) jcri;
180:                    conn = (Connection) cm.allocateConnection(mcf, cri);
181:                    if (conn == null) {
182:                        logger.log(BasicLevel.DEBUG, cName
183:                                + ". getConnection, cm.allocateConnection"
184:                                + " error: Null connection object returned");
185:                        throw new ResourceException(
186:                                "Null connection object returned by allocateConnection");
187:                    }
188:                    return conn;
189:                } catch (IllegalStateException is) {
190:                    logger.log(BasicLevel.DEBUG, cName
191:                            + ".getConnection IllegalStateException" + is);
192:                    throw is;
193:                } catch (ResourceException re) {
194:                    logger.log(BasicLevel.DEBUG, cName
195:                            + ".getConnection ResourceException=" + re);
196:                    throw re;
197:                }
198:            }
199:
200:            public RecordFactory getRecordFactory() throws ResourceException {
201:                cName = "ConnectionFactory";
202:                logger.log(BasicLevel.DEBUG, cName + ".getRecordFactory");
203:                NotSupportedException nse = new NotSupportedException(
204:                        "RecordFactory is not currently supported");
205:                throw nse;
206:            }
207:
208:            public ResourceAdapterMetaData getMetaData()
209:                    throws ResourceException {
210:                cName = "ConnectionFactory";
211:                logger.log(BasicLevel.DEBUG, cName + ".getMetaData");
212:                ResourceAdapterMetaData rd = null; // TODO  do something
213:                return rd;
214:            }
215:
216:            public ManagedConnectionFactory getMcf() {
217:                ManagedConnectionFactory MCF = (ManagedConnectionFactory) mcf;
218:                return MCF;
219:            }
220:
221:            //
222:            // *****************
223:            //    Reference
224:            // *****************
225:            //
226:            /** Required by the referencable attribute
227:             *  @param  ref Reference object
228:             **/
229:            public void setReference(javax.naming.Reference ref) {
230:                this .reference = ref;
231:            }
232:
233:            /** Required by the referencable attribute
234:             *  @return  Reference object
235:             **/
236:            public Reference getReference() throws NamingException {
237:                return reference;
238:            }
239:
240:            //
241:            // ***********************
242:            // ResourceAdapterMetaData  methods
243:            // ***********************
244:            //
245:            public String getAdapterVersion() {
246:                return "1.0";
247:            }
248:
249:            public String getAdapterVendorName() {
250:                return "Bull";
251:            }
252:
253:            public String getAdapterName() {
254:                return "JOnAS Test Resource Adapter";
255:            }
256:
257:            public String getAdapterShortDescription() {
258:                return "Test JOnAS Application Server compliance to J2EE Java Community Process (JSR112)";
259:            }
260:
261:            public String getSpecVersion() {
262:                return "J2EE Java Community Process (JSR112)";
263:            }
264:
265:            public String[] getInteractionSpecsSupported() {
266:                String[] s = { "JSR016", "JSR112" };
267:                return s;
268:            }
269:
270:            public boolean supportsExecuteWithInputAndOutputRecord() {
271:                return true;
272:            }
273:
274:            public boolean supportsExecuteWithInputRecordOnly() {
275:                return true;
276:            }
277:
278:            public boolean supportsLocalTransactionDemarcation() {
279:                return false;
280:            }
281:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.