1
2
3
4
5
6
7
8
9
10
11 package it.imolinfo.jbi4cics.connection.jca;
12
13 import it.imolinfo.jbi4cics.exception.ConnectionException;
14 import it.imolinfo.jbi4cics.exception.FormatException;
15 import it.imolinfo.jbi4cics.messageformat.commarea.CommareaBeanMappingDescriptor;
16 import it.imolinfo.jbi4cics.service.ServiceContext;
17
18 import javax.resource.cci.ConnectionSpec;
19 import javax.resource.cci.InteractionSpec;
20 import javax.resource.cci.Record;
21 import it.imolinfo.jbi4cics.Logger;
22 import it.imolinfo.jbi4cics.LoggerFactory;
23
24
25
26
27
28 public abstract class JCACommareaBasedConnectionManager extends JCAAbstractConnectionManager {
29
30
31
32
33 private static final Logger LOG
34 = LoggerFactory.getLogger(JCACommareaBasedConnectionManager.class);
35
36
37
38
39 public JCACommareaBasedConnectionManager() {
40 super();
41
42 }
43
44
45
46
47 protected Object createOutputMessage(ServiceContext serviceContext, Record outputRecord) throws ConnectionException {
48 if (!(outputRecord instanceof CommareaRecord)){
49
50 throw new ConnectionException("CIC000310_Expected_commarea_record", new Object[] {outputRecord.getClass()});
51 }
52 return ((CommareaRecord)outputRecord).getCommarea();
53 }
54
55
56
57
58
59
60 protected Record createOutputRecord(ServiceContext serviceContext) throws ConnectionException {
61 CommareaRecord outputRecord=new CommareaRecord();
62
63
64 if (!(serviceContext.getOutputMappingDescriptor() instanceof CommareaBeanMappingDescriptor)){
65
66 throw new ConnectionException("CIC000311_Expected_commarea_bean_mapping_descriptor", new Object[] {serviceContext.getOutputMappingDescriptor().getClass()});
67 }
68 CommareaBeanMappingDescriptor outputMappingDescriptor=(CommareaBeanMappingDescriptor)serviceContext.getOutputMappingDescriptor();
69 try{
70 outputRecord.setCommareaLength(outputMappingDescriptor.getBufferedLength());
71 }
72 catch (FormatException e){
73 LOG.error("CIC000312_Error_setting_commarea_lengths", new Object[] {e.getMessage()}, e);
74 throw new ConnectionException("CIC000312_Error_setting_commarea_lengths", new Object[] {e.getMessage()}, e);
75 }
76 return outputRecord;
77 }
78
79
80
81
82 protected Record createInputRecord(ServiceContext serviceContext) throws ConnectionException {
83 CommareaRecord inputRecord=new CommareaRecord();
84
85
86 Object inputMessage=serviceContext.getInputMessage();
87 if (!(inputMessage instanceof byte[])){
88
89 throw new ConnectionException("CIC000313_Expected_byte[]_input_message", new Object[] {inputMessage.getClass()});
90 }
91 inputRecord.setCommarea((byte[])inputMessage);
92 return inputRecord;
93 }
94
95
96
97
98 protected abstract InteractionSpec createInteractionSpec(ServiceContext serviceContext) throws ConnectionException;
99
100
101
102
103 protected abstract ConnectionSpec createConnectionSpec(ServiceContext serviceContext) throws ConnectionException;
104
105 }