summaryrefslogtreecommitdiffstats
path: root/Master/Reference Architectures and Patterns/EJB 3.0 Code/Rima Examples/src/examples/integration/out_loan_ra/ManagedConnectionFactoryImpl.java
blob: 3d3407ee24ca01f17fc50f879e7adc05d968aef4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package examples.integration.out_loan_ra;

import java.io.*;
import java.util.*;

import javax.resource.*;
import javax.resource.spi.*;
import javax.resource.spi.security.PasswordCredential;
import javax.resource.spi.SecurityException;
import javax.security.auth.Subject;
import javax.naming.Context;
import javax.naming.InitialContext;

public class ManagedConnectionFactoryImpl implements ManagedConnectionFactory, Serializable {

     private PrintWriter manConnLogWriter;

     public ManagedConnectionFactoryImpl() {
     
          System.out.println("ManagedConnectionFactoryImpl() called");
     }

     public Object createConnectionFactory(ConnectionManager connManager) throws ResourceException {

          System.out.println("ManagedConnectionFactoryImpl.createConnectionFactory(ConnectionManager) called");

          return new ConnectionFactoryImpl(this, connManager);
     }

     public Object createConnectionFactory() throws ResourceException {
          throw new ResourceException ("How can you call this method in a managed environment?");
     }


     public ManagedConnection createManagedConnection (Subject subject, ConnectionRequestInfo connRequestInfo) {

          System.out.println ("ManagedConnectionFactoryImpl.createManagedConnection (Subject, ConnectionRequestInfo) called");

          return new ManagedConnectionImpl (this);
     }


     public ManagedConnection matchManagedConnections(Set connSet, Subject subject, ConnectionRequestInfo connRequestInfo) 
          throws ResourceException {

          System.out.println("ManagedConnectionFactoryImpl.matchManagedConnections(Set, Subject, ConnectionRequestInfo) called");

          Iterator iterator = connSet.iterator();

          while (iterator.hasNext()) {

               Object object = iterator.next();

               if (object instanceof ManagedConnectionImpl) {

                    ManagedConnectionImpl manConn = (ManagedConnectionImpl) object;
                    ManagedConnectionFactory manConnFactory = manConn.getManagedConnectionFactory();

                    if (manConnFactory.equals(this)) {

                         System.out.println("From ManagedConnectionFactoryImpl.matchManagedConnections() -> Connection matched");

                         return manConn;
                    }
               }
          }

          System.out.println("From ManagedConnectionFactoryImpl.matchManagedConnections() -> Connection did not match");

          return null;
     }

     public void setLogWriter(PrintWriter manConnLogWriter) {

          this.manConnLogWriter = manConnLogWriter;
     }

     public PrintWriter getLogWriter() {

          return manConnLogWriter;
     }

     public boolean equals(Object object) {

          if (object == null) return false;

          if (object instanceof ManagedConnectionFactoryImpl) {

               return true;
          } else {

               return false;
          }
     }

     public int hashCode() {
          
          return (new String("ManagedConnectionFactoryImpl")).hashCode();
     }
}