Adapter Development Kit 6.5 | 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 (as described in Resource Domains).
To implement this approach, you must update a string array (usually in the connection factory) containing the class name for each service or notification type added to an adapter. No additional changes are required for the connection factory or connection implementation. These service and notification classes must implement the ResourceDomainHandler interface, which enables the classes to manage their own resource domain functionality. A complete listing of the ResourceDomainHandler interface is provided below.
Note:
The ResourceDomainHandler interface is not delivered as part of the ADK.
Note:
An example of a notification that implements this interface is provided in Defining a WmAsyncListenerNotification Implementation Class.
package com.mycompany.adapter...;
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;
}
To use this model, you must have a list of services and notifications that implement the interface. Since the connection factory must already register its services, the connection factory is a logical place to create these lists. The lists are then passed to the connections that the connection factory creates. For example:
public class SimpleConnectionFactory extends WmManagedConnectionFactory
{
private static final String[] _supportedServiceTemplates = {
SimpleService.class.getName(),
TestService.class.getName(),
CopySLN.class.getName(),
Copy2SLN.class.getName()};
private static final String[] _supportedNotificationTemplates = {
SimpleNotification.class.getName(),
SessionLogListenerNotification.class.getName()};
// add metadata parameter support here
public WmManagedConnection createManagedConnectionObject(
javax.security.auth.Subject subject,
javax.resource.spi.ConnectionRequestInfo cxRequestInfo)
{
ArrayList templateList = new ArrayList(
Arrays.asList(_supportedServiceTemplates));
templateList.addAll(Arrays.asList(_supportedNotificationTemplates));
String [] listArg = new String[templateList.size()];
templateList.toArray(listArg);
return new SimpleConnection(...,listArg);
}
public void fillWmDescriptor(WmDescriptor d,Locale l) throws
AdapterException
{
...
}
public void fillResourceAdapterMetadataInfo(
ResourceAdapterMetadataInfo info,
Locale locale)
{
String[] templateList = _supportedServiceTemplates;
for (int i = 0; i < templateList.length;i++)
{
info.addServiceTemplate(templateList[i]);
}
}
}
The connection implementation then uses the service name it receives in the adapterResourceDomainLookup, and adapterCheckValue calls to forward those requests to the appropriate service or notification class:
public class SimpleConnection extends WmManagedConnection
{
private String[] _resourceHandlerList;
public SimpleConnection(...,String[] resourceHandlerList)
{
_resourceHandlerList = resourceHandlerList;
...
}
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 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);
}
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);
}
...
}