📄 videoclassclient.java
字号:
package com.singnet.video.client;
import java.util.ArrayList;
import java.util.Hashtable;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.rmi.PortableRemoteObject;
import com.singnet.util.Pager;
import com.singnet.video.VideoClassInfo;
import com.singnet.video.ejb.VideoClass;
import com.singnet.video.ejb.VideoClassHome;
public class VideoClassClient {
private VideoClass videoClass = null;
private VideoClassHome videoClassHome = null;
//Construct the EJB test client
public VideoClassClient() {
initialize();
videoClass=create();
}
public void initialize() {
try {
//get naming context
Context context = getInitialContext();
//look up jndi name
Object ref = context.lookup("VideoClass");
//look up jndi name and cast to Home interface
videoClassHome = (VideoClassHome) PortableRemoteObject.narrow(ref, VideoClassHome.class);
} 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 VideoClass create() {
try {
videoClass = videoClassHome.create();
} catch (Exception e) {
e.printStackTrace();
}
return videoClass;
}
//----------------------------------------------------------------------------
// Methods that use Remote interface methods to access data through the bean
//----------------------------------------------------------------------------
public boolean addVideoClassInfo(VideoClassInfo videoClassinfo) {
boolean returnValue = false;
if (videoClass == null) {
System.out.println("Error in addVideoClassInfo(): ");
return returnValue;
}
try {
returnValue = videoClass.addVideoClass(videoClassinfo);
} catch (Exception e) {
e.printStackTrace();
}
return returnValue;
}
public boolean editVideoClassInfo(VideoClassInfo videoClassinfo) {
boolean returnValue = false;
if (videoClass == null) {
System.out.println("Error in editVideoClassInfo(): ");
return returnValue;
}
try {
returnValue = videoClass.editVideoClass(videoClassinfo);
} catch (Exception e) {
e.printStackTrace();
}
return returnValue;
}
public boolean deleteVideoClassInfo(String id) {
boolean returnValue = false;
if (videoClass == null) {
System.out.println("Error in deleteVideoClassInfo(): " );
return returnValue;
}
try {
returnValue = videoClass.deleteVideoClass(id);
} catch (Exception e) {
e.printStackTrace();
}
return returnValue;
}
public ArrayList queryVideoClassInfo(Pager pager) {
ArrayList returnValue = null;
if (videoClass == null) {
System.out.println("Error in queryVideoClassInfo(): " );
return returnValue;
}
try {
returnValue = videoClass.queryVideoClass(pager);
} catch (Exception e) {
e.printStackTrace();
}
return returnValue;
}
public int getTotal(Pager pager) {
int returnValue = 0;
if (videoClass == null) {
System.out.println("Error in getTotal(): " );
return returnValue;
}
try {
returnValue = videoClass.getTotal(pager);
} catch (Exception e) {
e.printStackTrace();
}
return returnValue;
}
public VideoClassInfo getVideoClassById(String id) {
VideoClassInfo returnValue = null;
if (videoClass == null) {
System.out.println("Error in getVideoClassInfoByUid(): "
);
return returnValue;
}
try {
returnValue = videoClass.getVideoClassById(id);
} catch (Exception e) {
e.printStackTrace();
}
return returnValue;
}
public VideoClassInfo getVideoClassByClassname(String classname) {
VideoClassInfo returnValue = null;
if (videoClass == null) {
System.out.println("Error in getVideoClassInfoByUid(): "
);
return returnValue;
}
try {
returnValue = videoClass.getVideoClassByClassname(classname);
} catch (Exception e) {
e.printStackTrace();
}
return returnValue;
}
//Main method
public static void main(String[] args) {
VideoClassClient client = new VideoClassClient();
// Use the client object to call one of the Home interface wrappers
// above, to create a Remote interface reference to the bean.
// If the return value is of the Remote interface type, you can use it
// to access the remote interface methods. You can also just use the
// client object to call the Remote interface wrappers.
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -