【Java开源代码栏目提醒】:网学会员--在 Java开源代码编辑为广大网友搜集整理了:CmpOneManyClientBeanTestClient1.java绩等信息,祝愿广大网友取得需要的信息,参考学习。
package cmponemany;
import javax.naming.*;
import javax.rmi.PortableRemoteObject;
import java.lang.String;
import javax.naming.InitialContext;
import java.util.Hashtable;
public class CmpOneManyClientBeanTestClient1 {
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 CmpOneManyClient cmpOneManyClient = null;
private CmpOneManyClientHome cmpOneManyClientHome = null;
//Construct the EJB test client
public CmpOneManyClientBeanTestClient1() {
initialize();
}
public void initialize() {
try {
//get naming context
Context context = getInitialContext();
//look up jndi name
Object ref = context.lookup("CmpOneManyClientBean");
//look up jndi name and cast to Home interface
cmpOneManyClientHome = (CmpOneManyClientHome) PortableRemoteObject.
narrow(ref, CmpOneManyClientHome.class);
cmpOneManyClient=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 CmpOneManyClient create() {
try {
cmpOneManyClient = cmpOneManyClientHome.create();
} catch (Exception e) {
e.printStackTrace();
}
return cmpOneManyClient;
}
//----------------------------------------------------------------------------
// Methods that use Remote interface methods to access data through the bean
//----------------------------------------------------------------------------
public void getChildrenOfFamily(String familyID) {
if (cmpOneManyClient == null) {
System.out.println("Error in getChildrenOfFamily(): " +
ERROR_NULL_REMOTE);
return;
}
try {
cmpOneManyClient.getChildrenOfFamily(familyID);
} catch (Exception e) {
e.printStackTrace();
}
}
//----------------------------------------------------------------------------
// Utility Methods
//----------------------------------------------------------------------------
public CmpOneManyClientHome getHome() {
return cmpOneManyClientHome;
}
//Main method
public static void main(String[] args) {
CmpOneManyClientBeanTestClient1 client = new
CmpOneManyClientBeanTestClient1();
// 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.
}
}
上一篇:
CmpOneManyClientBean.java
下一篇:
9月大一新生自我介绍