summaryrefslogtreecommitdiffstats
path: root/Master/Reference Architectures and Patterns/EJB 3.0 Code/Rima Examples/src/examples/integration/out_loan_ra/InteractionImpl.java
blob: 2f532f9613d56f6d77add9d9ed483d3bf2113f76 (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
package examples.integration.out_loan_ra;

import examples.jni.JavaLoanApp;

import java.util.*;
import javax.resource.ResourceException;
import javax.resource.spi.ConnectionEvent;
import javax.resource.spi.IllegalStateException;
import javax.resource.cci.*;
import java.lang.reflect.*;
import java.lang.*;

public class InteractionImpl implements Interaction {

     Connection conn = null;
	
     public InteractionImpl(Connection conn) {

          System.out.println("InteractionImpl(Connection conn) called");

          this.conn = conn;
     }
    
     public javax.resource.cci.Connection getConnection() {

          return conn;
     }

     public void close() throws ResourceException {

          conn = null;
     }

     public boolean execute (InteractionSpec iSpec, Record in, Record out) throws ResourceException {

          System.out.println ("InteractionImpl.execute(InteractionSpec iSpec, Record in, Record out) called");

          out = exec((MappedRecord)in,(MappedRecord)out);

          if (out != null) {

               return true;
          } else {

               return false;
          }
     }

     public Record execute (InteractionSpec iSpec, Record in) throws ResourceException {

          System.out.println ("InteractionImpl.execute(InteractionSpec iSpec, Record in) called");

          MappedRecord out = new MappedRecordImpl();

          return exec((MappedRecord)in, out);
     }

     Record exec(MappedRecord in, MappedRecord out) throws ResourceException {

          try {

               System.out.println("InteractionImpl.exec(MappedRecord in, MappedRecord out) called");
               
               Set keys = in.keySet();
               Iterator iterator = keys.iterator();

               while (iterator.hasNext()) {

                    String key = (String)iterator.next();

                    if (key.equalsIgnoreCase("HomeEquityRate")) {

                         JavaLoanApp jlaObj = new JavaLoanApp("C:\\LoanApp.dll");
                         float equityRate = jlaObj.getHomeEquityLoanRate();
                         System.out.println ("JNI Call Returned: " + equityRate);
                         out.put(key, new Float(equityRate));
                    }
               }
               
               return out;	
          }
          catch(Exception e) {
          
               throw new ResourceException(e.getMessage());		
          }
     }

     public ResourceWarning getWarnings() throws ResourceException {

          return null;
     }

     public void clearWarnings() throws ResourceException {

     }
}