1 16 17 package org.springframework.jca.cci.object; 18 19 import java.io.IOException ; 20 21 import javax.resource.cci.ConnectionFactory ; 22 import javax.resource.cci.InteractionSpec ; 23 import javax.resource.cci.Record ; 24 import javax.resource.cci.RecordFactory ; 25 26 import org.springframework.dao.DataAccessException; 27 import org.springframework.dao.DataRetrievalFailureException; 28 import org.springframework.jca.cci.core.support.CommAreaRecord; 29 30 37 public abstract class MappingCommAreaOperation extends MappingRecordOperation { 38 39 44 public MappingCommAreaOperation() { 45 } 46 47 52 public MappingCommAreaOperation(ConnectionFactory connectionFactory, InteractionSpec interactionSpec) { 53 super(connectionFactory, interactionSpec); 54 } 55 56 57 protected final Record createInputRecord(RecordFactory recordFactory, Object inObject) { 58 try { 59 return new CommAreaRecord(objectToBytes(inObject)); 60 } 61 catch (IOException ex) { 62 throw new DataRetrievalFailureException("I/O exception during bytes conversion", ex); 63 } 64 } 65 66 protected final Object extractOutputData(Record record) throws DataAccessException { 67 CommAreaRecord commAreaRecord = (CommAreaRecord) record; 68 try { 69 return bytesToObject(commAreaRecord.toByteArray()); 70 } 71 catch (IOException ex) { 72 throw new DataRetrievalFailureException("I/O exception during bytes conversion", ex); 73 } 74 } 75 76 77 84 protected abstract byte[] objectToBytes(Object inObject) throws IOException , DataAccessException; 85 86 93 protected abstract Object bytesToObject(byte[] bytes) throws IOException , DataAccessException; 94 95 } 96 | Popular Tags |