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

📄 musiccommendclient.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.MusicCommendInfo;
import com.singnet.music.ejb.MusicCommend;
import com.singnet.music.ejb.MusicCommendHome;
import com.singnet.util.Pager;

public class MusicCommendClient {
     
	      private MusicCommend musicCommend = null;
	    private MusicCommendHome musicCommendHome = null;
	
	    //Construct the EJB test client
	    public MusicCommendClient() {
	        initialize();
	        musicCommend=this.create();
	    }
	
	    public void initialize() {
	       try {
	
	            //get naming context
	            Context context = getInitialContext();
	            //look up jndi name
	            Object ref = context.lookup("MusicCommend");
	            //look up jndi name and cast to Home interface
	            musicCommendHome = (MusicCommendHome) PortableRemoteObject.narrow(
	                    ref, MusicCommendHome.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 MusicCommend create() {
	               try {
	            musicCommend = musicCommendHome.create();
	        } catch (Exception e) {
	            e.printStackTrace();
	        }
	        return musicCommend;
	    }
	
	    //----------------------------------------------------------------------------
	    // Methods that use Remote interface methods to access data through the bean
	    //----------------------------------------------------------------------------
	
	    public boolean addMusicCommendInfo(MusicCommendInfo musicCommendInfo) {
	        boolean returnValue = false;
	        if (musicCommend == null) {
	            System.out.println("Error in addMusicCommendInfo(): " 
	                               );
	            return returnValue;
	        }
	               try {
	            returnValue = musicCommend.addMusicCommendInfo(musicCommendInfo);
	        } catch (Exception e) {
	            e.printStackTrace();
	        }
	        return returnValue;
	    }
	
	    public boolean editMusicCommendInfo(MusicCommendInfo musicCommendInfo) {
	        boolean returnValue = false;
	        if (musicCommend == null) {
	            System.out.println("Error in editMusicCommendInfo(): " 
	                               );
	            return returnValue;
	        }
	               try {
	            returnValue = musicCommend.editMusicCommendInfo(musicCommendInfo);
	        } catch (Exception e) {
	            
	            e.printStackTrace();
	        }
	        return returnValue;
	    }
	
	    public boolean deleteMusicCommendInfo(String id) {
	        boolean returnValue = false;
	        if (musicCommend == null) {
	            System.out.println("Error in deleteMusicCommendInfo(): " 
	                               );
	            return returnValue;
	        }
	               try {
	            returnValue = musicCommend.deleteMusicCommendInfo(id);
	        } catch (Exception e) {
	            e.printStackTrace();
	        }
	        return returnValue;
	    }
	
	    public MusicCommendInfo queryMusicCommendInfoById(String id) {
	        MusicCommendInfo returnValue = null;
	        if (musicCommend == null) {
	            System.out.println("Error in getMusicCommendInfoById(): " 
	                               );
	            return returnValue;
	        }
	               try {
	            returnValue = musicCommend.queryMusicCommendInfoById(id);
	        } catch (Exception e) {
	            e.printStackTrace();
	        }
	        return returnValue;
	    }
	
	    public ArrayList queryMusicCommendInfo(Pager pager) {
	        ArrayList returnValue = null;
	        if (musicCommend == null) {
	            System.out.println("Error in queryMusicCommendInfo(): " 
	                               );
	            return returnValue;
	        }
	       
	        try {
	            returnValue = musicCommend.queryMusicCommendInfo(pager);
	        } catch (Exception e) {
	            e.printStackTrace();
	        }
	          return returnValue;
	    }
	
	     
	    //Main method
	    public static void main(String[] args) {
	        MusicCommendClient client = new MusicCommendClient();
	        // 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 + -