/*
* edit by shyang
* 该文件演示将自己写的程序,在Shell里面单独执行时,将打印信息输出到method server中
* 这对于输出日志很有用,不然只能自己单独写日志
* 
*/
package ext;

import wt.method.RemoteMethodServer;
import java.io.IOException;
import java.io.Serializable;


public class Loginms implements wt.method.RemoteAccess, Serializable{

    public static void main(String args[]){
/*
*调用invoke方法时,如果不是调用的是非静态类,this是不可以用的,
*所以请先声明一个示例,然后在普通方法doSomething中调用
*/
    	Loginms loginms= new Loginms();
    	loginms.doSomething("Test if can send message to MS");
    	System.exit(0);
    }
    
    public void doSomething(String arg){
    		Class argTypes[] = {String.class};
    		Object argsValues[] = {arg};
    		try{
/*
* invoke请参考API,里面有详细描述
*/    		
    		RemoteMethodServer remotemethodserver = RemoteMethodServer.getDefault();
    		remotemethodserver.setUserName("wcadmin");
    		remotemethodserver.setPassword("windchill");
    		//静态方法
    		remotemethodserver.invoke("doStaticMethod", "ext.Loginms", null, argTypes, argsValues);
    		//非静态方法
    		remotemethodserver.invoke("doCommonMethod", null, this, argTypes, argsValues);
    	}
    	catch (java.rmi.RemoteException re) {
    		System.out.println(">>>>>>There is somthing wrong!");
    		re.printStackTrace();
    	} 
    	catch (java.lang.reflect.InvocationTargetException ite) {
    		System.out.println(">>>>>>There is somthing wrong!");
    		ite.printStackTrace();
    	}

}
//调用的方法,返回值必须是Boolean型的,其他类型不可以执行
//自己其他的方法,都可以从这里调用
public static Boolean doStaticMethod(String oo){
	System.out.println(">>>>>>>>>>Success in Static Method!>>>> " + oo);
	return new Boolean(true);
}
public Boolean doCommonMethod(String oo){
	System.out.println(">>>>>>>>>>Success in Common Method!>>>> " + oo);
	return new Boolean(true);
}
}
posted on 2009-08-14 11:18  重金属  阅读(741)  评论(0编辑  收藏  举报