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

📄 musicsingerclient.java

📁 本程序是作者开发的一个宽带娱乐系统的一个模块.
💻 JAVA
字号:
package com.singnet.music.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.music.MusicSingerInfo;
import com.singnet.music.ejb.MusicSinger;
import com.singnet.music.ejb.MusicSingerHome;
import com.singnet.util.Pager;

public class MusicSingerClient {
     
	      private MusicSinger musicSinger = null;
	    private MusicSingerHome musicSingerHome = null;
	
	    //Construct the EJB test client
	    public MusicSingerClient() {
	        initialize();
	        musicSinger=this.create();
	    }
	
	    public void initialize() {
	       try {
	
	            //get naming context
	            Context context = getInitialContext();
	            //look up jndi name
	            Object ref = context.lookup("MusicSinger");
	            //look up jndi name and cast to Home interface
	            musicSingerHome = (MusicSingerHome) PortableRemoteObject.narrow(
	                    ref, MusicSingerHome.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 MusicSinger create() {
	               try {
	            musicSinger = musicSingerHome.create();
	        } catch (Exception e) {
	            e.printStackTrace();
	        }
	        return musicSinger;
	    }
	
	    //----------------------------------------------------------------------------
	    // Methods that use Remote interface methods to access data through the bean
	    //----------------------------------------------------------------------------
	
	    public boolean addMusicSingerInfo(MusicSingerInfo musicSingerInfo) {
	        boolean returnValue = false;
	        if (musicSinger == null) {
	            System.out.println("Error in addMusicSingerInfo(): " 
	                               );
	            return returnValue;
	        }
	               try {
	            returnValue = musicSinger.addMusicSingerInfo(musicSingerInfo);
	        } catch (Exception e) {
	            e.printStackTrace();
	        }
	        return returnValue;
	    }
	
	    public boolean editMusicSingerInfo(MusicSingerInfo musicSingerInfo) {
	        boolean returnValue = false;
	        if (musicSinger == null) {
	            System.out.println("Error in editMusicSingerInfo(): " 
	                               );
	            return returnValue;
	        }
	               try {
	            returnValue = musicSinger.editMusicSingerInfo(musicSingerInfo);
	        } catch (Exception e) {
	            
	            e.printStackTrace();
	        }
	        return returnValue;
	    }
	
	    public boolean deleteMusicSingerInfo(String id) {
	        boolean returnValue = false;
	        if (musicSinger == null) {
	            System.out.println("Error in deleteMusicSingerInfo(): " 
	                               );
	            return returnValue;
	        }
	               try {
	            returnValue = musicSinger.deleteMusicSingerInfo(id);
	        } catch (Exception e) {
	            e.printStackTrace();
	        }
	        return returnValue;
	    }
	
	    public MusicSingerInfo queryMusicSingerInfoById(String id) {
	        MusicSingerInfo returnValue = null;
	        if (musicSinger == null) {
	            System.out.println("Error in getMusicSingerInfoById(): " 
	                               );
	            return returnValue;
	        }
	               try {
	            returnValue = musicSinger.queryMusicSingerInfoById(id);
	        } catch (Exception e) {
	            e.printStackTrace();
	        }
	        return returnValue;
	    }
	    public MusicSingerInfo queryMusicSingerInfoByName(String name) {
	        MusicSingerInfo returnValue = null;
	        if (musicSinger == null) {
	            System.out.println("Error in getMusicSingerInfoById(): " 
	                               );
	            return returnValue;
	        }
	               try {
	            returnValue = musicSinger.queryMusicSingerInfoByName(name);
	        } catch (Exception e) {
	            e.printStackTrace();
	        }
	        return returnValue;
	    }
	    public ArrayList queryMusicSingerInfo( ) {
	        ArrayList returnValue = null;
	        if (musicSinger == null) {
	            System.out.println("Error in queryMusicSingerInfo(): " 
	                               );
	            return returnValue;
	        }
	       
	        try {
	            returnValue = musicSinger.queryMusicSingerInfo();
	        } catch (Exception e) {
	            e.printStackTrace();
	        }
	          return returnValue;
	    }
	
	     
	    //Main method
	    public static void main(String[] args) {
	        MusicSingerClient client = new MusicSingerClient();
	        // 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 + -