Example 1: WmAdapterService Implementation Class
package com.wm.MyAdapter.services;
import com.wm.adk.cci.interaction.WmAdapterService;
import com.wm.adk.cci.record.WmRecord;
import com.wm.adk.cci.record.WmRecordFactory;
import com.wm.adk.connection.WmManagedConnection;
import com.wm.adk.metadata.WmTemplateDescriptor;
import com.wm.data.IData;
import com.wm.data.IDataCursor;
import com.wm.data.IDataFactory;
import com.wm.data.IDataUtil;
import java.util.Hashtable;
import java.util.Locale;
import javax.resource.ResourceException;
import com.wm.MyAdapter.MyAdapter;
public class MockDbUpdate extends WmAdapterService {
//MockDB Group
public static final String UPD_SETTINGS_GRP = "Mock Settings";
public static final String TABLE_NAME_PARM = "tableName";
public static final String COLUMN_NAMES_PARM = "columnNames";
public static final String COLUMN_TYPES_PARM = "columnTypes";
public static final String REPEATING_PARM = "repeating";
public static final String OVERRIDE_TYPES_PARM = "overrideTypes";
private String _tableName;
private String[] _columnNames;
private String[] _columnTypes;
private boolean _repeating;
private String[] _overrideTypes;
public void setTableName(String val){ _tableName = val;}
public void setColumnNames(String[] val){ _columnNames = val;}
public void setColumnTypes(String[] val){ _columnTypes = val;}
public void setRepeating(boolean val){ _repeating = val;}
public void setOverrideTypes(String[] val){_overrideTypes = val;}
public static final String TABLES_RD = "tablesRD";
public static final String COLUMN_NAMES_RD = "columnNamesRD";
public static final String COLUMN_TYPES_RD = "columnTypesRD";
public static final String OVERRIDE_TYPES_RD = "overrideTypesRD";
//MockDB Signature Group
public static final String SIG_SETTINGS_GRP = "Signature";
public static final String FIELD_NAMES_PARM = "fieldNames";
public static final String FIELD_TYPES_PARM = "fieldTypes";
public static final String SIG_IN_PARM = "sigIn";
public static final String SIG_OUT_PARM = "sigOut";
private String[] _fieldNames;
private String[] _fieldTypes;
public void setFieldNames(String[] val){ _fieldNames = val;}
public void setFieldTypes(String[] val){ _fieldTypes = val;}
public void setSigIn(String[] val){}
public void setSigOut(String[] val){}
public static final String FIELD_NAMES_RD = "fieldNamesRD";
public static final String FIELD_TYPES_RD = "fieldTypesRD";
public void fillWmTemplateDescriptor(WmTemplateDescriptor d,Locale l)
throws ResourceException
{
//MockDB Grouping and resource domain setup
d.createGroup(UPD_SETTINGS_GRP, new String [] {
TABLE_NAME_PARM,
REPEATING_PARM,
COLUMN_NAMES_PARM,
COLUMN_TYPES_PARM,
OVERRIDE_TYPES_PARM}
);
d.createFieldMap(new String[] {
COLUMN_NAMES_PARM,
COLUMN_TYPES_PARM,
OVERRIDE_TYPES_PARM},
true);
d.createTuple(new String[]{COLUMN_NAMES_PARM,COLUMN_TYPES_PARM});
d.setResourceDomain(TABLE_NAME_PARM,TABLES_RD,null);
d.setResourceDomain(COLUMN_NAMES_PARM,COLUMN_NAMES_RD,
new String[]{TABLE_NAME_PARM});
d.setResourceDomain(COLUMN_TYPES_PARM,COLUMN_TYPES_RD,
new String[]{TABLE_NAME_PARM});
d.setResourceDomain(OVERRIDE_TYPES_PARM,OVERRIDE_TYPES_RD,null);
//MockDB Signature Grouping and resource domain setup
d.createGroup(SIG_SETTINGS_GRP, new String [] {
FIELD_NAMES_PARM,
FIELD_TYPES_PARM,
SIG_IN_PARM,
SIG_OUT_PARM}
);
d.createFieldMap(new String [] {
FIELD_NAMES_PARM,
FIELD_TYPES_PARM,
SIG_IN_PARM,
SIG_OUT_PARM},
false);
d.createTuple(new String[]{FIELD_NAMES_PARM,FIELD_TYPES_PARM});
String [] fieldTupleDependencies = {TABLE_NAME_PARM,
REPEATING_PARM,
COLUMN_NAMES_PARM,
COLUMN_TYPES_PARM,
OVERRIDE_TYPES_PARM};
d.setResourceDomain(FIELD_NAMES_PARM,FIELD_NAMES_RD, fieldTupleDependencies);
d.setResourceDomain(FIELD_TYPES_PARM,FIELD_TYPES_RD, fieldTupleDependencies);
d.setResourceDomain(SIG_IN_PARM,WmTemplateDescriptor.INPUT_FIELD_NAMES,
new String[] {FIELD_NAMES_PARM, FIELD_TYPES_PARM});
d.setResourceDomain(SIG_OUT_PARM,WmTemplateDescriptor.OUTPUT_FIELD_NAMES,
new String[] {FIELD_NAMES_PARM, FIELD_TYPES_PARM});
//Call to setDescriptions
d.setDescriptions(MyAdapter.getInstance().
getAdapterResourceBundleManager(),l);
}
public WmRecord execute(WmManagedConnection connection, WmRecord input)
throws ResourceException
{
Hashtable[] request = this.unpackRequest(input);
return this.packResonse(request);
}
private Hashtable[] unpackRequest(WmRecord request) throws ResourceException
{
Hashtable data[] = null;
IData mainIData = request.getIData();
IDataCursor mainCursor = mainIData.getCursor();
try
{
String tableName = this._tableName;
String[] columnNames = this._columnNames;
if(mainCursor.first(tableName))
{
IData[] recordIData;
if(this._repeating)
{
recordIData = IDataUtil.getIDataArray (mainCursor,tableName);
data = new Hashtable[recordIData.length];
}
else
{
recordIData = new IData[] {IDataUtil.getIData(mainCursor)};
data = new Hashtable[1];
}
for(int rec=0;rec<recordIData.length;rec++)
{
IDataCursor recordCursor = recordIData[rec].getCursor();
data[rec] = new Hashtable();
for(int c = 0; c < columnNames.length;c++)
{
if(recordCursor.first(columnNames[c]))
{
data[rec].put(tableName + "." + columnNames[c],
recordCursor.getValue());
}
}
recordCursor.destroy();
}
}
else
{
throw MyAdapter.getInstance().createAdapterException(9999,
new String[] {"No Request Data"});
}
}
catch (Throwable t)
{
throw MyAdapter.getInstance().createAdapterException(9999,
new String[] {"Error unpacking request data"},t);
}
finally
{
mainCursor.destroy();
}
return data;
}
private WmRecord packResonse(Hashtable[] response) throws ResourceException
{
WmRecord data = null;
try
{
IData[] recordIData = new IData[response.length];
String tableName = this._tableName;
String[] columnNames = this._columnNames;
for(int rec = 0; rec < response.length; rec++)
{
recordIData[rec] = IDataFactory.create();
IDataCursor recordCursor = recordIData[rec].getCursor();
for(int col = 0; col < columnNames.length;col++)
{
IDataUtil.put(recordCursor,columnNames[col],
response[rec].get(tableName + "." +
columnNames[col]));
}
recordCursor.destroy();
}
IData mainIData = IDataFactory.create();
IDataCursor mainCursor = mainIData.getCursor();
if(this._repeating)
{
IDataUtil.put(mainCursor,tableName,recordIData);
}
else
{
IDataUtil.put(mainCursor,tableName,recordIData[0]);
}
mainCursor.destroy();
data = WmRecordFactory.getFactory().createWmRecord("nameNotUsed");
data.setIData(mainIData);
}
catch (Throwable t)
{
throw MyAdapter.getInstance().createAdapterException(9999,
new String[] {"Error packing response data"},t);
}
return data;
}
}