📄 actionpip.java
字号:
HashMap action = new HashMap();
QName[] qName = null;
for (int j=0; j<vector.size(); j++) {
ActionParameter parameter = (ActionParameter)vector.get(j);
qName = parameter.getParmeterPath();
String type = this.getDataType(qName,keyMethods[i],wsdl);
if (type==null) throw new InitializeException("cannot find such parameter path");
TypeAndValue tv = new TypeAndValue(type,null);
action.put(qName[qName.length-1],tv);
logger.debug("parameter: "+qName[qName.length-1].getLocalPart()+" - "+tv.getDataType());
}
ParameterPath path = new ParameterPath(qName,action);
this.actions.put(keyMethods[i],path);
}
} catch (SecurityException se) {
throw new InitializeException("error:"+se);
}
}
public void close() throws CloseException {
logger.info("the custom action PIP finishes collecting the action and its parameters");
}
private String getDataType(QName[] params, String method, Element wsdl) throws InitializeException {
String tns = wsdl.getAttribute("xmlns:tns");
String xsd = wsdl.getAttribute("xmlns:xsd");
if (wsdl==null) throw new InitializeException("invalid wsdl: return null");
String input = this.getInputMessage(method,wsdl);
if (input==null) throw new InitializeException("invalid wsdl: cannot find such operation :"+method);
QName parameters = this.getParameters(input,wsdl);
if (parameters==null) throw new InitializeException("invalid wsdl: cannot find corresponding parameters :"+input);
Element request = this.getRequest(parameters,wsdl);
if (request==null) throw new InitializeException("invalid wsdl: parameter specification is missing");
return this.getType(params,request,tns,xsd);
}
private String getInputMessage(String method, Element wsdl) {
NodeList list = wsdl.getElementsByTagName("operation");
String result = null;
for (int i=0; i<list.getLength(); i++) {
Node node = list.item(i);
if (Text.class.isAssignableFrom(node.getClass())) continue;
if (((Element)node).getAttribute("name").equals(method)) {
NodeList list1 = node.getChildNodes();
for (int j=0; j<list1.getLength(); j++) {
Node node1 = list1.item(j);
if (Text.class.isAssignableFrom(node1.getClass())) continue;
if (node1.getNodeName().equals("input")) {
Element ele = (Element)node1;
result = ele.getAttribute("message");
int index = result.indexOf("tns:");
if (index==0) result = result.substring(4);
}
}
}
}
return result;
}
private QName getParameters(String inputMessage,Element wsdl) {
String tns = wsdl.getAttribute("xmlns:tns");
NodeList list = wsdl.getElementsByTagName("message");
QName result = null;
for (int i=0; i<list.getLength(); i++) {
Node node = list.item(i);
if (Text.class.isAssignableFrom(node.getClass())) continue;
if (((Element)node).getAttribute("name").equals(inputMessage)) {
NodeList list1 = node.getChildNodes();
for (int j=0; j<list1.getLength(); j++) {
Node node1 = list1.item(j);
if (Text.class.isAssignableFrom(node.getClass())) continue;
if (node1.getNodeName().equals("part")) {
Element ele = (Element)node1;
String str = ele.getAttribute("element");
int index = str.indexOf("tns:");
if (index==0) {
str = str.substring(4);
result = new QName(tns,str);
}
}
}
}
}
return result;
}
private Element getRequest(QName parameters,Element wsdl) {
String xsd = wsdl.getAttribute("xmlns:xsd");
NodeList list = wsdl.getElementsByTagName("types");
Element result = null;
for (int i=0; i<list.getLength(); i++) {
Node node = list.item(i);
if (Text.class.isAssignableFrom(node.getClass())) continue;
NodeList list0 = node.getChildNodes();
for (int k=0; k<list0.getLength(); k++) {
Node node0 = list0.item(k);
if (Text.class.isAssignableFrom(node0.getClass())) continue;
if (node0.getNodeName().equals("xsd:schema")) {
NodeList list1 = node0.getChildNodes();
for (int j=0; j<list1.getLength(); j++) {
Node node1 = list1.item(j);
if (Text.class.isAssignableFrom(node1.getClass())) continue;
if (node1.getNodeName().equals("xsd:element")) {
Element ele = (Element)node1;
if (ele.getAttribute("name").equals(parameters.getLocalPart())) {
result = ele;
return result;
}
}
}
}
}
}
return result;
}
private String getType(QName[] paramPath, Element request, String tns, String xsd) {
String result = null;
for (int i=0; i<paramPath.length; i++) {
String local = paramPath[i].getLocalPart();
String uri = paramPath[i].getNamespaceURI();
String name = request.getAttribute("name");
if (tns.equals(uri) && name.equals(local)) {
NodeList list = request.getChildNodes();
if (list.getLength()==0) {
result = request.getAttribute("type");
int index = result.indexOf(":");
if (index>=0) result = result.substring(index+1);
if (i==paramPath.length-1) return result;
else return null;
} else {
NodeList list1 = request.getElementsByTagNameNS(xsd,"element");
boolean found = false;
for (int j=0; j<list1.getLength(); j++) {
Node node1 = list1.item(j);
request = (Element)node1;
if (i+1>=paramPath.length) return null;
if (request.getAttribute("name").equals(paramPath[i+1].getLocalPart())) {
found = true;
break;
}
}
if (!found) return null;
}
} else return null;
}
return result;
}
private String[] getWsdlFileName(Element wsdd) throws InitializeException {
ArrayList strs = new ArrayList();
NodeList list = wsdd.getChildNodes();
String result = null;
for (int i=0; i<list.getLength(); i++) {
Node node = list.item(i);
if (Text.class.isAssignableFrom(node.getClass())) continue;
if (node.getNodeName().equals("service")) {
NodeList list2 = node.getChildNodes();
for (int j=0; j<list2.getLength(); j++) {
Node node2 = list2.item(j);
if (Text.class.isAssignableFrom(node2.getClass())) continue;
if (node2.getNodeName().equals("wsdlFile")) {
NodeList list1 = node2.getChildNodes();
if (list1.getLength()!=1) throw new InitializeException("invalid wsdd");
Node node1 = list1.item(0);
if (Text.class.isAssignableFrom(node1.getClass())) {
Text text = (Text)node1;
String value = text.getNodeValue().trim();
int index = value.toLowerCase().lastIndexOf("_service.wsdl");
if (index<1) throw new InitializeException("invalid wsdl file name");
result = value.substring(0,index);
} else throw new InitializeException("invalid wsdd");
}
}
}
}
if (result==null) throw new InitializeException("invalid wsdd");
int index1 = 0;
int index = result.indexOf("/");
if (index<0) strs.add(result);
while (index>=0) {
if (index==0) {
strs.add(new String());
} else strs.add(result.substring(index1,index));
index1=index+1;
index = result.indexOf("/",index1);
if (index<0) strs.add(result.substring(index1));
}
String[] folders = new String[strs.size()];
folders = (String[])strs.toArray(folders);
return folders;
}
private String depthTraverse(Node node, QName[] paramName) {
String soapEleName = node.getNodeName();
if (node==null) return null;
NodeList list = node.getChildNodes();
if (paramName[0].getLocalPart().equals(soapEleName) && soapEleName.equals(paramName[paramName.length-1].getLocalPart())) {
if (list.getLength()==1) {
Node node1 = list.item(0);
if (Text.class.isAssignableFrom(node1.getClass())) {
String value = node1.getNodeValue();
return value.trim();
} else return null;
} else return null;
} else {
for (int i=0; i<list.getLength(); i++) {
Node node1 = list.item(i);
if (Text.class.isAssignableFrom(node1.getClass())) continue;
for (int j=0; j<paramName.length-1; j++) paramName[j]=paramName[j+1];
String result = depthTraverse(node1,paramName);
if (result!=null) return result;
}
}
return null;
}
private String getConvertedType(String typeIn) {
if (typeIn.equals("int")) return "integer";
if (typeIn.equals("float")) return "double";
return typeIn;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -