aboutsummaryrefslogtreecommitdiffstats
path: root/ONAP-XACML/src/main/java/org/onap/policy/xacml/util/XACMLPolicyWriter.java
diff options
context:
space:
mode:
authorJorge Hernandez <jh1730@att.com>2018-09-06 12:53:21 +0000
committerGerrit Code Review <gerrit@onap.org>2018-09-06 12:53:21 +0000
commit5aeeaae2e6ea881dd11601bedc2ffc94443bc9d3 (patch)
tree42bbf56dcc9680be6b0fa2836596ebc80283f3d5 /ONAP-XACML/src/main/java/org/onap/policy/xacml/util/XACMLPolicyWriter.java
parent5dfb55068e2bb88af55d6ce48c235cff7ea9b326 (diff)
parent7fd58e9a2427a215daa6b543e901534e83d3c246 (diff)
Merge "XACML Platform Enhancements"
Diffstat (limited to 'ONAP-XACML/src/main/java/org/onap/policy/xacml/util/XACMLPolicyWriter.java')
-rw-r--r--ONAP-XACML/src/main/java/org/onap/policy/xacml/util/XACMLPolicyWriter.java25
1 files changed, 21 insertions, 4 deletions
diff --git a/ONAP-XACML/src/main/java/org/onap/policy/xacml/util/XACMLPolicyWriter.java b/ONAP-XACML/src/main/java/org/onap/policy/xacml/util/XACMLPolicyWriter.java
index 928165909..e1d0223f6 100644
--- a/ONAP-XACML/src/main/java/org/onap/policy/xacml/util/XACMLPolicyWriter.java
+++ b/ONAP-XACML/src/main/java/org/onap/policy/xacml/util/XACMLPolicyWriter.java
@@ -137,11 +137,28 @@ public class XACMLPolicyWriter {
*
*
*/
- public static InputStream getXmlAsInputStream(PolicyType policy) {
- JAXBElement<PolicyType> policyElement = new ObjectFactory().createPolicy(policy);
+ public static InputStream getXmlAsInputStream(Object policy) {
+ JAXBElement<?> policyElement;
+ if (policy instanceof PolicyType) {
+ policyElement = new ObjectFactory().createPolicy((PolicyType) policy);
+ return getByteArrayInputStream(policyElement, PolicyType.class);
+ } else if (policy instanceof PolicyType) {
+ policyElement = new ObjectFactory().createPolicySet((PolicySetType) policy);
+ return getByteArrayInputStream(policyElement, PolicySetType.class);
+ }
+ return null;
+ }
+
+ /**
+ * Helper static class that reads the JAXB element and return policy input stream.
+ * @param policyElement
+ * @param className (PolicyType or PolicySetType ?).
+ * @return ByteArrayInputStream.
+ */
+ public static InputStream getByteArrayInputStream(JAXBElement<?> policyElement, Class<?> className) {
try {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
- JAXBContext context = JAXBContext.newInstance(PolicyType.class);
+ JAXBContext context = JAXBContext.newInstance(className);
Marshaller m = context.createMarshaller();
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
m.marshal(policyElement, byteArrayOutputStream);
@@ -149,7 +166,7 @@ public class XACMLPolicyWriter {
} catch (JAXBException e) {
PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "XACMLPolicyWriter", "writePolicyFile failed");
throw new IllegalArgumentException("XACMLPolicyWriter writePolicyFile failed", e);
- }
+ }
}
/**
* Helper static class that does the work to write a policy set to an output stream.