Jon Rollins

Greenhorn
+ Follow
since Oct 30, 2002
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Jon Rollins

On the "Should I go to college" question - many companies won't give you a look if you don't have the sheep skin (mine included). I'm not saying agree, I'm just telling you what my experience has been.
On a personal note though - I know several developers without degrees and they are fine coders - with jobs.
19 years ago
Okay, here's the issue: We want a generic service to make EJB calls to our CICS-CTG business logic, governed by entries in an XML file for ease of config. A CTG session EJB requires an InputRecord, and produces an OutputRecord which are both generated (along with the command bean and home and remote interfaces) by VAJ.
Here's the code (we just figured this out, BTW):
Object outputRecord = null;

String home = "com.xyz.cics.ows522.Ows522Home";
String remote = "com.xyz.cics.ows522.Ows522";
String input = "com.xyz.cics.ows522.Ows522InputRecord";


// the output record to be returned.
Method remoteMethod = null;
Object remoteInterface = null;

// do we already have a reference for the ows522 EJB in the Hashtable??
remoteInterface = ejbReferences.get( this.OWS522 );

// if no existing reference, create one.
if ( remoteInterface == null )
{
// find the entry in the JNDI Registry for the Ows522 EJB Home Interface.
String ejbName = this.EJB_JNDI_ROOT + this.OWS522 + this.EJB_HOME_SUFFIX;
Object jndiHome = ctx.lookup( ejbName );

// get Home Interface for EJB.
Object ows525Home = javax.rmi.PortableRemoteObject.narrow(jndiHome, Class.forName( home ));

if ( ows525Home == null )
throw new Exception( this.getClass().getName() + ".execute() Error: Coulnd't create Home Interface for " + ejbName + "." );
// get Remote Interface for EJB to create local bean.
Class homeClass = Class.forName(home);
Method homeMethod = homeClass.getDeclaredMethod("create", null);


remoteInterface = homeMethod.invoke(ows525Home, null);


if ( remoteInterface == null )
throw new Exception( this.getClass().getName() + ".execute() Error: Coulnd't create Remote Interface for " + ejbName + "." );
// store Remote Interface reference in hashtable for reuse.
this.ejbReferences.put( this.OWS525, remoteInterface );
}

// call the execute method of the EJB, passing the input record casted to the correct object type.
Class remoteClass = Class. forName(remote);
remoteMethod = remoteClass.getDeclaredMethod("execute", new Class[] {Class.forName(input)} );
outputRecord = remoteMethod.invoke(remoteInterface, new Object[] {inputRecord} );

This allows us to create a super generic service that takes as parameters the qualifier for the CTG EJB to execute, and the InputRecord that is required for that EJB. Anyone have any better ideas??
Thanks,
Jon
19 years ago
I don't know if I'm even using the correct terminology, but here goes:
We have the need to dynamically cast (yes, I know that actually all casting is dynamic - I mean REALLY dynamic) some objects at runtime based on a String parameter passed into a method. Here goes:
public Object executeEJB(String objectType)
{
Object newObj = (objectType)Class.forName(objectType);
newObj.execute();
}
This is oversimplified, but it gets the point across (I hope). The new object that is created needs to be cast into the proper type in order to call the "execute" method. The problem seems to be at compile time, since the compiler can't resolve the object type represented by "objectType".
Any suggestions??
Thanks,
Jon
19 years ago