Example WmManagedConnectionFactory Implementation Class
The example connection factory, SimpleConnectionFactory, supports some simple metadata parameters. Note the following:
Two constant strings represent the names of the metadata parameters for the connection factory. These strings must correspond to the names of the "set" accessor methods in this class. Using string constants is not required, but they make the code more manageable because metadata methods and the resource bundle often contain multiple references to the parameter name.
Each parameter name has a "set" method and an attribute to hold the value passed to the "set" method. This implementation does not provide "get" methods because there are no default values for parameters (and this adapter has no other use for the "get" methods).
The createManagedConnectionObject method simply instantiates the connection class, passing the parameter values in the connection constructor.
The fillWmDescriptor method uses the createGroup method to determine the order in which the parameters will appear on the display. The last line of fillWmDescriptor causes the server to retrieve display text for the connection from the example resource bundle. (To see the updated resource bundle, see
Updating the Resource Bundle.)
The final method in the example, fillResourceAdapterMetadataInfo, indicates which services are supported by the connection.
package com.mycompany.adapter.myadapter.connections;
import com.mycompany.ad apter.myadapter.*;
import com.wm.adk.connection.*;
import com.wm.adk.info.ResourceAdapterMetadataInfo;
import com.wm.adk.metadata.WmDescriptor;
import com.wm.adk.erro r . AdapterException;
import java.util.Locale;
public class Si mp le ConnectionFactory extends Wm Man agedConnectionFactory
{
public static final String CONFIG_PARM1_PARAMETER = "configParm1";
public static final String CONFIG_PARM2_PARAMETER = "configParm2";
private String _configParm1;
private int _configParm2;
public void setConfigParm1(String val){_configParm1 = val;}
public void setConfigParm2(int val){_configParm2 = val;}
public SimpleConnectionFactory(){super();}
public WmManagedConnection
createManagedConnectionObject(javax.security.auth.Subject subject,
javax.resource.spi.ConnectionRequestInfo cxRequestInfo)
{
return new SimpleConnection(_configParm1, _configParm2);
}
public void fillWmDescriptor(WmDescriptor d,Locale l) throws
AdapterException
{
d.createGroup("nameNotUsedForConnections",
new String[]{CONFIG_PARM2_PARAMETER,
CONFIG_PARM1_PARAMETER});
d.setValidValues(CONFIG_PARM2_PARAMETER, new String[] {"1","2","4"});
d.setRequired(CONFIG_PARM1_PARAMETER);
d.setDescriptions(
MyAdapter.getInstance().getAdapterResourceBundleManager(),l);
}
public void fillResourceAdapterMetadataInfo(ResourceAdapterMetadataInfo
info,
Locale locale)
{
}
}