📄 zipcodeserverimpl_skel.java
字号:
import java.lang.reflect.*;
public class ZipCodeServerImpl_skel {
/** Creates a new instance of ZipCodeServerImpl_skel */
public ZipCodeServerImpl_skel() {
}
// This method unmarshalls the method args and calls the actual initialise
// method in the local object
public String initialise(String s, Object localObjRef)
{ String[] arr = s.split(",");
ZipCodeList prev = new ZipCodeList(arr[6], arr[7], null);
ZipCodeList start = prev;
// Unmarshall Method Args
for(int i = 8; i < arr.length; i+=2){
ZipCodeList n = new ZipCodeList(arr[i], arr[i+1], null);
prev.next = n;
prev = n;
}
try{
Class c = localObjRef.getClass();
Class[] paramTypes = {start.getClass()};
Method m = c.getMethod("initialise", paramTypes);
Object[] args = {start};
m.invoke(localObjRef, args);
}catch(Exception e){}
//Marshall reply and return to yourRMI
return "It worked";
}
// This method unmarshalls the method args and calls the actual find
// method in the local object
public String find(String args, Object localObjRef)
{ //Unmarshall args
String reply = "";
try{
// Search the list.
Class c = localObjRef.getClass();
Class[] paramTypes = {args.getClass()};
Method m = c.getMethod("find", paramTypes);
Object[] o = {args};
reply = (String)m.invoke(localObjRef, o);
}catch(Exception e){}
//Marshall reply and return to yourRMI
return reply;
}
// This method unmarshalls the method args and calls the actual findAll
// method in the local object
public String findAll(Object localObjRef)
{ String temp = "";
try
{ Class c = localObjRef.getClass();
Class[] cArr = {};
Method m = c.getMethod("findAll", cArr);
Object[] obj = {};
ZipCodeList newlist = (ZipCodeList)m.invoke(localObjRef, obj);
ZipCodeList iter = newlist;
int length = 0;
while(iter != null)
{ length++;
iter = iter.next;
}
temp += "ZipCodeList," ;
temp += length + ",";
temp += "String,city,";
temp += "String,ZipCode,";
iter = newlist;
while(iter != null)
{ temp += iter.city + "," ;
temp += iter.ZipCode + "," ;
iter = iter.next;
}
}catch(Exception e)
{ System.out.println(e);
}
//return the marshalled reply to yourRMI
return temp;
}
// The following method calls the actual printAll method
// in the local object reference
public String printAll(Object localObjRef)
{ try{
Class c = localObjRef.getClass();
Method m = c.getMethod("printAll", null);
m.invoke(localObjRef, null);
}catch(Exception e)
{ System.out.println(e.getMessage());
}
//return the marshalled reply to yourRMI
return "It worked";
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -