| Method from org.apache.axis2.util.PolicyUtil Detail: |
public static PolicyReference createPolicyReference(Policy policy) {
PolicyReference policyReference = new PolicyReference();
String key = policy.getName();
if (key == null) {
key = policy.getId();
if (key == null) {
key = UUIDGenerator.getUUID();
policy.setId(key);
}
policyReference.setURI("#" + key);
} else {
policyReference.setURI(key);
}
return policyReference;
}
|
public static String generateId(AxisDescription description) {
PolicyInclude policyInclude = description.getPolicyInclude();
String identifier = "-policy-1";
if (description instanceof AxisMessage) {
identifier = "msg-" + ((AxisMessage) description).getName()
+ identifier;
description = description.getParent();
}
if (description instanceof AxisOperation) {
identifier = "op-" + ((AxisOperation) description).getName()
+ identifier;
description = description.getParent();
}
if (description instanceof AxisService) {
identifier = "service-" + ((AxisService) description).getName()
+ identifier;
}
/*
* Int 49 is the value of the Character '1'. Here we want to change '1'
* to '2' or '2' to '3' .. etc. to construct a unique identifier.
*/
for (int index = 49; policyInclude.getPolicy(identifier) != null; index++) {
identifier = identifier.replace((char) index, (char) (index + 1));
}
return identifier;
}
|
public static Policy getMergedPolicy(List policies,
AxisDescription description) {
Policy policy = null;
for (Iterator iterator = policies.iterator(); iterator.hasNext();) {
Object policyElement = iterator.next();
if (policyElement instanceof Policy) {
policy = (policy == null) ? (Policy) policyElement
: (Policy) policy.merge((Policy) policyElement);
} else {
PolicyReference policyReference = (PolicyReference) policyElement;
Policy policy2 = (Policy) policyReference.normalize(
new AxisPolicyLocator(description), false);
policy = (policy == null) ? policy2 : (Policy) policy
.merge(policy2);
}
}
if (policy != null) {
policy = (Policy) policy.normalize(new AxisPolicyLocator(
description), false);
}
return policy;
}
|
public static Policy getMergedPolicy(List policies,
AxisService service) {
Policy policy = null;
for (Iterator iterator = policies.iterator(); iterator.hasNext();) {
Object policyElement = iterator.next();
if (policyElement instanceof Policy) {
policy = (policy == null) ? (Policy) policyElement
: (Policy) policy.merge((Policy) policyElement);
} else {
PolicyReference policyReference = (PolicyReference) policyElement;
Policy policy2 = (Policy) policyReference.normalize(
new PolicyLocator(service), false);
policy = (policy == null) ? policy2 : (Policy) policy
.merge(policy2);
}
}
if (policy != null) {
policy = (Policy) policy.normalize(new PolicyLocator(service),
false);
}
return policy;
}
|
public static PolicyComponent getPolicyComponent(Element element) {
if (Constants.URI_POLICY_NS.equals(element.getNamespaceURI())) {
if (Constants.ELEM_POLICY.equals(element.getLocalName())) {
return PolicyEngine.getPolicy(nodeToStream(element));
} else if (Constants.ELEM_POLICY_REF.equals(element.getLocalName())) {
return PolicyEngine.getPolicyReferene(nodeToStream(element));
}
}
throw new IllegalArgumentException(
"Agrument is neither a < wsp:Policy > nor a < wsp:PolicyReference > element");
}
|
public static OMElement getPolicyComponentAsOMElement(PolicyComponent component) throws XMLStreamException, FactoryConfigurationError {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
XMLStreamWriter writer = XMLOutputFactory.newInstance()
.createXMLStreamWriter(baos);
component.serialize(writer);
writer.flush();
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
return (OMElement) XMLUtils.toOM(bais);
}
|
public static OMElement getPolicyComponentAsOMElement(PolicyComponent policyComponent,
ExternalPolicySerializer externalPolicySerializer) throws XMLStreamException, FactoryConfigurationError {
if (policyComponent instanceof Policy) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
externalPolicySerializer.serialize((Policy) policyComponent, baos);
ByteArrayInputStream bais = new ByteArrayInputStream(baos
.toByteArray());
return (OMElement) XMLUtils.toOM(bais);
} else {
OMFactory fac = OMAbstractFactory.getOMFactory();
OMElement elem = fac.createOMElement(Constants.ELEM_POLICY_REF,
Constants.URI_POLICY_NS, Constants.ATTR_WSP);
elem.addAttribute(Constants.ATTR_URI,
((PolicyReference) policyComponent).getURI(), null);
return elem;
}
}
|
public static PolicyComponent getPolicyComponentFromOMElement(OMElement policyComponent) throws IllegalArgumentException {
if (Constants.Q_ELEM_POLICY.equals(policyComponent.getQName())) {
return PolicyEngine.getPolicy(policyComponent);
} else if (policyComponent.getQName().equals(
new QName(Constants.URI_POLICY_NS, Constants.ELEM_POLICY_REF))) {
return PolicyEngine.getPolicyReference(policyComponent);
} else {
throw new IllegalArgumentException(
"Agrument is neither a < wsp:Policy > nor a < wsp:PolicyReference > element");
}
}
|
public static Policy getPolicyFromOMElement(OMElement policyElement) {
if (Constants.Q_ELEM_POLICY.equals(policyElement.getQName())) {
return PolicyEngine.getPolicy(policyElement);
} else {
throw new IllegalArgumentException(
"argument is not a < wsp:Policy .. > element");
}
}
|
public static PolicyReference getPolicyReferenceFromOMElement(OMElement policyRefElement) {
if (Constants.URI_POLICY_NS.equals(policyRefElement.getNamespace()
.getNamespaceURI())
&& Constants.ELEM_POLICY_REF.equals(policyRefElement
.getLocalName())) {
return PolicyEngine.getPolicyReference(policyRefElement);
} else {
throw new IllegalArgumentException(
"argument is not a < wsp:PolicyReference > element");
}
}
|
public static String getSafeString(String unsafeString) {
StringBuffer sbuf = new StringBuffer();
char[] chars = unsafeString.toCharArray();
for (int i = 0; i < chars.length; i++) {
char c = chars[i];
switch (c) {
case '\\":
sbuf.append('\\");
sbuf.append('\\");
break;
case '"":
sbuf.append('\\");
sbuf.append('"");
break;
case '\n":
sbuf.append('\\");
sbuf.append('n");
break;
case '\r":
sbuf.append('\\");
sbuf.append('r");
break;
default:
sbuf.append(c);
}
}
return sbuf.toString();
}
|
public static String policyComponentToString(PolicyComponent policyComponent) throws XMLStreamException, FactoryConfigurationError {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
XMLStreamWriter writer = XMLOutputFactory.newInstance()
.createXMLStreamWriter(baos);
policyComponent.serialize(writer);
writer.flush();
return baos.toString();
}
|