dsiimpl.java
来自「UCS (Ultra Corba Simulator) is one more 」· Java 代码 · 共 303 行
JAVA
303 行
package com.corba.mnq.skelstub;
import com.corba.mnq.main.MNQmainFrame;
import com.corba.mnq.skelstub.dsiext.ServantExtension;
import com.corba.mnq.tool.CorbaFacility;
import com.corba.mnq.tool.EtcProperties;
import com.corba.mnq.tool.GetEtcTool;
import com.corba.mnq.tool.LoggerTool;
import com.corba.mnq.tool.idl.Args;
import com.corba.mnq.tool.idl.ExceptSequence;
import com.corba.mnq.tool.idl.IdlInterface;
import com.corba.mnq.tool.idl.IdlOperation;
import com.corba.mnq.tool.idl.InArgs;
import com.corba.mnq.tool.idl.InoutArgs;
import com.corba.mnq.tool.idl.OutArgs;
import com.corba.mnq.tool.idl.ReturnArgs;
import com.corba.mnq.tool.idl.type.CTExceptList;
import com.corba.mnq.tool.idl.type.TypeBase;
import com.corba.mnq.ui.MNQMutableTreeNode;
import java.util.Enumeration;
import java.util.List;
import java.util.Vector;
import java.util.logging.Logger;
import org.omg.CORBA.ARG_IN;
import org.omg.CORBA.ARG_INOUT;
import org.omg.CORBA.ARG_OUT;
import org.omg.CORBA.Any;
import org.omg.PortableServer.DynamicImplementation;
public class DsiImpl extends DynamicImplementation {
// Whether to provide the customized servant method in DSI
public static boolean customized = false;
/** used for java.util.logging */
private static final Logger LOG = Logger.getLogger(DsiImpl.class.getName());
private static EtcProperties props;
static {
props = GetEtcTool.getProperties();
customized = props.getProperty("CorbaMNQ.dsi.customized", "false").equalsIgnoreCase("true");
}
private IdlInterface in = null;
private List ops;
// singleton ORB as any factory
org.omg.CORBA.ORB orb = null;
public DsiImpl(org.omg.CORBA.ORB orb, IdlInterface in) {
this.orb = orb;
this.in = in;
ops = getAllOpNodes();
}
/** from Servant */
public String[] _all_interfaces(org.omg.PortableServer.POA poa, byte[] objectId) {
String[] ids = new String[] { in.id() };
return ids;
}
private List getAllOpNodes() {
List ret = new Vector();
MNQMutableTreeNode top = in.dmtn;
do {
for (Enumeration e = top.children(); e.hasMoreElements();) {
Object o = ((MNQMutableTreeNode) e.nextElement()).getUserObject();
if (o instanceof IdlOperation) {
ret.add(o);
MNQmainFrame.initialParaTree((IdlOperation) o);
}
}
top = (MNQMutableTreeNode) top.getParent();
if (top.isRoot())
break;
} while (true);
return ret;
}
public void invoke(org.omg.CORBA.ServerRequest request) {
String op = request.operation();
try {
MNQmainFrame.serverPane.appendln("Conent of the request\"" + op + "\":", "Title");
for (int i = 0; i < ops.size(); i++) {
CTExceptList excepts = null;
IdlOperation on = (IdlOperation) ops.get(i);
if (op.equals(on.sName)) {
List in = new Vector();
// Servant extension
List in_type = new Vector();
List name = new Vector();
List out = new Vector();
List out_type = new Vector();
TypeBase rt = null;
TypeBase except = null;
org.omg.CORBA.NVList params = orb.create_list(0);
for (Enumeration e = ((MNQMutableTreeNode) on.dtm.getRoot()).children(); e
.hasMoreElements();) {
Args o = (Args) (((MNQMutableTreeNode) e.nextElement()).getUserObject());
Any argAny = orb.create_any();
if (o.pt.type() != null) {// to avoid
// ExceptList
argAny.type(o.pt.type());
}
if (o instanceof InArgs) {
// o.pt.getValueFromTree();
o.pt.argModes = "in";
params.add_value("", argAny, ARG_IN.value);
in.add(argAny);
name.add(o.pt.toString());
in_type.add(o.pt);
} else if (o instanceof OutArgs) {
o.pt.getValueFromTree();
o.pt.argModes = "out";
params.add_value("", argAny, ARG_OUT.value);
out.add(argAny);
out_type.add(o.pt);
} else if (o instanceof InoutArgs) {
o.pt.getValueFromTree();
o.pt.argModes = "inout";
params.add_value("", argAny, ARG_INOUT.value);
in.add(argAny);
name.add(o.pt.toString());
out.add(argAny);
out_type.add(o.pt);
in_type.add(o.pt);
} else if (o instanceof ReturnArgs) {
rt = o.pt;
rt.getValueFromTree();
} else if (o instanceof ExceptSequence) {
excepts = (CTExceptList) o.pt;
except = ((CTExceptList) o.pt).selectedExcept;
if (except != null)
except.getValueFromTree();
}
}
/* read in and inout arguments */
request.arguments(params);
// output in & inout values
for (int j = 0; j < in.size(); j++) {
Any a = (Any) in.get(j);
MNQmainFrame.serverPane.appendln((String) name.get(j), "Input");
MNQmainFrame.serverPane.appendln(CorbaFacility.toString(a, true));
}
// extact object value from corba any
List in_ext = new Vector();
List out_ext = new Vector();
boolean extension = false;
if (customized) {
for (int j = 0; j < in.size(); j++) {
Any a = (Any) in.get(j);
TypeBase intype = (TypeBase) in_type.get(j);
Object obj = intype.extract(a);
//System.out.println(objOutput(obj));
in_ext.add(obj);
}
String claName = on.getClassName();// "Ucs_"
// +
// on.cName.replaceAll("::",
// "");
LOG.info(claName + " will be loaded");
try {
Class cls = MNQmainFrame.dsiCL.loadClass(claName); // Class.forName(claName);
ServantExtension sext = (ServantExtension) cls.newInstance();
sext.servantImpl(in_ext, out_ext);
extension = true;
} catch (Exception ex) {
LoggerTool.logStackTrace(ex, LOG);
}
}
if (extension) {
try {
Object objVal = out_ext.get(out_ext.size() - 1);
if (objVal != null) {
List ex = (List) objVal;
int ii = ((Integer) ex.remove(0)).intValue();
except = (TypeBase) excepts.memType.get(ii);
Any exceptAny = orb.create_any();
except.insert(exceptAny, objVal);
request.set_exception(exceptAny);
return;
}
} catch (Exception ex) {
LoggerTool.logStackTrace(ex, LOG);
}
}
// check whether it needs to send exception.
if (except != null) {
Any exceptAny = orb.create_any();
except.insert(exceptAny, except.val);
request.set_exception(exceptAny);
return;
}
// insert values to out & inout
for (int j = 0; j < out.size(); j++) {
Any oriAny = (Any) out.get(j);
TypeBase refType = (TypeBase) out_type.get(j);
if (extension) {
try {
Object objVal = out_ext.get(j);
if (objVal != null) {
refType.insert(oriAny, objVal);
continue;
}
} catch (Exception ex) {
LoggerTool.logStackTrace(ex, LOG);
}
}
refType.insert(oriAny, refType.val);
}
Any resultAny = orb.create_any();
if (extension) {
try {
Object objVal = out_ext.get(out_ext.size() - 2);
if (objVal != null) {
rt.insert(resultAny, objVal);
request.set_result(resultAny);
return;
}
} catch (Exception ex) {
LoggerTool.logStackTrace(ex, LOG);
}
}
rt.insert(resultAny, rt.val);
request.set_result(resultAny);
return;
}
}
if (op.equals("_all_interfaces")) {
throw new org.omg.CORBA.BAD_OPERATION(
"Object reference operations not implemented in example!");
} else if (op.equals("_get_interface")) {
throw new org.omg.CORBA.BAD_OPERATION(
"Object reference operations not implemented in example!");
} else if (op.equals("_is_a")) {
throw new org.omg.CORBA.BAD_OPERATION(
"Object reference operations not implemented in example");
} else {
throw new org.omg.CORBA.BAD_OPERATION(op + " not found.");
}
} catch (Exception ex) {
LoggerTool.logStackTrace(ex, LOG);
}
}
/**
* Method: "objOutput"
*
* @param obj
*/
private String objOutput(Object obj) {
String str = "";
if (obj instanceof Object[]) {
Object[] objs = (Object[]) obj;
str += "{";
// LOG.info("{");
for (int i = 0; i < objs.length; i++) {
str += objOutput(objs[i]);
if (i != objs.length) {
str += ";";
// LOG.info(";");
}
}
str += "}";
// LOG.info("}");
} else {
str = obj.toString();
// LOG.info(obj.toString());
}
return str;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?