001: /*
002: * Copyright 2002-2005 the original author or authors.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016:
017: package org.springframework.jca.cci.object;
018:
019: import java.io.IOException;
020:
021: import javax.resource.cci.ConnectionFactory;
022: import javax.resource.cci.InteractionSpec;
023: import javax.resource.cci.Record;
024: import javax.resource.cci.RecordFactory;
025:
026: import org.springframework.dao.DataAccessException;
027: import org.springframework.dao.DataRetrievalFailureException;
028: import org.springframework.jca.cci.core.support.CommAreaRecord;
029:
030: /**
031: * EIS operation object for access to COMMAREA records.
032: * Subclass of the generic MappingRecordOperation class.
033: *
034: * @author Thierry Templier
035: * @since 1.2
036: */
037: public abstract class MappingCommAreaOperation extends
038: MappingRecordOperation {
039:
040: /**
041: * Create a new MappingCommAreaQuery.
042: * @see #setConnectionFactory
043: * @see #setInteractionSpec
044: */
045: public MappingCommAreaOperation() {
046: }
047:
048: /**
049: * Create a new MappingCommAreaQuery.
050: * @param connectionFactory ConnectionFactory to use to obtain connections
051: * @param interactionSpec specification to configure the interaction
052: */
053: public MappingCommAreaOperation(
054: ConnectionFactory connectionFactory,
055: InteractionSpec interactionSpec) {
056: super (connectionFactory, interactionSpec);
057: }
058:
059: protected final Record createInputRecord(
060: RecordFactory recordFactory, Object inObject) {
061: try {
062: return new CommAreaRecord(objectToBytes(inObject));
063: } catch (IOException ex) {
064: throw new DataRetrievalFailureException(
065: "I/O exception during bytes conversion", ex);
066: }
067: }
068:
069: protected final Object extractOutputData(Record record)
070: throws DataAccessException {
071: CommAreaRecord commAreaRecord = (CommAreaRecord) record;
072: try {
073: return bytesToObject(commAreaRecord.toByteArray());
074: } catch (IOException ex) {
075: throw new DataRetrievalFailureException(
076: "I/O exception during bytes conversion", ex);
077: }
078: }
079:
080: /**
081: * Method used to convert an object into COMMAREA bytes.
082: * @param inObject the input data
083: * @return the COMMAREA's bytes
084: * @throws IOException if thrown by I/O methods
085: * @throws DataAccessException if conversion failed
086: */
087: protected abstract byte[] objectToBytes(Object inObject)
088: throws IOException, DataAccessException;
089:
090: /**
091: * Method used to convert the COMMAREA's bytes to an object.
092: * @param bytes the COMMAREA's bytes
093: * @return the output data
094: * @throws IOException if thrown by I/O methods
095: * @throws DataAccessException if conversion failed
096: */
097: protected abstract Object bytesToObject(byte[] bytes)
098: throws IOException, DataAccessException;
099:
100: }
|