Adapter Development Kit 9.12 | webMethods Adapter Development Kit Documentation | webMethods Adapter Development Kit Installation and User’s Documentation | Listener Notifications | Listener Notification Implementation | Example Listener Notification Class
 
Example Listener Notification Class
package com.wm.MyAdapter.listeners;

import com.wm.adk.error.AdapterException;
import com.wm.adk.metadata.WmDescriptor;
import com.wm.adk.notification.WmAsyncListenerNotification;
import com.wm.adk.notification.NotificationResults;
import com.wm.adk.notification.AsyncNotificationResults;
import com.wm.adk.notification.NotificationEvent;
import com.wm.adk.connection.WmManagedConnection;
import com.wm.adk.metadata.*;
import com.wm.adk.cci.record.WmRecord;
import com.wm.adk.cci.record.WmRecordFactory;

import javax.resource.ResourceException;
import java.util.Locale;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.StringTokenizer;

import com.wm.MyAdapter.MyAdapter;
import com.wm.MyAdapter.MyAdapterConstants;
import com.wm.MyAdapter.connections.SimpleConnection;
public class SessionLogListenerNotification extends WmAsyncListenerNotification
implements MyAdapterConstants
{

private String[] _fieldNames = null;
private String[] _fieldTypes = null;
private boolean[] _uses = null;

public void setFieldNames(String[] val){_fieldNames = val;}
public void setFieldTypes(String[] val){_fieldTypes = val;}
public void setUses (boolean[] val){_uses = val;}
public void setSignature(String[] val){}

public static final String NOTIFICATION_SETUP_GROUP =
"SessionLogListenerNotification.setup";

public static final String FIELD_NAMES_PARM = "fieldNames";
public static final String FIELD_TYPES_PARM = "fieldTypes";
public static final String USES_PARM = "uses";
public static final String SIG_PARM = "signature";

public static final String FIELD_NAMES_RD =
"SessionLogListenerNotification.fieldNames.rd";
public static final String FIELD_TYPES_RD =
"SessionLogListenerNotification.fieldTypes.rd";

public static final String[] _sigFieldNames = {
"timeStamp",
"component",
"rootContext",
"parentContext",
"currentContext",
"server",
"eventCode",
"user",
"sessionName",
"RPCs",
"age"};
private Object[] _parsedValues = new Object[_sigFieldNames.length];
public void fillWmTemplateDescriptor(WmTemplateDescriptor descriptor,Locale l)
throws ResourceException
{
String[] parms = new String[] {FIELD_NAMES_PARM,
FIELD_TYPES_PARM,
USES_PARM,
SIG_PARM};
descriptor.createGroup(NOTIFICATION_SETUP_GROUP, parms);
descriptor.createFieldMap(parms, false);
descriptor.createTuple(new String[]{FIELD_NAMES_PARM, FIELD_TYPES_PARM});

descriptor.setResourceDomain(FIELD_NAMES_PARM, FIELD_NAMES_RD, null);
descriptor.setResourceDomain(FIELD_TYPES_PARM, FIELD_TYPES_RD, null);
descriptor.setResourceDomain(SIG_PARM,
WmTemplateDescriptor.OUTPUT_FIELD_NAMES,new String[]{
FIELD_NAMES_PARM,FIELD_TYPES_PARM}, USES_PARM);

descriptor.setDescriptions( MyAdapter.getInstance().
getAdapterResourceBundleManager(), l);
}

public Boolean adapterCheckValue(WmManagedConnection connection,
String resourceDomainName, String[][] values,
String testValue) throws AdapterException
{
return true;
}
public ResourceDomainValues[] adapterResourceDomainLookup(
WmManagedConnection connection, String resourceDomainName,
String[][] values) throws AdapterException
{
ResourceDomainValues[] results = null;
if (resourceDomainName.equals(FIELD_NAMES_RD)
|| resourceDomainName.equals(FIELD_TYPES_RD))
{
ResourceDomainValues names = new ResourceDomainValues(
FIELD_NAMES_RD, _sigFieldNames);
ResourceDomainValues types = new ResourceDomainValues(
FIELD_TYPES_RD,new String[] {
Date.class.getName(), //timestamp
String.class.getName(), // component
String.class.getName(), // rootContext
String.class.getName(), // parentContext
String.class.getName(), // currentContext
String.class.getName(), // server
Integer.class.getName(), // eventCode
String.class.getName(), // user
String.class.getName(), // sessionName
Integer.class.getName(), // RPCs
Long.class.getName() // age
});
results = new ResourceDomainValues[] {names,types};
}
return results;
}
public void registerResourceDomain(WmManagedConnection connection,
WmAdapterAccess access) throws AdapterException
{
access.addResourceDomainLookup(this.getClass().getName(),
FIELD_NAMES_RD, connection);
access.addResourceDomainLookup(this.getClass().getName(),
FIELD_TYPES_RD, connection);
}

public boolean supports(Object data) throws ResourceException
{
boolean result = false;
try
{
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd H:mm:ss zzz");
String sData = (String)data;
this._parsedValues[0] = sdf.parse(sData.substring(0,48));
StringTokenizer st = new StringTokenizer(sData.substring(49)," ",false);
this._parsedValues[1] = st.nextToken();
this._parsedValues[2] = st.nextToken();
this._parsedValues[3] = st.nextToken();
this._parsedValues[4] = st.nextToken();
/*
st.nextToken(); // skip the session ID
this._parsedValues[5] = st.nextToken();
this._parsedValues[6] = new Integer(st.nextToken());
this._parsedValues[7] = st.nextToken();
this._parsedValues[8] = st.nextToken();
this._parsedValues[9] = new Integer(st.nextToken());
this._parsedValues[10] = new Long(st.nextToken());
*/
result = true;
}
catch(Throwable t){}
return result;
}

public NotificationResults runNotification(NotificationEvent event)
throws ResourceException
{
NotificationResults result = null;
WmRecord notice = WmRecordFactory.getFactory().createWmRecord("notUsed");
for(int i = 0; i< _sigFieldNames.length;i++)
{
if (_uses[i])
{
notice.put(_sigFieldNames[i],_parsedValues[i]);
}
}
this.doNotify(notice);
result = new AsyncNotificationResults(this.nodeName(),true,null);
return result;

}
}