12.11.2014 Views

web server - Borland Technical Publications

web server - Borland Technical Publications

web server - Borland Technical Publications

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Other Considerations<br />

To illustrate, if the connection factory is com.shme.BadConnectionFactory, extend the<br />

connection factory as com.shme.GoodConnectionFactory, and implement Referenceable as<br />

follows:<br />

package com.shme.shmeAdapter;<br />

public class GoodConnectionFactory<br />

{<br />

private javax.naming.Reference ref;<br />

// ...<br />

public javax.naming.Reference getReference()<br />

{<br />

// implement such that getReference() never returns null<br />

// ...<br />

return ref;<br />

}<br />

public javax.naming.Reference setReference( javax.naming.Reference ref )<br />

// this.ref = ref;<br />

}<br />

//<br />

Also, when dealing with a poorly behaving getReference(), there are various ways to<br />

accomplish this, but principally, the idea is to implement getReference() such that it<br />

never returns null. The best approach is to implement:<br />

■<br />

A fallback mechanism in getReference() which sets the reference to be returned<br />

correctly if the connection factory's reference attribute is null - returning a<br />

registrable javax.naming.Reference object, and<br />

■<br />

A helper class implementing javax.naming.spi.ObjectFactory to provide the fallback<br />

object to create the connection factory object from the valid Reference instance.<br />

To illustrate, if the connection factory is com.shme.BadConnectionFactory, extend the<br />

connection factory as com.shme.GoodConnectionFactory, and override getReference() as<br />

follows:<br />

package com.shme.shmeAdapter;<br />

public class GoodConnectionFactory<br />

{<br />

// ...<br />

public javax.naming.Reference getReference()<br />

{<br />

if ( ref == null )<br />

{<br />

ref = new javax.naming.Reference( this.getClass().getName(),<br />

"com.shme.shmeAdapter.GoodCFObjectFactory"<br />

/* object factory for GoodConnectionFactory references */,<br />

null );<br />

String value;<br />

value = managedCxFactory.getClass().getName();<br />

if ( value != null )<br />

{<br />

ref.add( new javax.naming.StringRefAddr(<br />

"managedconnectionfactory-class", value ) );<br />

}<br />

value = cxManager.getClass().getName();<br />

if ( value != null )<br />

{<br />

280 BES Developer’s Guide

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!