axisservice2wsdl11.java
来自「开源的axis2框架的源码。用于开发WEBSERVER」· Java 代码 · 共 1,070 行 · 第 1/4 页
JAVA
1,070 行
// Adding ext elements
OMElement httpBinding = fac.createOMElement("binding", http);
binding.addChild(httpBinding);
httpBinding.addAttribute("verb", "POST", null);
for (Iterator operations = axisService.getOperations(); operations.hasNext();) {
AxisOperation axisOperation = (AxisOperation) operations.next();
if (axisOperation.isControlOperation() || axisOperation.getName() == null) {
continue;
}
String opeartionName = axisOperation.getName().getLocalPart();
OMElement operation = fac.createOMElement(OPERATION_LOCAL_NAME,
wsdl);
binding.addChild(operation);
OMElement httpOperation = fac.createOMElement("operation", http);
operation.addChild(httpOperation);
httpOperation.addAttribute("location", axisService.getName() + "/" + axisOperation.getName()
.getLocalPart(), null);
String MEP = axisOperation.getMessageExchangePattern();
if (WSDL2Constants.MEP_URI_IN_ONLY.equals(MEP)
|| WSDL2Constants.MEP_URI_IN_OPTIONAL_OUT
.equals(MEP)
|| WSDL2Constants.MEP_URI_OUT_OPTIONAL_IN
.equals(MEP)
|| WSDL2Constants.MEP_URI_ROBUST_OUT_ONLY
.equals(MEP)
|| WSDL2Constants.MEP_URI_ROBUST_IN_ONLY
.equals(MEP)
|| WSDL2Constants.MEP_URI_IN_OUT
.equals(MEP)) {
AxisMessage inaxisMessage = axisOperation
.getMessage(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
if (inaxisMessage != null) {
operation.addAttribute(ATTRIBUTE_NAME, opeartionName, null);
OMElement input = fac.createOMElement(IN_PUT_LOCAL_NAME,
wsdl);
OMElement inputelement = fac.createOMElement("content",
mime);
input.addChild(inputelement);
inputelement.addAttribute("type", "text/xml", null);
inputelement.addAttribute("part", axisOperation.getName()
.getLocalPart(), null);
operation.addChild(input);
}
}
if (WSDL2Constants.MEP_URI_OUT_ONLY.equals(MEP)
|| WSDL2Constants.MEP_URI_OUT_OPTIONAL_IN
.equals(MEP)
|| WSDL2Constants.MEP_URI_IN_OPTIONAL_OUT
.equals(MEP)
|| WSDL2Constants.MEP_URI_ROBUST_OUT_ONLY
.equals(MEP)
|| WSDL2Constants.MEP_URI_IN_OUT
.equals(MEP)) {
AxisMessage outAxisMessage = axisOperation
.getMessage(WSDLConstants.MESSAGE_LABEL_OUT_VALUE);
if (outAxisMessage != null) {
OMElement output = fac.createOMElement(OUT_PUT_LOCAL_NAME,
wsdl);
OMElement outElement = fac.createOMElement("content", mime);
outElement.addChild(outElement);
outElement.addAttribute("type", "text/xml", null);
outElement.addAttribute("part", axisOperation.getName()
.getLocalPart(), null);
output.addChild(outElement);
operation.addChild(output);
}
}
}
}
private void writeSoapHeaders(AxisMessage inaxisMessage, OMFactory fac,
OMElement input, OMNamespace soapNameSpace) throws Exception {
ArrayList extElementList;
extElementList = inaxisMessage.getSoapHeaders();
if (extElementList != null) {
Iterator elements = extElementList.iterator();
while (elements.hasNext()) {
SOAPHeaderMessage soapheader = (SOAPHeaderMessage) elements
.next();
addSOAPHeader(fac, input, soapheader, soapNameSpace);
}
}
}
private void addExtensionElement(OMFactory fac, OMElement element,
String name, String att1Name, String att1Value,
String att2Name,
String att2Value, OMNamespace soapNameSpace) {
OMElement soapbinding = fac.createOMElement(name, soapNameSpace);
element.addChild(soapbinding);
soapbinding.addAttribute(att1Name, att1Value, null);
if (att2Name != null) {
soapbinding.addAttribute(att2Name, att2Value, null);
}
}
private void setDefinitionElement(OMElement defintion) {
this.definition = defintion;
}
private void addSOAPHeader(OMFactory fac, OMElement element,
SOAPHeaderMessage header, OMNamespace soapNameSpace) {
OMElement extElement = fac.createOMElement("header", soapNameSpace);
element.addChild(extElement);
String use = header.getUse();
if (use != null) {
extElement.addAttribute("use", use, null);
}
if (header.part() != null) {
extElement.addAttribute("part", header.part(), null);
}
if (header.getMessage() != null) {
extElement.addAttribute("message", WSDLSerializationUtil
.getPrefix(targetNamespace, axisService.getNamespaceMap()) + ":" +
header.getMessage().getLocalPart(), null);
}
}
private void addPolicyAsExtElement(int type, PolicyInclude policyInclude, OMElement element)
throws Exception {
ArrayList elementList = policyInclude.getPolicyElements(type);
for (Iterator iterator = elementList.iterator(); iterator.hasNext();) {
Object policyElement = iterator.next();
if (policyElement instanceof Policy) {
element.addChild(PolicyUtil.getPolicyComponentAsOMElement(
(PolicyComponent) policyElement, serializer));
} else if (policyElement instanceof PolicyReference) {
element
.addChild(PolicyUtil
.getPolicyComponentAsOMElement((PolicyComponent) policyElement));
PolicyRegistry reg = policyInclude.getPolicyRegistry();
String key = ((PolicyReference) policyElement).getURI();
if (key.startsWith("#")) {
key = key.substring(key.indexOf("#") + 1);
}
Policy p = reg.lookup(key);
if (p == null) {
throw new Exception("Policy not found for uri : " + key);
}
addPolicyToDefinitionElement(key, p);
}
}
}
private void addPolicyAsExtAttribute(int type, PolicyInclude policyInclude,
OMElement element, OMFactory factory) throws Exception {
ArrayList elementList = policyInclude.getPolicyElements(type);
ArrayList policyURIs = new ArrayList();
for (Iterator iterator = elementList.iterator(); iterator.hasNext();) {
Object policyElement = iterator.next();
String key;
if (policyElement instanceof Policy) {
Policy p = (Policy) policyElement;
if (p.getId() != null) {
key = "#" + p.getId();
} else if (p.getName() != null) {
key = p.getName();
} else {
throw new RuntimeException(
"Can't add the Policy as an extensibility attribute since it doesn't have a id or a name attribute");
}
policyURIs.add(key);
addPolicyToDefinitionElement(key, p);
} else {
String uri = ((PolicyReference) policyElement).getURI();
PolicyRegistry registry = policyInclude.getPolicyRegistry();
if (uri.startsWith("#")) {
key = uri.substring(uri.indexOf('#') + 1);
} else {
key = uri;
}
Policy p = registry.lookup(key);
if (p == null) {
throw new RuntimeException("Cannot resolve " + uri
+ " to a Policy");
}
addPolicyToDefinitionElement(key, p);
}
}
if (!policyURIs.isEmpty()) {
String value = null;
/*
* We need to create a String that is like 'uri1 uri2 .." to set as
* the value of the wsp:PolicyURIs attribute.
*/
for (Iterator iterator = policyURIs.iterator(); iterator.hasNext();) {
String uri = (String) iterator.next();
value = (value == null) ? uri : " " + uri;
}
OMNamespace ns = factory.createOMNamespace(
org.apache.neethi.Constants.URI_POLICY_NS,
org.apache.neethi.Constants.ATTR_WSP);
OMAttribute URIs = factory.createOMAttribute("PolicyURIs", ns,
value);
element.addAttribute(URIs);
}
}
private void addPoliciesToDefinitionElement(Iterator iterator,
OMElement definitionElement) throws Exception {
Policy policy;
OMElement policyElement;
OMNode firstChild;
for (; iterator.hasNext();) {
policy = (Policy) iterator.next();
policyElement = PolicyUtil.getPolicyComponentAsOMElement(policy,
serializer);
firstChild = definition.getFirstOMChild();
if (firstChild != null) {
firstChild.insertSiblingBefore(policyElement);
} else {
definitionElement.addChild(policyElement);
}
}
}
private void addPolicyToDefinitionElement(String key, Policy policy) {
policiesInDefinitions.put(key, policy);
}
public String getStyle() {
return style;
}
public void setStyle(String style) {
this.style = style;
}
public String getUse() {
return use;
}
public void setUse(String use) {
this.use = use;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?