KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > webdav > connector > WebDAVManagedConnectionFactory


1 /*
2  * $Header: /home/cvs/jakarta-slide/webdavclient/connector/src/java/org/apache/webdav/connector/WebDAVManagedConnectionFactory.java,v 1.4 2004/07/15 12:37:36 ozeigermann Exp $
3  * $Revision: 1.4 $
4  * $Date: 2004/07/15 12:37:36 $
5  *
6  * ====================================================================
7  *
8  * Copyright 2004 The Apache Software Foundation
9  *
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  * http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  *
22  */

23
24 package org.apache.webdav.connector;
25
26 import java.io.IOException JavaDoc;
27 import java.io.PrintWriter JavaDoc;
28 import java.util.Iterator JavaDoc;
29 import java.util.Set JavaDoc;
30
31 import javax.resource.ResourceException JavaDoc;
32 import javax.resource.spi.ConnectionManager JavaDoc;
33 import javax.resource.spi.ConnectionRequestInfo JavaDoc;
34 import javax.resource.spi.ManagedConnection JavaDoc;
35 import javax.resource.spi.ManagedConnectionFactory JavaDoc;
36 import javax.security.auth.Subject JavaDoc;
37
38 import org.apache.commons.httpclient.HttpException;
39
40 /**
41  *
42  * @version $Revision: 1.4 $
43  *
44  */

45 public class WebDAVManagedConnectionFactory implements ManagedConnectionFactory JavaDoc {
46
47     protected PrintWriter JavaDoc writer;
48
49     /**
50      * @see ManagedConnectionFactory#createConnectionFactory(ConnectionManager)
51      */

52     public Object JavaDoc createConnectionFactory(ConnectionManager JavaDoc cm) throws ResourceException JavaDoc {
53
54         return new WebDAVConnectionFactory(this, cm);
55     }
56
57     /**
58      * @see ManagedConnectionFactory#createConnectionFactory()
59      */

60     public Object JavaDoc createConnectionFactory() throws ResourceException JavaDoc {
61
62         return new WebDAVConnectionFactory(this, null);
63     }
64
65     /**
66      * @see ManagedConnectionFactory#createManagedConnection(Subject,
67      * ConnectionRequestInfo)
68      */

69     public ManagedConnection JavaDoc createManagedConnection(Subject JavaDoc subject, ConnectionRequestInfo JavaDoc cxRequestInfo)
70             throws ResourceException JavaDoc {
71
72         try {
73             return new WebDAVManagedConnection(cxRequestInfo);
74         } catch (HttpException e) {
75             if (writer != null) {
76                 writer.println("Exception: " + e);
77                 e.printStackTrace(writer);
78             }
79             // XXX only in 1.4
80
// throw new ResourceException("Could not create managed connection", e);
81
throw new ResourceException JavaDoc("Could not create managed connection", e.toString());
82         } catch (IOException JavaDoc e) {
83             if (writer != null) {
84                 writer.println("Exception: " + e);
85                 e.printStackTrace(writer);
86             }
87             // XXX only in 1.4
88
// throw new ResourceException("Could not create managed connection", e);
89
throw new ResourceException JavaDoc("Could not create managed connection", e.toString());
90         }
91     }
92
93     /**
94      * @see ManagedConnectionFactory#matchManagedConnections(Set, Subject,
95      * ConnectionRequestInfo)
96      */

97     public ManagedConnection JavaDoc matchManagedConnections(Set JavaDoc connectionSet, Subject JavaDoc subject,
98             ConnectionRequestInfo JavaDoc cxRequestInfo) throws ResourceException JavaDoc {
99
100         ManagedConnection JavaDoc match = null;
101         Iterator JavaDoc iterator = connectionSet.iterator();
102         if (iterator.hasNext()) {
103             match = (ManagedConnection JavaDoc) iterator.next();
104         }
105
106         return match;
107     }
108
109     /**
110      * @see ManagedConnectionFactory#setLogWriter(PrintWriter)
111      */

112     public void setLogWriter(PrintWriter JavaDoc writer) throws ResourceException JavaDoc {
113
114         this.writer = writer;
115     }
116
117     /**
118      * @see ManagedConnectionFactory#getLogWriter()
119      */

120     public PrintWriter JavaDoc getLogWriter() throws ResourceException JavaDoc {
121
122         return writer;
123     }
124
125     public boolean equals(Object JavaDoc other) {
126
127         if (other instanceof WebDAVManagedConnectionFactory) {
128             return true;
129         }
130         return false;
131     }
132
133     public int hashCode() {
134
135         return 0;
136     }
137 }
Popular Tags