📄 componentbuilder.java
字号:
}
private OperationInfo buildOperation(OperationInfo operationInfo,
BindingOperation bindingOper) {
System.out.println("从一个BindingOperation对象(<wsdl:operation>)构建OperationInfo对象");
Operation oper = bindingOper.getOperation();
operationInfo.setTargetMethodName(oper.getName());
Vector operElems = findExtensibilityElement(bindingOper
.getExtensibilityElements(), "operation");
ExtensibilityElement operElem = (ExtensibilityElement) operElems
.elementAt(0);
if (operElem != null && operElem instanceof SOAPOperation) {
SOAPOperation soapOperation = (SOAPOperation) operElem;
operationInfo.setSoapActionURI(soapOperation.getSoapActionURI());
}
BindingInput bindingInput = bindingOper.getBindingInput();
BindingOutput bindingOutput = bindingOper.getBindingOutput();
Vector bodyElems = findExtensibilityElement(bindingInput
.getExtensibilityElements(), "body");
ExtensibilityElement bodyElem = (ExtensibilityElement) bodyElems
.elementAt(0);
if (bodyElem != null && bodyElem instanceof SOAPBody) {
SOAPBody soapBody = (SOAPBody) bodyElem;
List styles = soapBody.getEncodingStyles();
String encodingStyle = null;
if (styles != null) {
encodingStyle = styles.get(0).toString();
}
if (encodingStyle == null) {
encodingStyle = DEFAULT_SOAP_ENCODING_STYLE;
}
operationInfo.setEncodingStyle(encodingStyle.toString());
operationInfo.setTargetObjectURI(soapBody.getNamespaceURI());
}
Input inDef = oper.getInput();
System.out.println("开始转移到了<wsdl:portTyp>结点下的<wsdl:input>");
if (inDef != null) {
Message inMsg = inDef.getMessage();
if (inMsg != null) {
operationInfo.setInputMessageName(inMsg.getQName().getLocalPart());
//输入消息的参数构建
getParameterFromMessage(operationInfo, inMsg, 1);
System.out.println("***操作:"+operationInfo.getTargetMethodName()+"的所有输入参数已经构建完毕***");
System.out.println("");
operationInfo.setInmessage(inMsg);
}
}
Output outDef = oper.getOutput();
if (outDef != null) {
Message outMsg = outDef.getMessage();
if (outMsg != null) {
operationInfo.setOutputMessageName(outMsg.getQName()
.getLocalPart());
//输出消息的参数构建
getParameterFromMessage(operationInfo, outMsg, 2);
System.out.println("***操作:"+operationInfo.getTargetMethodName()+"的所有输出参数已经构建完毕***");
System.out.println("");
operationInfo.setOutmessage(outMsg);
}
}
return operationInfo;
}
private void getParameterFromMessage(OperationInfo operationInfo,
Message msg, int manner) {
String tip="";
System.out.println("*******************");
if(manner==1){
tip="输入";
}
else{
tip="输出";
}
System.out.println("");
System.out.println("***开始构建"+operationInfo.getTargetMethodName()+"操作的所有消息"+tip+"参数***");
List msgParts = msg.getOrderedParts(null);
Schema wsdlType = null;
Iterator iter = msgParts.iterator();
while (iter.hasNext()) {
Part part = (Part) iter.next();
String targetnamespace = "";
XMLType xmlType=getXMLType(part, wsdlType, operationInfo);
if (xmlType!=null&&xmlType.isComplexType()) {
buildComplexParameter((ComplexType) xmlType, operationInfo,
manner);
}
else {
System.out.print("part所引用的xml元素是简单类型");
String partName = part.getName();
ParameterInfo parameter = new ParameterInfo();
parameter.setName(partName);
parameter.setKind(part.getTypeName().getLocalPart());
if (manner == 1) {
//1表示构建的是操作的输入参数
operationInfo.addInparameter(parameter);
} else {
operationInfo.addOutparameter(parameter);
}
}
operationInfo.setWsdltype(wsdlTypes);
}
}
private void buildComplexParameter(ComplexType type,
OperationInfo operationInfo, int manner) {
//XML Schema 规范定义了大量的组件,
//如schema、complexType、simpleType、group、annotation、include、import、element 和 attribute 等等。
//particleEnum就是ComplexType下的子元素内容,可以是上面的部分组件组合
Enumeration particleEnum=type.enumerate();
//group就是元素(可以是复杂类型)集合
Group group = null;
if(!particleEnum.hasMoreElements()){
System.out.println(operationInfo+"操作不需要输入参数");
}
while (particleEnum.hasMoreElements()) {
System.out.println("这是<complexType>容器下的子元素");
Particle particle = (Particle) particleEnum.nextElement();
if (particle instanceof Group) {
System.out.println("子元素也是一个元素集合(<xsd:element...>)");
group = (Group) particle;
break;
}
}
if (group != null) {
Enumeration groupEnum = group.enumerate();
while (groupEnum.hasMoreElements()) {
//看看此复杂数据类型的每一个Element情况
Structure item = (Structure) groupEnum.nextElement();
if (item.getStructureType()==Structure.ELEMENT) {
ElementDecl elementDecl = (ElementDecl) item;
System.out.println("复杂数据类型的子元素是一个Element:"+elementDecl.getReferenceId());
XMLType xmlType = elementDecl.getType();
if (xmlType != null && xmlType.isComplexType()) {
System.out.println("***"+elementDecl.getReferenceId()+"元素是一个复杂类型,进入递归调用****");
buildComplexParameter((ComplexType)xmlType,operationInfo, manner);
} else {
System.out.println("现在开始处理简单数据类型");
ParameterInfo parameter = new ParameterInfo();
parameter.setName(elementDecl.getName());
System.out.println("参数名为:" + elementDecl.getName());
parameter.setKind(elementDecl.getType().getName());
System.out.println("参数类型为:" + elementDecl.getType().getName());
if (manner == 1) {
operationInfo.addInparameter(parameter);
} else {
operationInfo.addOutparameter(parameter);
}
}
}
}
}
}
protected XMLType getXMLType(Part part, Schema wsdlType,
OperationInfo operationInfo) {
if (wsdlTypes == null) {
System.out.println("null is here in the 1 ");
return null;
}
XMLType xmlType = null;
if (part.getElementName()!= null) {
String elemName=part.getElementName().getLocalPart();
System.out.println("part引用的类型名为:"+elemName);
ElementDecl elemDecl = null;
for (int i = 0; i < wsdlTypes.size(); i++) {
wsdlType = (Schema) (wsdlTypes.elementAt(i));
String targetnamespace=wsdlType.getTargetNamespace();
operationInfo.setNamespaceURI(targetnamespace);
elemDecl=wsdlType.getElementDecl(elemName);
if (elemDecl!=null) {
break;
}
}
if (elemDecl!=null) {
xmlType = elemDecl.getType();
//System.out.println(xmlType);
}
}
return xmlType;
}
private static Vector findExtensibilityElement(List extensibilityElements,
String elementType) {
int i = 0;
Vector elements = new Vector();
if (extensibilityElements!= null) {
Iterator iter = extensibilityElements.iterator();
while (iter.hasNext()) {
ExtensibilityElement elment = (ExtensibilityElement)iter.next();
if (elment.getElementType().getLocalPart().equalsIgnoreCase(elementType)) {
elements.add(elment);
}
}
}
return elements;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -