View Javadoc

1   /*******************************************************************************
2    *  Copyright (c) 2005, 2006 Imola Informatica.
3    *  All rights reserved. This program and the accompanying materials
4    *  are made available under the terms of the LGPL License v2.1
5    *  which accompanies this distribution, and is available at
6    *  http://www.gnu.org/licenses/lgpl.html
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   * @author raffaele
26   *
27   */
28  public abstract class JCACommareaBasedConnectionManager extends JCAAbstractConnectionManager {
29  
30    /**
31     * The logger for this class and its instances.
32     */
33    private static final Logger LOG
34            = LoggerFactory.getLogger(JCACommareaBasedConnectionManager.class);
35  
36    /**
37     * 
38     */
39    public JCACommareaBasedConnectionManager() {
40      super();
41      // TODO Auto-generated constructor stub
42    }
43  
44    /* (non-Javadoc)
45     * @see it.imolinfo.jbi4cics.connection.jca.JCAAbstractConnectionManager#createOutputMessage(it.imolinfo.jbi4cics.service.ServiceContext, javax.resource.cci.Record)
46     */
47    protected Object createOutputMessage(ServiceContext serviceContext, Record outputRecord) throws ConnectionException {
48      if (!(outputRecord instanceof CommareaRecord)){
49        //TODO loggare correttamente
50        throw new ConnectionException("CIC000310_Expected_commarea_record", new Object[] {outputRecord.getClass()});
51      }
52      return ((CommareaRecord)outputRecord).getCommarea();
53    }
54  
55  
56  
57    /* (non-Javadoc)
58     * @see it.imolinfo.jbi4cics.connection.jca.JCAAbstractConnectionManager#createOutputRecord(it.imolinfo.jbi4cics.service.ServiceContext)
59     */
60    protected Record createOutputRecord(ServiceContext serviceContext) throws ConnectionException {
61      CommareaRecord outputRecord=new CommareaRecord();
62      //TODO ?? inputRecord.setRecordName();      
63      //TODO ?? inputRecord.setRecordShortDescription();
64      if (!(serviceContext.getOutputMappingDescriptor() instanceof CommareaBeanMappingDescriptor)){
65        //TODO loggare correttamente
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    /* (non-Javadoc)
80     * @see it.imolinfo.jbi4cics.connection.jca.JCAAbstractConnectionManager#createInputRecord(it.imolinfo.jbi4cics.service.ServiceContext)
81     */
82    protected Record createInputRecord(ServiceContext serviceContext) throws ConnectionException {
83      CommareaRecord inputRecord=new CommareaRecord();
84      //TODO ?? inputRecord.setRecordName();      
85      //TODO ?? inputRecord.setRecordShortDescription();
86      Object inputMessage=serviceContext.getInputMessage();
87      if (!(inputMessage instanceof byte[])){
88        //TODO loggare correttamente
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    /* (non-Javadoc)
96     * @see it.imolinfo.jbi4cics.connection.jca.JCAAbstractConnectionManager#createInteractionSpec(it.imolinfo.jbi4cics.service.ServiceContext)
97     */
98    protected abstract InteractionSpec createInteractionSpec(ServiceContext serviceContext) throws ConnectionException;
99  
100   /* (non-Javadoc)
101    * @see it.imolinfo.jbi4cics.connection.jca.JCAAbstractConnectionManager#createConnectionSpec(it.imolinfo.jbi4cics.service.ServiceContext)
102    */
103   protected abstract ConnectionSpec createConnectionSpec(ServiceContext serviceContext) throws ConnectionException;
104 
105 }