private
String loadProtocal(String header)
{
String result=null;
try
{
Properties prop=
new
Properties();
// FileInputStream fis=new FileInputStream("emp.properties");
// id = prop.getProperty(idString);
// prop.load(fis);
// fis.close();
prop.load(getTCL().getResourceAsStream("emp.properties"));
result=prop.getProperty(header);
}
catch
(Exception e)
{
System.out.println(e);
}
return
result;
}
private
static
ClassLoader getTCL() throws IllegalAccessException,
InvocationTargetException {
Method method = null;
try
{
method = Thread.
class
.getMethod("getContextClassLoader", null);
}
catch
(NoSuchMethodException e) {
return
null;
}
return
(ClassLoader)method.invoke(Thread.currentThread(), null);
}
//针对消息作出响应,利用反射导入对应的类
public
String response(String header,String content,String content2,List list)
{
String result=null;
String s=null;
try
{
/*
* 导入属性文件 emp.properties,查询 header 所对应的类的名字
* 通过反射机制动态加载匹配的类,所有的类都被 Operator 接口隔离
* 可以通过修改属性文件、添加新的类(继承 MsgOperator 接口)来扩展协议
*/
s="org.bromon.reflect."+this.loadProtocal(header).trim();
//加载类