- 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) {