Adapter Development Kit 9.12 | webMethods Adapter Development Kit Documentation | webMethods Adapter Development Kit Installation and User’s Documentation | The Adapter Definition | Creating a WmAdapter Implementation Class | Creating WmAdapter Implementation Class with example
 
Creating WmAdapter Implementation Class with example
1. Create a folder structure for the Java package for adapter implementation. For example: com\mycompany\adapter\myadapter. In the example, the Java package created is com\wm\MyAdapter.
Note:
You must create your Java package and classes in the adapterPackageName\code\source folder in the webMethods package you created using Designer.
2. Create an interface that contains the constants for the adapter implementation.
In the example, create MyAdapterConstants interface:

package com.wm.MyAdapter;

public interface MyAdapterConstants {

static final int ADAPTER_MAJOR_CODE = 9001;
static final String ADAPTER_JCA_VERSION = "1.0";
static final String ADAPTER_NAME = "MyAdapter";
static final String ADAPTER_VERSION = "9.12";

//Using next statement creates cyclic class loading dependency issue
//therefore, the resource bundle class name is fully spelled out
//static final String ADAPTER_SOURCE_BUNDLE_NAME = MyAdapterResource.class.getName();
static final String ADAPTER_SOURCE_BUNDLE_NAME =
"com.wm.MyAdapter.MyAdapterResource";
}
3. Create a class by extending the com.wm.adk.WmAdapter base class.
*Your WmAdapter implementation class (MyAdapter) must call the base class constructor (super()). The base class constructor calls several of the implementation class's methods and instantiates your resource bundle.
*The base class constructor calls several of the implementation class's methods after the first call to getInstance. It is vital that they do not invoke another call to getInstance which results in an endlessly recursive call to the constructor, and ultimately crashes the JVM and bring down Integration Server. This must be avoided in static initializers in your resource bundle as some of the resource bundles are keyed on the same string that is returned from MyAdapter.getAdapterName. Do not populate the string in a static initializer. This line of code in a static initializer of a resource bundle produces an undesirable results:
{MyAdapter.getInstance().getAdapterName() +
ADKGLOBAL.RESOURCEBUNDLEKEY_DISPLAYNAME, "My Adapter"}
*When specifying any resource, you must use the fully qualified name of the resource's associated implementation class (rather than an object instance).
In the example, create MyAdapter class:

package com.wm.MyAdapter;

import java.util.Locale;

import com.wm.adk.WmAdapter;
import com.wm.adk.error.AdapterException;
import com.wm.adk.info.AdapterTypeInfo;
import com.wm.adk.log.ARTLogger;

public class MyAdapter extends WmAdapter implements MyAdapterConstants{

public static MyAdapter _instance = null;
public static ARTLogger _logger = null;

public MyAdapter() throws AdapterException { super(); }

public void fillAdapterTypeInfo(AdapterTypeInfo arg0, Locale arg1) {}
public String getAdapterJCASpecVersion() { return ADAPTER_JCA_VERSION; }
public int getAdapterMajorCode() { return ADAPTER_MAJOR_CODE; }
public String getAdapterName() { return ADAPTER_NAME; }
public String getAdapterResourceBundleName() { return ADAPTER_SOURCE_BUNDLE_NAME; }
public String getAdapterVersion() { return ADAPTER_VERSION; }
public static ARTLogger getLogger() { return _logger; }

public void initialize() throws AdapterException {
// TODO Auto-generated method stub
_logger = new ARTLogger(getAdapterMajorCode(),
getAdapterName(),
getAdapterResourceBundleName());
_logger.logDebug(9999,"My Adapter Initialized");
}

public void cleanup() {
if (_logger != null)
_logger.close();
}

public static MyAdapter getInstance() {
// TODO Auto-generated method stub
if (_instance != null)
return _instance;
else {
synchronized (MyAdapter.class) {
if (_instance != null) {
return _instance;
}
try {
_instance = new MyAdapter();
return _instance;
} catch (Throwable t) {
t.printStackTrace();
return null;
}
}
}
}
}