📄 idloperation.java
字号:
package com.corba.mnq.tool.idl;
import com.corba.mnq.skelstub.dsiext.SampleSerExt;
import com.corba.mnq.tool.BNFTool;
import com.corba.mnq.tool.Warehouse;
import com.corba.mnq.tool.idl.type.CTBasic;
import com.corba.mnq.tool.idl.type.CTExceptList;
import com.corba.mnq.tool.idl.type.TypeBase;
import javax.swing.tree.DefaultTreeModel;
import java.util.List;
import java.util.Vector;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class IdlOperation extends IdlBase {
/**
* @param args
*/
public static void main_(String[] args) {
// TODO Auto-generated method stub
}
// context content
public String context;
// store root node for paratree
public DefaultTreeModel dtm;
// store root node for resulttree
public DefaultTreeModel dtmRes;
// this operation is loacted in which interface node
public IdlInterface in = null;
// whether this is oneway method
public boolean oneway;
// parameter content
public String paras;
// raises content
public String raises;
// return type
public String rtype;
public IdlOperation() {
super();
// TODO Auto-generated constructor stub
}
public IdlBase cloneNode() {
IdlOperation on = new IdlOperation();
on.cName = this.cName;
on.content = this.content;
on.context = this.context;
on.dmtn = this.dmtn;
on.dtm = this.dtm;
on.fn = this.fn;
on.oneway = this.oneway;
on.paras = this.paras;
on.prefix = this.prefix;
on.raises = this.raises;
on.rtype = this.rtype;
on.sibling = this.sibling;
on.sName = this.sName;
on.val = on.val;
return on;
}
public List getAllNodes() {
List ret = getParametersNode();
ret.add(getReturnNode());
ExceptSequence eln = new ExceptSequence();
List ecps = getExceptions();
eln.pt = new CTExceptList();
eln.pt.rdn = "Exceptions";
for (int i = 0; i < ecps.size(); i++) {
IdlExcept en = (IdlExcept) ecps.get(i);
((CTExceptList) eln.pt).memType.add(en.toType());
}
ret.add(eln);
return ret;
}
/**
* Method: "getCodeBase"
*
* @return
*/
public String getCodeBase() {
String codeBase = SampleSerExt.SE_HEAD.replaceAll("XXXXXXXX", getClassName());
// get all in, in_out , out parameter
List ret = getParametersNode();
Args r = getReturnNode();
int ii = 0;
// retrive value from "in"
for (int i = 0; i < ret.size(); i++) {
Args o = (Args) ret.get(i);
if (o instanceof InArgs || o instanceof InoutArgs) {
codeBase += " " + o.pt.getValType() + " " + o.sName + " = (" + o.pt.getValType()
+ ") in.get(" + ii + ");\n";
ii++;
}
}
codeBase += "\n";
// prepare output value
for (int i = 0; i < ret.size(); i++) {
Args o = (Args) ret.get(i);
if (o instanceof OutArgs || o instanceof InoutArgs) {
codeBase += " " + o.pt.getValType() + " " + o.sName + " = null;\n";
}
}
codeBase += " " + r.pt.getValType() + " ret = null;\n";
codeBase += " java.util.List except = null;\n\n";
codeBase += SampleSerExt.BODY_BEGIN + SampleSerExt.BODY_END;
// add the output in the "out"
for (int i = 0; i < ret.size(); i++) {
Args o = (Args) ret.get(i);
if (o instanceof OutArgs || o instanceof InoutArgs) {
codeBase += " out.add(" + o.sName + ");\n";
}
}
codeBase += " out.add(ret);\n";
codeBase += " out.add(except);\n";
codeBase += SampleSerExt.SE_TAIL;
return codeBase;
}
/**
* Method: "getClassName"
*
* @return
*/
public String getClassName() {
return "Ucs_" + cName.replaceAll("::", "_");
}
public List getExceptions() {
List ret = new Vector();
if (raises == null)
return ret;
String scoped_name = BNFTool.scoped_name;
Pattern pType = Pattern.compile(scoped_name, Pattern.DOTALL + Pattern.MULTILINE);
Matcher mType = pType.matcher(raises);
while (mType.find()) {
String t = mType.group(0).replaceAll("\\s+", "").replaceAll("::_", "::");
String tmp;
Object node = null;
if (t.indexOf("::") < 0) {
String val;
val = cName;
do {
val = val.substring(0, val.lastIndexOf("::"));
tmp = val + "::" + t;
node = Warehouse.cname2node.get(tmp.replaceAll("::_", "::"));
if (node != null)
break;
if (val.equalsIgnoreCase(""))
break;
} while (true);
} else {
if (t.startsWith("::")) {
tmp = t;
} else {
tmp = "::" + t;
}
node = Warehouse.cname2node.get(tmp.replaceAll("::_", "::"));
}
ret.add(node);
}
return ret;
}
public String getIconName() {
return "operation.gif";
}
private TypeBase getIncludedType(String t) {
String tmp;
Object node = null;
if (t.indexOf("::") < 0) {
String val;
val = cName;
do {
val = val.substring(0, val.lastIndexOf("::"));
tmp = val + "::" + t;
node = Warehouse.cname2node.get(tmp.replaceAll("::_", "::"));
if (node != null)
break;
if (val.equalsIgnoreCase(""))
break;
} while (true);
} else {
if (t.startsWith("::")) {
tmp = t;
} else {
tmp = "::" + t;
}
node = Warehouse.cname2node.get(tmp.replaceAll("::_", "::"));
}
if (node != null) {
if (node instanceof IdlType) {
return ((IdlType) node).toType();
} else if (node instanceof IdlInterface) {
return ((IdlInterface) node).toType();
} else {
System.out.println("Wrong in getIncludedType() of IdlType: "
+ ((IdlBase) node).content);
}
}
CTBasic bt = new CTBasic();
if (t.equalsIgnoreCase("float"))
bt.rdn = "float";
else if (t.equalsIgnoreCase("double"))
bt.rdn = "double";
else if (t.equalsIgnoreCase("long double") || t.equalsIgnoreCase("longdouble"))
bt.rdn = "long double";
else if (t.equalsIgnoreCase("short"))
bt.rdn = "short";
else if (t.equalsIgnoreCase("long"))
bt.rdn = "long";
else if (t.equalsIgnoreCase("long long") || t.equalsIgnoreCase("longlong"))
bt.rdn = "long long";
else if (t.equalsIgnoreCase("unsigned short") || t.equalsIgnoreCase("unsignedshort"))
bt.rdn = "unsigned short";
else if (t.equalsIgnoreCase("unsigned long") || t.equalsIgnoreCase("unsignedlong"))
bt.rdn = "unsigned long";
else if (t.equalsIgnoreCase("unsigned long long") || t.equalsIgnoreCase("unsignedlonglong"))
bt.rdn = "unsigned long long";
else if (t.equalsIgnoreCase("char"))
bt.rdn = "char";
else if (t.equalsIgnoreCase("wchar"))
bt.rdn = "wchar";
else if (t.equalsIgnoreCase("boolean"))
bt.rdn = "boolean";
else if (t.equalsIgnoreCase("octet"))
bt.rdn = "octet";
else if (t.equalsIgnoreCase("any"))
bt.rdn = "any";
else if (t.equalsIgnoreCase("string"))
bt.rdn = "string";
else if (t.equalsIgnoreCase("wstring"))
bt.rdn = "wstring";
else if (t.equalsIgnoreCase("void"))
bt.rdn = "void";
else {
bt.rdn = "string";
}
return bt;
}
public String getIor() {
if (in == null) {
String tmp = cName.substring(0, cName.lastIndexOf("::"));
IdlInterface inn = (IdlInterface) Warehouse.cname2node.get(tmp.replaceAll("::_", "::"));
in = inn;
return inn.getior();
}
return in.getior();
}
public List getParametersNode() {
List ret = new Vector();
String param_type_spec = BNFTool.param_type_spec;
// group --memMode, group 2--memType, group 3--memName
String strmem = "((?>in)|(?>out)|(?>inout))\\s+" + "(" + param_type_spec + ")" + "\\s+"
+ BNFTool.identifier_catch;
Pattern pType = Pattern.compile(strmem, Pattern.DOTALL + Pattern.MULTILINE);
Matcher mType = pType.matcher(paras);
while (mType.find()) {
String name = mType.group(3);
String type = mType.group(2).replaceAll("\\s+", "").replaceAll("::_", "::");
String mode = mType.group(1);
if (mode.equalsIgnoreCase("in")) {
InArgs n = new InArgs();
n.cName = "in:" + name;
n.sName = name;
n.pt = getIncludedType(type);
n.pt.disName = n.cName;
ret.add(n);
} else if (mode.equalsIgnoreCase("out")) {
OutArgs n = new OutArgs();
n.cName = "out:" + name;
n.sName = name;
n.pt = getIncludedType(type);
n.pt.disName = n.cName;
ret.add(n);
} else {
InoutArgs n = new InoutArgs();
n.cName = "inout:" + name;
n.sName = name;
n.pt = getIncludedType(type);
n.pt.disName = n.cName;
ret.add(n);
}
}
return ret;
}
public ReturnArgs getReturnNode() {
ReturnArgs n = new ReturnArgs();
n.pt = getIncludedType(rtype);
n.cName = n.pt.dn;
n.sName = n.pt.rdn;
return n;
}
public TypeBase getReturnType() {
return getIncludedType(rtype);
}
public void recurContent() {
// TODO Auto-generated method stub
}
}
/* EOF */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -