【Java开源代码栏目提醒】:网学会员,鉴于大家对Java开源代码十分关注,论文会员在此为大家搜集整理了“CmpFinderClientBeanTestClient1.java”一文,供大家参考学习!
package cmpfinder;
import javax.naming.*;
import javax.rmi.PortableRemoteObject;
import java.lang.String;
import javax.naming.InitialContext;
import java.util.Hashtable;
public class CmpFinderClientBeanTestClient1 {
private static final String ERROR_NULL_REMOTE = "Remote interface reference is null. It must be created by calling one of the Home interface methods first.";
private CmpFinderClient cmpFinderClient = null;
private CmpFinderClientHome cmpFinderClientHome = null;
//Construct the EJB test client
public CmpFinderClientBeanTestClient1() {
initialize();
}
public void initialize() {
try {
//get naming context
Context context = getInitialContext();
//look up jndi name
Object ref = context.lookup("CmpFinderClientBean");
//look up jndi name and cast to Home interface
cmpFinderClientHome = (CmpFinderClientHome) PortableRemoteObject.
narrow(ref, CmpFinderClientHome.class);
cmpFinderClient=create();
getChildrenOfFamily("Family02");
} catch (Exception e) {
e.printStackTrace();
}
}
private Context getInitialContext() throws NamingException {
Hashtable environment = new Hashtable();
environment.put(Context.INITIAL_CONTEXT_FACTORY,
"org.jnp.interfaces.NamingContextFactory");
environment.put(Context.URL_PKG_PREFIXES,
"org.jboss.naming:org.jnp.interfaces");
environment.put(Context.PROVIDER_URL, "jnp://localhost:1099");
return new InitialContext(environment);
}
//----------------------------------------------------------------------------
// Methods that use Home interface methods to generate a Remote interface reference
//----------------------------------------------------------------------------
public CmpFinderClient create() {
try {
cmpFinderClient = cmpFinderClientHome.create();
} catch (Exception e) {
e.printStackTrace();
}
return cmpFinderClient;
}
//----------------------------------------------------------------------------
// Methods that use Remote interface methods to access data through the bean
//----------------------------------------------------------------------------
public void getChildrenOfFamily(String familyID) {
if (cmpFinderClient == null) {
System.out.println("Error in getChildrenOfFamily(): " +
ERROR_NULL_REMOTE);
return;
}
try {
cmpFinderClient.getChildrenOfFamily(familyID);
} catch (Exception e) {
e.printStackTrace();
}
}
//----------------------------------------------------------------------------
// Utility Methods
//----------------------------------------------------------------------------
public CmpFinderClientHome getHome() {
return cmpFinderClientHome;
}
//Main method
public static void main(String[] args) {
CmpFinderClientBeanTestClient1 client = new
CmpFinderClientBeanTestClient1();
// Use the getHome() method of the client object to call Home interface
// methods that will return a Remote interface reference. Then
// use that Remote interface reference to access the EJB.
}
}