private static Policy getAddressingPolicy(Element wsamAddressingElm, String usedPolicyNamespace) {
// check if found reference is addressing policy
Element wsAddressing = XmlUtils.getFirstChildElementNS(wsamAddressingElm, WsaUtils.WS_A_NAMESPACE_200705,
"Addressing");
Element addressingPolicy = null;
Policy newPolicy = PolicyDocument.Factory.newInstance().addNewPolicy();
Addressing newAddressing = null;
if (wsAddressing != null) {
newAddressing = newPolicy.addNewAddressing();
String optional = wsAddressing.getAttributeNS(usedPolicyNamespace, "Optional");
if (!StringUtils.isNullOrEmpty(optional) && optional.equals(OptionalType.TRUE.toString())) {
newAddressing.setOptional(OptionalType.TRUE);
} else {
newAddressing.setOptional(OptionalType.FALSE);
}
addressingPolicy = XmlUtils.getFirstChildElementNS(wsAddressing, usedPolicyNamespace, "Policy");
if (addressingPolicy != null) {
Element exactlyOne = XmlUtils.getFirstChildElementNS(addressingPolicy, usedPolicyNamespace, "ExactlyOne");
if (exactlyOne != null) {
Element all = XmlUtils.getFirstChildElementNS(exactlyOne, usedPolicyNamespace, "All");
if (all != null) {
getAddressingAnonymous(all, newAddressing);
}
} else {
getAddressingAnonymous(addressingPolicy, newAddressing);
}
}
}
Element usingAddressing = XmlUtils.getFirstChildElementNS(wsamAddressingElm, WsaUtils.WS_A_NAMESPACE_200605,
"UsingAddressing");
if (usingAddressing != null) {
// add UsingAddressing to policy
newPolicy.addNewUsingAddressing();
}
return newPolicy;
}