1 23 24 package org.apache.webdav.connector; 25 26 import java.io.IOException ; 27 import java.io.PrintWriter ; 28 import java.util.Iterator ; 29 import java.util.Set ; 30 31 import javax.resource.ResourceException ; 32 import javax.resource.spi.ConnectionManager ; 33 import javax.resource.spi.ConnectionRequestInfo ; 34 import javax.resource.spi.ManagedConnection ; 35 import javax.resource.spi.ManagedConnectionFactory ; 36 import javax.security.auth.Subject ; 37 38 import org.apache.commons.httpclient.HttpException; 39 40 45 public class WebDAVManagedConnectionFactory implements ManagedConnectionFactory { 46 47 protected PrintWriter writer; 48 49 52 public Object createConnectionFactory(ConnectionManager cm) throws ResourceException { 53 54 return new WebDAVConnectionFactory(this, cm); 55 } 56 57 60 public Object createConnectionFactory() throws ResourceException { 61 62 return new WebDAVConnectionFactory(this, null); 63 } 64 65 69 public ManagedConnection createManagedConnection(Subject subject, ConnectionRequestInfo cxRequestInfo) 70 throws ResourceException { 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 throw new ResourceException ("Could not create managed connection", e.toString()); 82 } catch (IOException e) { 83 if (writer != null) { 84 writer.println("Exception: " + e); 85 e.printStackTrace(writer); 86 } 87 throw new ResourceException ("Could not create managed connection", e.toString()); 90 } 91 } 92 93 97 public ManagedConnection matchManagedConnections(Set connectionSet, Subject subject, 98 ConnectionRequestInfo cxRequestInfo) throws ResourceException { 99 100 ManagedConnection match = null; 101 Iterator iterator = connectionSet.iterator(); 102 if (iterator.hasNext()) { 103 match = (ManagedConnection ) iterator.next(); 104 } 105 106 return match; 107 } 108 109 112 public void setLogWriter(PrintWriter writer) throws ResourceException { 113 114 this.writer = writer; 115 } 116 117 120 public PrintWriter getLogWriter() throws ResourceException { 121 122 return writer; 123 } 124 125 public boolean equals(Object 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 |