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

📄 client.java

📁 J2EE的一个开发实例
💻 JAVA
字号:
package music.client; 

import java.util.*;
import javax.naming.*;
import javax.rmi.*;

import music.ejb.*;
import music.ejb.db.*;
import music.shared.*;

public class Client  {

    void initData() throws Exception {
        MusicManageRemote manage = getMusicManageRemote();
        // create some categories:
        int chs_id = manage.newCategory(0, "Chinese");
        int eng_id = manage.newCategory(0, "English");
        int female_id = manage.newCategory(eng_id, "Female");
        manage.newCategory(eng_id, "Male");
        manage.newCategory(eng_id, "Other");
        // create some artists:
        int dido_id = manage.newArtist(female_id, new ArtistVO(0, "Dido", Boolean.TRUE, null));
    }

    void testGetCategories(int parentCategoryId) throws Exception {
        MusicViewRemote view = getMusicViewRemote();
        Collection c = view.getCategories(parentCategoryId);
        Iterator it = c.iterator();
        while(it.hasNext())
            System.out.print(it.next().toString());
    }

    public static void main(String[] args) throws Exception {
        Client client = new Client();
        //client.initData();
        //client.testGetCategories(0);
        Collection c = client.getMusicViewRemote().searchSongs("white");
        Iterator it = c.iterator();
        while(it.hasNext())
            System.out.println(it.next().toString());
    }

    MusicViewRemote getMusicViewRemote() throws Exception {
        Hashtable ht = new Hashtable();
        ht.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
        ht.put(Context.PROVIDER_URL, "t3://localhost:7001");
        Context ctx = new InitialContext(ht);
        Object obj = ctx.lookup("ejb/MusicView");
        MusicViewRemoteHome home = (MusicViewRemoteHome)PortableRemoteObject.narrow(obj, MusicViewRemoteHome.class);
        return home.create();
    }

    MusicManageRemote getMusicManageRemote() throws Exception {
        Hashtable ht = new Hashtable();
        ht.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
        ht.put(Context.PROVIDER_URL, "t3://localhost:7001");
        Context ctx = new InitialContext(ht);
        Object obj = ctx.lookup("ejb/MusicManage");
        MusicManageRemoteHome home = (MusicManageRemoteHome)PortableRemoteObject.narrow(obj, MusicManageRemoteHome.class);
        return home.create();
    }

} 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -