Adapter Development Kit 9.12 | webMethods Adapter Development Kit Documentation | webMethods Adapter Development Kit Installation and User’s Documentation | Alternative Approaches to Metadata | An Alternative Approach to Organizing Resource Domains
 
An Alternative Approach to Organizing Resource Domains
The model described in this section provides an alternative way of organizing resource domain information, such that the resource domain implementation is contained within each adapter service or notification class that uses the resource domain, rather than within your WmManagedConnection implementation. To implement this approach you must perform the following:
*Create an interface defining the methods for resource domain handling. The following methods are defined:
*adapterResourceDomainLookup
*adapterCheckValue
*registerResourceDomain
*Update the connection factory to use a string array containing the class name for each service or notification type added to the adapter.
*Remove the methods listed in the resource domain handler interface from connection implementation class.
*Implement the resource domain handler interface in the service and notification classes which enables the classes to manage their own resource domain functionality.
Note:
The ResourceDomainHandler interface is not delivered as part of the ADK.
1. Create an interface for handling the resource domain.
In this example, a ResourceDomainHandler is created in the com.wm.MyAdapter package.
package com.wm.MyAdapter;

import com.wm.adk.connection.WmManagedConnection;

import com.wm.adk.metadata.*;
import com.wm.adk.error.*;

public interface ResourceDomainHandler
{
/**
* Implements resource domain lookups using the provided connection. Refer to
* the method of the same name in com.wm.adk.connection.WmManagedConnection.
**
@param connection
* @param resourceDomainName
* @param values
* @return ResourceDomainValues[]
* @throws AdapterException
*/
public ResourceDomainValues[] adapterResourceDomainLookup(
WmManagedConnection connection, String resourceDomainName,
String[][] values) throws AdapterException;
/**
* Implements Adapter check values using the provided connection. Refer to
* the method of the same name in com.wm.adk.connection.WmManagedConnection.
**
@param connection
* @param resourceDomainName
* @param values
* @param testValue
* @return Boolean
* @throws AdapterException
*/
public Boolean adapterCheckValue( WmManagedConnection connection,
String resourceDomainName,
String[][] values, String testValue) throws AdapterException;
/**
* Implements resource domain registrations specific to a particular service
* or notification. Refer to the method of the same name in
* com.wm.adk.connection.WmManagedConnectionFactory.
**
@param connection
* @param access
* @throws AdapterException
*/
public void registerResourceDomain(WmManagedConnection connection,
WmAdapterAccess access) throws AdapterException;
}
2. Update the connection factory implementation class to create a list of services and notifications that implement the interface, register them, and pass to the connections that the connection factory creates.
In this example a class SimpleConnectionFactory contains the following:
*Create a supportedServiceTemplates string array containing the class name of the adapter service templates.
*Create a supportedNotificationTemplates string array containing the class name of the adapter notification templates.
*Update fillResourceAdapterMetadataInfo method using supportedServiceTemplates to register the adapter service templates, and supportedNotificationTemplates to register the adapter notification templates.
*Update createManagedConnectionObject method to pass the list of services and notifications implementing the resource domain handler interface to the connection class.
package com.wm.MyAdapter.connections;

import com.wm.adk.connection.WmManagedConnectionFactory;
import com.wm.adk.connection.WmManagedConnection;
import com.wm.adk.info.ResourceAdapterMetadataInfo;
import com.wm.adk.metadata.WmDescriptor;
import com.wm.adk.error.AdapterException;

import java.util.Locale;
import java.util.ArrayList;
import java.util.Arrays;

import com.wm.MyAdapter.MyAdapter;
import com.wm.MyAdapter.MyAdapterConstants;
import com.wm.MyAdapter.services.MockDbUpdate;
import com.wm.MyAdapter.services.UIMockDbUpdate;


