Example WmAdapter Implementation Class
Your WmAdapter implementation class must call the base class constructor (super()). The base class constructor calls several of the implementation class's "get" methods and instantiates your resource bundle (see
The Adapter Load Process). Because these activities occur in the base class constructor after the first call to getInstance, it is vital that they do not invoke another call to getInstance. Doing this results in an endlessly recursive call to the constructor, which will ultimately crash the JVM and bring down
Integration Server. In particular, pay attention to static initializers in your resource bundle. Because some of the resource bundles are keyed on the same string that is returned from WmAdapter.getAdapterName, do not populate that string in a static initializer, in a way similar to the following:
{MyAdapter.getInstance().getAdapterName() +
ADKGLOBAL.RESOURCEBUNDLEKEY_DISPLAYNAME, "My Adapter"}
This line of code in a static initializer of a resource bundle will produce the undesirable results described above.
The following example WmAdapter implementation class includes only the concepts discussed up to this point.
package com.mycompany.adapter.myadapter;
import com.wm.adk.WmAdapter;
import com.wm.adk.error.AdapterException;
import com.wm.adk.info.AdapterTypeInfo;
import com.wm.adk.log.ARTLogger;
import java.util.Locale;
public class MyAdapter extends WmAdapter
{
public static final String ADAPTER_NAME = MyAdapter.class.getName();
private static final int ADAPTER_MAJOR_CODE = 9001;
private static MyAdapter _instance = null;
private static ARTLogger _logger;
private MyAdapter() throws AdapterException {super();}
public String getAdapterName(){return ADAPTER_NAME;}
public String getAdapterVersion(){return "1.0";}
public String getAdapterJCASpecVersion(){return "1.0";}
public String getAdapterResourceBundleName()
{
return MyAdapterResourceBundle.class.getName();
}
public int getAdapterMajorCode(){return ADAPTER_MAJOR_CODE;}
public static ARTLogger getLogger() {return _logger;}
public static MyAdapter getInstance()
{
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;
}
}
}
}
public void initialize() throws AdapterException
{
_logger = new ARTLogger(getAdapterMajorCode(),
getAdapterName(),
getAdapterResourceBundleName());
getLogger().logDebug(9999,"My Adapter Initialized");
}
public void fillAdapterTypeInfo(AdapterTypeInfo info, Locale locale)
{
}
public void cleanup() {
if (_logger != null)
_logger.close();
}
}