KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > jca > cci > object > MappingCommAreaOperation


1 /*
2  * Copyright 2002-2005 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.springframework.jca.cci.object;
18
19 import java.io.IOException JavaDoc;
20
21 import javax.resource.cci.ConnectionFactory JavaDoc;
22 import javax.resource.cci.InteractionSpec JavaDoc;
23 import javax.resource.cci.Record JavaDoc;
24 import javax.resource.cci.RecordFactory JavaDoc;
25
26 import org.springframework.dao.DataAccessException;
27 import org.springframework.dao.DataRetrievalFailureException;
28 import org.springframework.jca.cci.core.support.CommAreaRecord;
29
30 /**
31  * EIS operation object for access to COMMAREA records.
32  * Subclass of the generic MappingRecordOperation class.
33  *
34  * @author Thierry Templier
35  * @since 1.2
36  */

37 public abstract class MappingCommAreaOperation extends MappingRecordOperation {
38
39     /**
40      * Create a new MappingCommAreaQuery.
41      * @see #setConnectionFactory
42      * @see #setInteractionSpec
43      */

44     public MappingCommAreaOperation() {
45     }
46
47     /**
48      * Create a new MappingCommAreaQuery.
49      * @param connectionFactory ConnectionFactory to use to obtain connections
50      * @param interactionSpec specification to configure the interaction
51      */

52     public MappingCommAreaOperation(ConnectionFactory JavaDoc connectionFactory, InteractionSpec JavaDoc interactionSpec) {
53         super(connectionFactory, interactionSpec);
54     }
55
56
57     protected final Record JavaDoc createInputRecord(RecordFactory JavaDoc recordFactory, Object JavaDoc inObject) {
58         try {
59             return new CommAreaRecord(objectToBytes(inObject));
60         }
61         catch (IOException JavaDoc ex) {
62             throw new DataRetrievalFailureException("I/O exception during bytes conversion", ex);
63         }
64     }
65
66     protected final Object JavaDoc extractOutputData(Record JavaDoc record) throws DataAccessException {
67         CommAreaRecord commAreaRecord = (CommAreaRecord) record;
68         try {
69             return bytesToObject(commAreaRecord.toByteArray());
70         }
71         catch (IOException JavaDoc ex) {
72             throw new DataRetrievalFailureException("I/O exception during bytes conversion", ex);
73         }
74     }
75
76
77     /**
78      * Method used to convert an object into COMMAREA bytes.
79      * @param inObject the input data
80      * @return the COMMAREA's bytes
81      * @throws IOException if thrown by I/O methods
82      * @throws DataAccessException if conversion failed
83      */

84     protected abstract byte[] objectToBytes(Object JavaDoc inObject) throws IOException JavaDoc, DataAccessException;
85
86     /**
87      * Method used to convert the COMMAREA's bytes to an object.
88      * @param bytes the COMMAREA's bytes
89      * @return the output data
90      * @throws IOException if thrown by I/O methods
91      * @throws DataAccessException if conversion failed
92      */

93     protected abstract Object JavaDoc bytesToObject(byte[] bytes) throws IOException JavaDoc, DataAccessException;
94
95 }
96
Popular Tags