user manual

318 BES Developers Guide
Application Development Overview
javax.naming.Context ctx = new javax.naming.InitialContext();
javax.resource.cci.ConnectionFactory cxFactory =
(javax.resource.cci.ConnectionFactory)ctx.lookup(
"java:comp/env/shme/shmeAdapter" );
javax.resource.cci.Connection cx = cxFactory.getConnection();
// Create an Interaction instance
javax.resource.cci.Interaction ix = ct.createInteraction();
// Create a new instance of the respective InteractionSpec
com.shme.shmeAdapter.InteractionSpecImpl ixSpec = new
com.shme.shmeAdapter.InteractionSpecImpl();
ixSpec.setFunctionName( "S_EXEC" );
ixSpec.setInteractionVerb(
javax.resource.cci.InteractionSpec.SYNC_SEND_RECEIVE );
// ...
// Get a RecordFactory instance
javax.resource.cci.RecordFactory recFactory = // ... get a RecordFactory
// Create a generic MappedRecord using the RecordFactory instance. This
record
// instance acts as an input to the execution of an interaction. The name
of the
// Record acts as a pointer to the metadata for a specific record type
javax.resource.cci.MappedRecord input = recFactory.createMappedRecord(
"ShmeExecRecord" );
// Populate the generic MappedRecord instance with input values. The
component
// code adds values based on the metadata it has accessed from the metadata
// repository
input.put( "<key: element0>", new String( "S_APP01" );
input.put( "<key: element1>", // ... );
// ...
// Create a generic IndexedRecord to hold output values that are set by the
// execution of the interaction
javax.resource.cci.IndexedRecord output = recFactory.createIndexedRecord(
"ShmeExecRecord" );
// Execute the Interaction
boolean response = ix.execute( ixSpec, input, output );
// Extract data from the output IndexedRecord. Note that type mapping is
done
// in the generic IndexedRecord by mean of the type mapping information in
the
// metadata repository. Since the component uses generic methods on the
// IndexedRecord, the component code performs the required type casting
java.util.Iterator iter = output.iterator();