📄 videoclient.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.VideoInfo;
import com.singnet.video.ejb.Video;
import com.singnet.video.ejb.VideoHome;
import com.singnet.video.ejb.VideoHome;
public class VideoClient {
private Video video = null;
private VideoHome videoHome = null;
//Construct the EJB test client
public VideoClient() {
initialize();
video=create();
}
public void initialize() {
try {
//get naming context
Context context = getInitialContext();
//look up jndi name
Object ref = context.lookup("Video");
//look up jndi name and cast to Home interface
videoHome = (VideoHome) PortableRemoteObject.narrow(ref, VideoHome.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 Video create() {
try {
video = videoHome.create();
} catch (Exception e) {
e.printStackTrace();
}
return video;
}
//----------------------------------------------------------------------------
// Methods that use Remote interface methods to access data through the bean
//----------------------------------------------------------------------------
public boolean addVideoInfo(VideoInfo videoinfo) {
boolean returnValue = false;
if (video == null) {
System.out.println("Error in addVideoInfo(): ");
return returnValue;
}
try {
returnValue = video.addVideo(videoinfo);
} catch (Exception e) {
e.printStackTrace();
}
return returnValue;
}
public boolean editVideoInfo(VideoInfo videoinfo) {
boolean returnValue = false;
if (video == null) {
System.out.println("Error in editVideoInfo(): ");
return returnValue;
}
try {
returnValue = video.editVideo(videoinfo);
} catch (Exception e) {
e.printStackTrace();
}
return returnValue;
}
public boolean deleteVideoInfo(String id) {
boolean returnValue = false;
if (video == null) {
System.out.println("Error in deleteVideoInfo(): " );
return returnValue;
}
try {
returnValue = video.deleteVideo(id);
} catch (Exception e) {
e.printStackTrace();
}
return returnValue;
}
public ArrayList queryVideoInfo(Pager pager) {
ArrayList returnValue = null;
if (video == null) {
System.out.println("Error in queryVideoInfo(): " );
return returnValue;
}
try {
returnValue = video.queryVideo(pager);
} catch (Exception e) {
e.printStackTrace();
}
return returnValue;
}
public int getTotal(Pager pager) {
int returnValue = 0;
if (video == null) {
System.out.println("Error in getTotal(): " );
return returnValue;
}
try {
returnValue = video.getTotal(pager);
} catch (Exception e) {
e.printStackTrace();
}
return returnValue;
}
public VideoInfo getVideoById(String id) {
VideoInfo returnValue = null;
if (video == null) {
System.out.println("Error in getVideoInfoByUid(): "
);
return returnValue;
}
try {
returnValue = video.getVideoById(id);
} catch (Exception e) {
e.printStackTrace();
}
return returnValue;
}
//Main method
public static void main(String[] args) {
VideoClient client = new VideoClient();
// 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 + -