public class SimpleConnectionFactory extends WmManagedConnectionFactory implements MyAdapterConstants {
private String hostName;
private int port;

private static final String[] supportedServiceTemplates = {
MockDbUpdate.class.getName(),
UIMockDbUpdate.class.getName()
};

/*
private static final String[] supportedNotificationTemplates = {
SimpleNotification.class.getName(),
SessionLogListenerNotification.class.getName()
};
*/

public void setHostName(String hostNameValue){hostName = hostNameValue;}
public void setPort(int portValue){port = portValue;}

public SimpleConnectionFactory(){super();}
public WmManagedConnection createManagedConnectionObject(
javax.security.auth.Subject subject,
javax.resource.spi.ConnectionRequestInfo cxRequestInfo)
{
ArrayList templateList = new ArrayList(Arrays.asList(supportedServiceTemplates));
//Use the following to add notifications or other services
//templateList.addAll(Arrays.asList(supportedNotificationTemplates));
String[] listArg = new String[templateList.size()];
templateList.toArray(listArg);
return new SimpleConnection(hostName,port,listArg);
}
public void fillWmDescriptor(WmDescriptor d,Locale l) throws
AdapterException
{
d.createGroup(GROUP_SIMPLE_CONNECTION,
new String[]{SIMPLE_SERVER_HOST_NAME, SIMPLE_SERVER_PORT_NUMBER});
d.setValidValues(SIMPLE_SERVER_PORT_NUMBER, new String[] {"5555","1555","4000"});
d.setDescriptions(
MyAdapter.getInstance().getAdapterResourceBundleManager(),l);
}
public void fillResourceAdapterMetadataInfo(ResourceAdapterMetadataInfo info, Locale locale) {

for (int i = 0; i < supportedServiceTemplates.length;i++)
{
info.addServiceTemplate(supportedServiceTemplates[i]);
}
//Use the following to add notifications or other services
/*
for (int i = 0; i < supportedNotificationTemplates.length;i++)
{
info.addNotificationTemplate(supportedNotificationTemplates[i]);
}
*/
}
}
3. Update the connection implementation class to use the service name and forward the requests to the appropriate service or notification class.
In this example, the SimpleConnection class contains the following:
*Create the registerResourceDomain method and forward the requests to the appropriate service or notification class.
*Create the adapterResourceDomainLookup method, use the service name to identify the class name, and forward the requests to the appropriate service or notification class.
*Create the adapterCheckValue method, use the service name to identify the class name, and forward the requests to the appropriate service or notification class.
package com.wm.MyAdapter.connections;

import com.wm.adk.connection.WmManagedConnection;
import com.wm.adk.metadata.*;
import com.wm.adk.error.AdapterException;

import com.wm.MyAdapter.MyAdapter;
import com.wm.MyAdapter.services.MockDbUpdate;
import com.wm.MyAdapter.ResourceDomainHandler;


public class SimpleConnection extends WmManagedConnection {
String hostName;
int port;
private String[] resourceHandlerList;


public SimpleConnection(String hostNameValue, int portValue, String[] resourceHandlerListValue)
{
super();
hostName = hostNameValue;
port = portValue;
resourceHandlerList = resourceHandlerListValue;
MyAdapter.getInstance().getLogger().logDebug(9999,
"Simple Connection created with hostName = "
+ hostName + "and port = " + Integer.toString(port));
}
public void destroyConnection()
{
MyAdapter.getInstance().getLogger().logDebug(9999,"Simple Connection Destroyed");
}

public void registerResourceDomain(WmAdapterAccess access)
throws AdapterException
{
try {
Class serviceClass;
ResourceDomainHandler serviceObject;
for (int i = 0;i < resourceHandlerList.length;i++ ) {
serviceClass = Class.forName(resourceHandlerList[i]);
serviceObject = (ResourceDomainHandler)serviceClass.newInstance();
serviceObject.registerResourceDomain(this,access);
}
}
catch (Throwable t) {
throw MyAdapter.getInstance().createAdapterException(9999,t);
}
}
public ResourceDomainValues[] adapterResourceDomainLookup(String serviceName,
String resourceDomainName, String[][] values) throws AdapterException
{
Class serviceClass;
ResourceDomainHandler serviceObject;
try {
serviceClass = Class.forName(serviceName);
serviceObject = (ResourceDomainHandler)serviceClass.newInstance();
}
catch (Throwable t) {
throw MyAdapter.getInstance().createAdapterException(9999,t);
}
return serviceObject.adapterResourceDomainLookup(this,resourceDomainName,values);
}

public Boolean adapterCheckValue(String serviceName,
String resourceDomainName,
String[][] values,
String testValue) throws AdapterException
{
Class serviceClass;
ResourceDomainHandler serviceObject;
try {
serviceClass = Class.forName(serviceName);
serviceObject = (ResourceDomainHandler)serviceClass.newInstance();
}
catch (Throwable t) {
throw MyAdapter.getInstance().createAdapterException(9999,t);
}
return serviceObject.adapterCheckValue(this,resourceDomainName,values,testValue);
}
}
4. Create two adapter service templates classes.
In this example, the two adapter service templates created are:
*UIMockDbUpdate 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;
//Alternate
import com.wm.adk.connection.WmManagedConnection;
import com.wm.adk.metadata.*;
import com.wm.adk.error.AdapterException;
import com.wm.MyAdapter.ResourceDomainHandler;
//


public class UIMockDbUpdate extends WmAdapterService implements ResourceDomainHandler{
//Adapter Services variables
private String[] UI_mockTableNames ={ "UI_CUSTOMERS","UI_ORDERS","UI_LINE_ITEMS"};
private String[][] UI_mockColumnNames ={
{"name","id", "ssn"},
{"id","date","customer_id"},
{"order_id","item_number","quantity","description"}
};

private String [][] UI_mockDataTypes = {
{"java.lang.String","java.lang.Integer", "java.lang.String"},
{"java.lang.Integer", "java.util.Date", "java.lang.Integer"},
{"java.lang.Integer", "java.lang.Integer", "java.lang.Integer",
"java.lang.String"}
};


//MockDB Group
public static final String UI_UPD_SETTINGS_GRP = "UI Mock Settings";
public static final String UI_TABLE_NAME_PARM = "baseTableName";
public static final String UI_COLUMN_NAMES_PARM = "baseColumnNames";
public static final String UI_COLUMN_TYPES_PARM = "baseColumnTypes";
public static final String UI_REPEATING_PARM = "baseRepeating";
public static final String UI_OVERRIDE_TYPES_PARM = "baseOverrideTypes";

private String baseTableName;
private String[] baseColumnNames;
private String[] baseColumnTypes;
private boolean baseRepeating;
private String[] baseOverrideTypes;

public void setBaseTableName(String val){ baseTableName = val;}
public void setBaseColumnNames(String[] val){ baseColumnNames = val;}
public void setBaseColumnTypes(String[] val){ baseColumnTypes = val;}
public void setBaseRepeating(boolean val){ baseRepeating = val;}
public void setBaseOverrideTypes(String[] val){baseOverrideTypes = val;}

public static final String UI_TABLES_RD = "baseTablesRD";
public static final String UI_COLUMN_NAMES_RD = "baseColumnNamesRD";
public static final String UI_COLUMN_TYPES_RD = "baseColumnTypesRD";
public static final String UI_OVERRIDE_TYPES_RD = "baseOverrideTypesRD";

public void fillWmTemplateDescriptor(WmTemplateDescriptor d,Locale l)
throws ResourceException
{
//UIMockDB Grouping and resource domain setup
d.createGroup(UI_UPD_SETTINGS_GRP, new String [] {
UI_TABLE_NAME_PARM,
UI_REPEATING_PARM,
UI_COLUMN_NAMES_PARM,
UI_COLUMN_TYPES_PARM,
UI_OVERRIDE_TYPES_PARM}
);
d.createFieldMap(new String[] {
UI_COLUMN_NAMES_PARM,
UI_COLUMN_TYPES_PARM,
UI_OVERRIDE_TYPES_PARM},
true);
d.createTuple(new String[]{UI_COLUMN_NAMES_PARM, UI_COLUMN_TYPES_PARM});

d.setResourceDomain(UI_TABLE_NAME_PARM, UI_TABLES_RD, null);
d.setResourceDomain(UI_COLUMN_NAMES_PARM, UI_COLUMN_NAMES_RD,
new String[]{UI_TABLE_NAME_PARM});
d.setResourceDomain(UI_COLUMN_TYPES_PARM, UI_COLUMN_TYPES_RD,
new String[]{UI_TABLE_NAME_PARM});
d.setResourceDomain(UI_OVERRIDE_TYPES_PARM,UI_OVERRIDE_TYPES_RD,null);

//Call to setDescriptions
d.setDescriptions(MyAdapter.getInstance().
getAdapterResourceBundleManager(),l);
}
public WmRecord execute(WmManagedConnection connection, WmRecord input)
throws ResourceException
{
Hashtable[] request = unpackRequest(input);
return packResonse(request);
}

private Hashtable[] unpackRequest(WmRecord request) throws ResourceException
{
Hashtable data[] = null;
IData mainIData = request.getIData();
IDataCursor mainCursor = mainIData.getCursor();

try
{
String tableNameValue = baseTableName;
String[] columnNamesValue = baseColumnNames;

if(mainCursor.first(tableNameValue))
{
IData[] recordIData;
if(baseRepeating)
{
recordIData = IDataUtil.getIDataArray (mainCursor,tableNameValue);
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 < columnNamesValue.length;c++)
{
if(recordCursor.first(columnNamesValue[c]))
{
data[rec].put(tableNameValue + "." + columnNamesValue[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 tableNameValue = baseTableName;
String[] columnNamesValue = baseColumnNames;

for(int rec = 0; rec < response.length; rec++)
{
recordIData[rec] = IDataFactory.create();
IDataCursor recordCursor = recordIData[rec].getCursor();
for(int col = 0; col < columnNamesValue.length;col++)
{
IDataUtil.put(recordCursor,columnNamesValue[col],
response[rec].get(tableNameValue + "." +
columnNamesValue[col]));
}
recordCursor.destroy();
}
IData mainIData = IDataFactory.create();
IDataCursor mainCursor = mainIData.getCursor();
if(baseRepeating)
{
IDataUtil.put(mainCursor,tableNameValue,recordIData);
}
else
{
IDataUtil.put(mainCursor,tableNameValue,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;
}

//Alternate Methods
public void registerResourceDomain(WmManagedConnection connection, WmAdapterAccess access)
throws AdapterException
{
//UIMockDB Group Registering Resource Domain
ResourceDomainValues tableRdvs = new ResourceDomainValues(
UIMockDbUpdate.UI_TABLES_RD, UI_mockTableNames);
tableRdvs.setComplete(true);
access.addResourceDomain(tableRdvs);

access.addResourceDomainLookup(UIMockDbUpdate.UI_COLUMN_NAMES_RD,connection);
access.addResourceDomainLookup(UIMockDbUpdate.UI_COLUMN_TYPES_RD,connection);

ResourceDomainValues rdvs = new ResourceDomainValues(
UIMockDbUpdate.UI_OVERRIDE_TYPES_RD, new String[] {""});
rdvs.setComplete(false);
rdvs.setCanValidate(true);
access.addResourceDomain(rdvs);
access.addCheckValue(UIMockDbUpdate.UI_OVERRIDE_TYPES_RD,connection);

}

public ResourceDomainValues[] adapterResourceDomainLookup(
WmManagedConnection connection,
String resourceDomainName, String[][] values) throws AdapterException
{
ResourceDomainValues[] results = null;

if(resourceDomainName.equals(UIMockDbUpdate.UI_COLUMN_NAMES_RD)||
resourceDomainName.equals(UIMockDbUpdate.UI_COLUMN_TYPES_RD))
{
String tableName = values[0][0];
for(int x = 0; x < UI_mockTableNames.length;x++)
{
if(UI_mockTableNames[x].equals(tableName))
{
ResourceDomainValues columnsRdvs = new ResourceDomainValues(
UIMockDbUpdate.UI_COLUMN_NAMES_RD,UI_mockColumnNames[x]);
columnsRdvs.setComplete(true);
ResourceDomainValues typesRdvs = new ResourceDomainValues(
UIMockDbUpdate.UI_COLUMN_TYPES_RD, UI_mockDataTypes[x]);
typesRdvs.setComplete(true);
results = new ResourceDomainValues[] {columnsRdvs,typesRdvs};
break;
}
}
}

return results;
}

public Boolean adapterCheckValue(WmManagedConnection connection,
String resourceDomainName,
String[][] values,
String testValue) throws AdapterException
{
Boolean result = new Boolean(false);
if(resourceDomainName.equals(UIMockDbUpdate.UI_OVERRIDE_TYPES_RD))
{
try
{
Object o = Class.forName(testValue).getConstructor(
new Class[] {String.class}).newInstance(new Object[]{"0"});
result = new Boolean(true);
}
catch (Throwable t){}
}
return result;
}

}
*MockDbUpdate 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;
//Alternate
import com.wm.adk.connection.WmManagedConnection;
import com.wm.adk.metadata.*;
import com.wm.adk.error.AdapterException;
import com.wm.MyAdapter.ResourceDomainHandler;
//


public class MockDbUpdate extends WmAdapterService implements ResourceDomainHandler {

//Adapter Services variables
private String[] mockTableNames ={ "CUSTOMERS","ORDERS","LINE_ITEMS"};
private String[][] mockColumnNames ={
{"name","id", "ssn"},
{"id","date","customer_id"},
{"order_id","item_number","quantity","description"}
};

private String [][] mockDataTypes = {
{"java.lang.String","java.lang.Integer", "java.lang.String"},
{"java.lang.Integer", "java.util.Date", "java.lang.Integer"},
{"java.lang.Integer", "java.lang.Integer", "java.lang.Integer",
"java.lang.String"}
};

//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 = unpackRequest(input);
return packResonse(request);
}

private Hashtable[] unpackRequest(WmRecord request) throws ResourceException
{
Hashtable data[] = null;
IData mainIData = request.getIData();
IDataCursor mainCursor = mainIData.getCursor();

try
{
String tableNameValue = tableName;
String[] columnNamesValue = columnNames;

if(mainCursor.first(tableNameValue))
{
IData[] recordIData;
if(repeating)
{
recordIData = IDataUtil.getIDataArray (mainCursor,tableNameValue);
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 < columnNamesValue.length;c++)
{
if(recordCursor.first(columnNamesValue[c]))
{
data[rec].put(tableNameValue + "." + columnNamesValue[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 tableNameValue = tableName;
String[] columnNamesValue = columnNames;

for(int rec = 0; rec < response.length; rec++)
{
recordIData[rec] = IDataFactory.create();
IDataCursor recordCursor = recordIData[rec].getCursor();
for(int col = 0; col < columnNamesValue.length;col++)
{
IDataUtil.put(recordCursor,columnNamesValue[col],
response[rec].get(tableNameValue + "." +
columnNamesValue[col]));
}
recordCursor.destroy();
}
IData mainIData = IDataFactory.create();
IDataCursor mainCursor = mainIData.getCursor();
if(repeating)
{
IDataUtil.put(mainCursor,tableNameValue,recordIData);
}
else
{
IDataUtil.put(mainCursor,tableNameValue,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;
}

public void registerResourceDomain(WmManagedConnection connection, WmAdapterAccess access)
throws AdapterException
{
//MockDB Group Registering Resource Domain
ResourceDomainValues tableRdvs = new ResourceDomainValues(
MockDbUpdate.TABLES_RD,mockTableNames);
tableRdvs.setComplete(true);
access.addResourceDomain(tableRdvs);

access.addResourceDomainLookup(MockDbUpdate.COLUMN_NAMES_RD,connection);
access.addResourceDomainLookup(MockDbUpdate.COLUMN_TYPES_RD,connection);

ResourceDomainValues rdvs = new ResourceDomainValues(
MockDbUpdate.OVERRIDE_TYPES_RD, new String[] {""});
rdvs.setComplete(false);
rdvs.setCanValidate(true);
access.addResourceDomain(rdvs);
access.addCheckValue(MockDbUpdate.OVERRIDE_TYPES_RD,connection);

//MockDB Signature Group Registering Resource Domain
access.addResourceDomainLookup(MockDbUpdate.FIELD_NAMES_RD,connection);
access.addResourceDomainLookup(MockDbUpdate.FIELD_TYPES_RD,connection);
}

public ResourceDomainValues[] adapterResourceDomainLookup(
WmManagedConnection connection,
String resourceDomainName, String[][] values) throws AdapterException
{
ResourceDomainValues[] results = null;

//MockDB Group Lookup
if(resourceDomainName.equals(MockDbUpdate.COLUMN_NAMES_RD)||
resourceDomainName.equals(MockDbUpdate.COLUMN_TYPES_RD))
{
String tableName = values[0][0];
for(int x = 0; x < mockTableNames.length;x++)
{
if(mockTableNames[x].equals(tableName))
{
ResourceDomainValues columnsRdvs = new ResourceDomainValues(
MockDbUpdate.COLUMN_NAMES_RD,mockColumnNames[x]);
columnsRdvs.setComplete(true);
ResourceDomainValues typesRdvs = new ResourceDomainValues(
MockDbUpdate.COLUMN_TYPES_RD, mockDataTypes[x]);
typesRdvs.setComplete(true);
results = new ResourceDomainValues[] {columnsRdvs,typesRdvs};
break;
}
}
}
//MockDB Signature Group Lookup
else if (resourceDomainName.equals(MockDbUpdate.FIELD_NAMES_RD)||
resourceDomainName.equals(MockDbUpdate.FIELD_TYPES_RD))
{
String tableName = values[0][0];
boolean repeating = Boolean.valueOf(values[1][0]).booleanValue();
String[] columnNames = values[2];
String[] columnTypes = values[3];
String[] overrideTypes = values[4];

String[] fieldNames = new String[columnNames.length];
String[] fieldTypes = new String[columnTypes.length];
String optBrackets;

if(repeating)
optBrackets ="[]";
else
optBrackets = "";


for (int i = 0; i< fieldNames.length;i++)
{
fieldNames[i] = tableName + optBrackets + "." + columnNames[i];
fieldTypes[i] = columnTypes[i] + optBrackets;

if(overrideTypes.length > i)
{
if (!overrideTypes[i].equals(""))
{
fieldTypes[i] = overrideTypes[i] + optBrackets;
}

}

}
results = new ResourceDomainValues[]{
new ResourceDomainValues(MockDbUpdate.FIELD_NAMES_RD,fieldNames),
new ResourceDomainValues(MockDbUpdate.FIELD_TYPES_RD,fieldTypes)};

}

return results;
}

public Boolean adapterCheckValue(WmManagedConnection connection,
String resourceDomainName,
String[][] values,
String testValue) throws AdapterException
{
Boolean result = new Boolean(false);
if(resourceDomainName.equals(MockDbUpdate.OVERRIDE_TYPES_RD))
{
try
{
Object o = Class.forName(testValue).getConstructor(
new Class[] {String.class}).newInstance(new Object[]{"0"});
result = new Boolean(true);
}
catch (Throwable t){}
}
return result;
}
}
*Corresponding MyAdapterResource class:
package com.wm.MyAdapter;

import java.util.ListResourceBundle;
import com.wm.adk.ADKGLOBAL;

import com.wm.MyAdapter.connections.SimpleConnectionFactory;
import com.wm.MyAdapter.services.MockDbUpdate;
import com.wm.MyAdapter.services.UIMockDbUpdate;


public class MyAdapterResource extends ListResourceBundle implements MyAdapterConstants{

static final String IS_PKG_NAME = "/MyAdapter/";

static final Object[][] _contents = {
// adapter type display name.
{ADAPTER_NAME + ADKGLOBAL.RESOURCEBUNDLEKEY_DISPLAYNAME, "MyAdapter"}
// adapter type descriptions.
,{ADAPTER_NAME + ADKGLOBAL.RESOURCEBUNDLEKEY_DESCRIPTION,
"Adapter for MyAdapter Server (a Sample System)"}
// adapter type vendor.
,{ADAPTER_NAME + ADKGLOBAL.RESOURCEBUNDLEKEY_VENDORNAME, "Software AG"}
//Copyright URL Page
,{ADAPTER_NAME + ADKGLOBAL.RESOURCEBUNDLEKEY_THIRDPARTYCOPYRIGHTURL, IS_PKG_NAME + "copyright.html"}
//Copyright Encoding
,{ADAPTER_NAME + ADKGLOBAL.RESOURCEBUNDLEKEY_COPYRIGHTENCODING, "UTF-8"}
//About URL Page
,{ADAPTER_NAME + ADKGLOBAL.RESOURCEBUNDLEKEY_ABOUT, IS_PKG_NAME + "About.html"}
//Release Notes URL Page
,{ADAPTER_NAME + ADKGLOBAL.RESOURCEBUNDLEKEY_RELEASENOTEURL, IS_PKG_NAME + "ReleaseNotes.html"}

//SimpleConnection
,{SimpleConnectionFactory.class.getName() + ADKGLOBAL.RESOURCEBUNDLEKEY_DISPLAYNAME,
"Simple Connection"}
,{SimpleConnectionFactory.class.getName() + ADKGLOBAL.RESOURCEBUNDLEKEY_DESCRIPTION,
"Simple framework for demonstration purposes"}
,{SimpleConnectionFactory.SIMPLE_SERVER_HOST_NAME + ADKGLOBAL.RESOURCEBUNDLEKEY_DISPLAYNAME,
"Host Name"}
,{SimpleConnectionFactory.SIMPLE_SERVER_PORT_NUMBER + ADKGLOBAL.RESOURCEBUNDLEKEY_DISPLAYNAME,
"Port"}

//UIMockDB Group Resource Domain Values
,{UIMockDbUpdate.class.getName() + ADKGLOBAL.RESOURCEBUNDLEKEY_DISPLAYNAME,
"UI Mock Update Service"}
,{UIMockDbUpdate.class.getName() + ADKGLOBAL.RESOURCEBUNDLEKEY_DESCRIPTION,
"UI Simulates a database update service"}
,{UIMockDbUpdate.UI_UPD_SETTINGS_GRP + ADKGLOBAL.RESOURCEBUNDLEKEY_GROUP,
UIMockDbUpdate.UI_UPD_SETTINGS_GRP}
,{UIMockDbUpdate.UI_TABLE_NAME_PARM + ADKGLOBAL.RESOURCEBUNDLEKEY_DISPLAYNAME,
"UI Table Name"}
,{UIMockDbUpdate.UI_TABLE_NAME_PARM + ADKGLOBAL.RESOURCEBUNDLEKEY_DESCRIPTION,
"UI Select Table Name"}
,{UIMockDbUpdate.UI_COLUMN_NAMES_PARM + ADKGLOBAL.RESOURCEBUNDLEKEY_DISPLAYNAME,
"UI Column Names"}
,{UIMockDbUpdate.UI_COLUMN_NAMES_PARM + ADKGLOBAL.RESOURCEBUNDLEKEY_DESCRIPTION,
"UI Name of column updated by this service"}
,{UIMockDbUpdate.UI_COLUMN_TYPES_PARM + ADKGLOBAL.RESOURCEBUNDLEKEY_DISPLAYNAME,
"UI Column Types"}
,{UIMockDbUpdate.UI_COLUMN_TYPES_PARM + ADKGLOBAL.RESOURCEBUNDLEKEY_DESCRIPTION,
"UI Default data type for column"}
,{UIMockDbUpdate.UI_OVERRIDE_TYPES_PARM + ADKGLOBAL.RESOURCEBUNDLEKEY_DISPLAYNAME,
"UI Override Data Types"}
,{UIMockDbUpdate.UI_OVERRIDE_TYPES_PARM + ADKGLOBAL.RESOURCEBUNDLEKEY_DESCRIPTION,
"UI Type to override column default"}
,{UIMockDbUpdate.UI_REPEATING_PARM + ADKGLOBAL.RESOURCEBUNDLEKEY_DISPLAYNAME,
"UI Update Multiple Rows?"}
,{UIMockDbUpdate.UI_REPEATING_PARM + ADKGLOBAL.RESOURCEBUNDLEKEY_DESCRIPTION,
"UI Select if input will include multiple rows to update"}

//MockDB Group Resource Domain Values
,{MockDbUpdate.class.getName() + ADKGLOBAL.RESOURCEBUNDLEKEY_DISPLAYNAME,
"Mock Update Service"}
,{MockDbUpdate.class.getName() + ADKGLOBAL.RESOURCEBUNDLEKEY_DESCRIPTION,
"Simulates a database update service"}
,{MockDbUpdate.UPD_SETTINGS_GRP + ADKGLOBAL.RESOURCEBUNDLEKEY_GROUP,
MockDbUpdate.UPD_SETTINGS_GRP}
,{MockDbUpdate.TABLE_NAME_PARM + ADKGLOBAL.RESOURCEBUNDLEKEY_DISPLAYNAME,
"Table Name"}
,{MockDbUpdate.TABLE_NAME_PARM + ADKGLOBAL.RESOURCEBUNDLEKEY_DESCRIPTION,
"Select Table Name"}
,{MockDbUpdate.COLUMN_NAMES_PARM + ADKGLOBAL.RESOURCEBUNDLEKEY_DISPLAYNAME,
"Column Names"}
,{MockDbUpdate.COLUMN_NAMES_PARM + ADKGLOBAL.RESOURCEBUNDLEKEY_DESCRIPTION,
"Name of column updated by this service"}
,{MockDbUpdate.COLUMN_TYPES_PARM + ADKGLOBAL.RESOURCEBUNDLEKEY_DISPLAYNAME,
"Column Types"}
,{MockDbUpdate.COLUMN_TYPES_PARM + ADKGLOBAL.RESOURCEBUNDLEKEY_DESCRIPTION,
"Default data type for column"}
,{MockDbUpdate.OVERRIDE_TYPES_PARM + ADKGLOBAL.RESOURCEBUNDLEKEY_DISPLAYNAME,
"Override Data Types"}
,{MockDbUpdate.OVERRIDE_TYPES_PARM + ADKGLOBAL.RESOURCEBUNDLEKEY_DESCRIPTION,
"Type to override column default"}
,{MockDbUpdate.REPEATING_PARM + ADKGLOBAL.RESOURCEBUNDLEKEY_DISPLAYNAME,
"Update Multiple Rows?"}
,{MockDbUpdate.REPEATING_PARM + ADKGLOBAL.RESOURCEBUNDLEKEY_DESCRIPTION,
"Select if input will include multiple rows to update"}
//MockDB Signature Group Resource Domain Values
,{MockDbUpdate.SIG_SETTINGS_GRP + ADKGLOBAL.RESOURCEBUNDLEKEY_GROUP,
MockDbUpdate.SIG_SETTINGS_GRP}
,{MockDbUpdate.FIELD_NAMES_PARM + ADKGLOBAL.RESOURCEBUNDLEKEY_DISPLAYNAME,
"Field Names"}
,{MockDbUpdate.FIELD_NAMES_PARM + ADKGLOBAL.RESOURCEBUNDLEKEY_DESCRIPTION,
"Name of Field"}
,{MockDbUpdate.FIELD_TYPES_PARM + ADKGLOBAL.RESOURCEBUNDLEKEY_DISPLAYNAME,
"Field Type"}
,{MockDbUpdate.FIELD_TYPES_PARM + ADKGLOBAL.RESOURCEBUNDLEKEY_DESCRIPTION,
"Type of Field"}
,{MockDbUpdate.SIG_IN_PARM + ADKGLOBAL.RESOURCEBUNDLEKEY_DISPLAYNAME,
"Input Signature"}
,{MockDbUpdate.SIG_IN_PARM + ADKGLOBAL.RESOURCEBUNDLEKEY_DESCRIPTION,
"Input Signature"}
,{MockDbUpdate.SIG_OUT_PARM + ADKGLOBAL.RESOURCEBUNDLEKEY_DISPLAYNAME,
"Output Signature"}
,{MockDbUpdate.SIG_OUT_PARM + ADKGLOBAL.RESOURCEBUNDLEKEY_DESCRIPTION,
"Output Signature"}
};

protected Object[][] getContents() {
// TODO Auto-generated method stub
return _contents;
}

}