001 package com.mockrunner.connector;
002
003 import javax.resource.ResourceException;
004 import javax.resource.cci.InteractionSpec;
005 import javax.resource.cci.Record;
006
007 /**
008 * Implementations of this interface can be addded to {@link InteractionHandler}.
009 * When one of the two <code>execute</code> methods of {@link com.mockrunner.mock.connector.cci.MockInteraction}
010 * are called, the {@link InteractionHandler} iterates through the implementors
011 * and dispatches the <code>execute</code> call to the first one which returns
012 * <code>true</code> for {@link #canHandle}.
013 * There are several implementations of this interface, e.g.
014 * {@link StreamableRecordByteArrayInteraction},
015 * {@link WSIFInteraction},
016 * {@link IndexedRecordInteraction},
017 * {@link MappedRecordInteraction}.
018 * Of course, you can also implement your own version and it may be necessary
019 * in many situations.
020 */
021 public interface InteractionImplementor
022 {
023 /**
024 * Implementors should return <code>true</code> if this implementor can handle the request.
025 * Please note that for calls to {@link #execute(InteractionSpec, Record)},
026 * the second <code>Record</code> parameter is <code>null</code>.
027 * @param interactionSpec the <code>InteractionSpec</code> for the actual call
028 * @param actualRequest the request for the actual call
029 * @param actualResponse the response for the actual call, may be <code>null</code>
030 * @return <code>true</code> if this implementor will handle the request and
031 * will return the specified response, <code>false</code> otherwise
032 */
033 public boolean canHandle(InteractionSpec interactionSpec, Record actualRequest, Record actualResponse);
034
035 /**
036 * First version of the <code>Interaction.execute</code> methods.
037 * @param interactionSpec the interaction spec
038 * @param actualRequest the actual request
039 * @return the response according to the current request
040 */
041 public Record execute(InteractionSpec interactionSpec, Record actualRequest) throws ResourceException;
042
043 /**
044 * Second version of the <code>Interaction.execute</code> methods.
045 * @param interactionSpec the interaction spec
046 * @param actualRequest the actual request
047 * @param actualResponse the actual response
048 * @return <code>true</code> under normal conditions
049 */
050 public boolean execute(InteractionSpec interactionSpec, Record actualRequest, Record actualResponse) throws ResourceException;
051 }