user manual

328 BES Developers Guide
Other Considerations
private javax.naming.Reference ref;
// ...
public javax.naming.Reference getReference()
{
// implement such that getReference() never returns null
// ...
return ref;
}
public javax.naming.Reference setReference( javax.naming.Reference ref )
// this.ref = ref;
}
//
Also, when dealing with a poorly behaving getReference(), there are various
ways to accomplish this, but principally, the idea is to implement getReference()
such that it never returns null. The best approach is to implement:
A fallback mechanism in getReference() which sets the reference to be
returned correctly if the connection factory's reference attribute is null -
returning a registerable javax.naming.Reference object, and
A helper class implementing javax.naming.spi.ObjectFactory to provide the
fallback objecfall back to create the connection factory object from the valid
Reference instance.
To illustrate, if the connection factory is com.shme.BadConnectionFactory, extend
the connection factory as com.shme.GoodConnectionFactory, and override
getReference() as follows:
package com.shme.shmeAdapter;
public class GoodConnectionFactory
{
// ...
public javax.naming.Reference getReference()
{
if ( ref == null )
{
ref = new javax.naming.Reference( this.getClass().getName(),
"com.shme.shmeAdapter.GoodCFObjectFactory"
/* object factory for GoodConnectionFactory references */,
null );
String value;
value = managedCxFactory.getClass().getName();
if ( value != null )
{
ref.add( new javax.naming.StringRefAddr(
"managedconnectionfactory-class", value ) );
}
value = cxManager.getClass().getName();