⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 videoactorclient.java

📁 本程序是作者开发的一个宽带娱乐系统的一个模块.
💻 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.VideoActorInfo;
import com.singnet.video.ejb.VideoActor;
import com.singnet.video.ejb.VideoActorHome;

public class VideoActorClient {
    private VideoActor videoActor = null;
    private VideoActorHome videoActorHome = null;

    //Construct the EJB test client
    public VideoActorClient() {
        initialize();
        videoActor=create();
    }

    public void initialize() {
        try {

            //get naming context
            Context context = getInitialContext();
            //look up jndi name
            Object ref = context.lookup("VideoActor");
            //look up jndi name and cast to Home interface
            videoActorHome = (VideoActorHome) PortableRemoteObject.narrow(ref, VideoActorHome.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 VideoActor create() {
      
        try {
            videoActor = videoActorHome.create();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return videoActor;
    }

    //----------------------------------------------------------------------------
    // Methods that use Remote interface methods to access data through the bean
    //----------------------------------------------------------------------------


    public boolean addVideoActorInfo(VideoActorInfo videoActorinfo) {
        boolean returnValue = false;
        if (videoActor == null) {
            System.out.println("Error in addVideoActorInfo(): ");
            return returnValue;
        }
        

        try {
            returnValue = videoActor.addVideoActor(videoActorinfo);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return returnValue;
    }

    public boolean editVideoActorInfo(VideoActorInfo videoActorinfo) {
        boolean returnValue = false;
        if (videoActor == null) {
            System.out.println("Error in editVideoActorInfo(): ");
            return returnValue;
        }
      
        try {
            returnValue = videoActor.editVideoActor(videoActorinfo);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return returnValue;
    }

    public boolean deleteVideoActorInfo(String id) {
        boolean returnValue = false;
        if (videoActor == null) {
            System.out.println("Error in deleteVideoActorInfo(): " );
            return returnValue;
        }
       
        try {
            returnValue = videoActor.deleteVideoActor(id);
        } catch (Exception e) {
            e.printStackTrace();
        
        }
        return returnValue;
    }

    public ArrayList queryVideoActorInfo(Pager pager) {
        ArrayList returnValue = null;
        if (videoActor == null) {
            System.out.println("Error in queryVideoActorInfo(): " );
            return returnValue;
        }
       
        try {
            returnValue = videoActor.queryVideoActor(pager);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return returnValue;
    }

    public int getTotal(Pager pager) {
        int returnValue = 0;
        if (videoActor == null) {
            System.out.println("Error in getTotal(): " );
            return returnValue;
        }
        try {
            returnValue = videoActor.getTotal(pager);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return returnValue;
    }

    public VideoActorInfo getVideoActorById(String id) {
        VideoActorInfo returnValue = null;
        if (videoActor == null) {
            System.out.println("Error in getVideoActorInfoByUid(): " 
                               );
            return returnValue;
        }
        try {
            returnValue = videoActor.getVideoActorById(id);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return returnValue;
    }

    public VideoActorInfo getVideoActorByName(String name) {
        VideoActorInfo returnValue = null;
        if (videoActor == null) {
            System.out.println("Error in getVideoActorInfoByUid(): " 
                               );
            return returnValue;
        }
        try {
            returnValue = videoActor.getVideoActorByName(name);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return returnValue;
    }

    //Main method
    public static void main(String[] args) {
    	VideoActorClient client = new VideoActorClient();
        // 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 + -