List<String[]> list = getMethods(content);
for (int i = 0; i < list.size(); i++) {
String[] func = list.get(i);
// 生成operation节点,函数的根节点
Element operation = new Element("operation");
operation.setAttribute("name", func[2]);
operation.setAttribute("type", func[0]);
// 生成req节点,属operation下一级节点
Element req = new Element("req");
Element rsp = null;
/**
* 如果函数是twoway类型则生成rsp节点 rsp节点下第一个param为函数调用结果
*/
if (func[0].equals("twoway")) {
rsp = new Element("rsp");
Element resultP = new Element("param");
Element resultN = new Element("node");
resultN.setAttribute("name", "call_result");
resultN.setAttribute("type", "oct");
resultN.setAttribute("value", "");
resultP.addContent(resultN);
rsp.addContent(resultP);
}
/**
* 获取第一个最外层容器,如果没有则返回null
*
* @param text
* @return
*/
protected String getContainer(String text, String regex) {
Pattern p = Pattern.compile(regex);
Matcher m = p.matcher(text);
if (m.find()) {
String temp = m.group();
int flag = 0;
int left = 0;
int right = 0;
char[] ca = temp.toCharArray();
for (int i = 0; i < ca.length; i++) {
if (ca[i] == '{') {
left++;
} else if (ca[i] == '}') {
right++;
}
if (left == right && left != 0) {
flag = i + 2;
break;
}
}
return temp.substring(0, flag);
}
return null;
}
/**
* 获取容器类型
* @param text
* @return module or interface
*/
protected String getContainerType(String text){
Pattern p = Pattern.compile(Regex.REGEX_CONTAI_TYPE);
Matcher m = p.matcher(text);
if(m.find()){
String temp = m.group();
return temp.substring(0, temp.indexOf(" ")).trim();
}
return null;
}