use of com.sun.xml.txw2.TypedXmlWriter in project metro-jax-ws by eclipse-ee4j.
the class PolicyModelMarshallerTest method testMarshal_PolicySourceModel_Object.
/**
* Test of marshal method, of class PolicyModelMarshaller.
*/
public void testMarshal_PolicySourceModel_Object() throws PolicyException {
PolicySourceModel model = PolicySourceModel.createPolicySourceModel(NamespaceVersion.v1_2);
Document document = builder.newDocument();
TypedXmlWriter storage = TXW.create(new QName("root"), TypedXmlWriter.class, new DomSerializer(document));
PolicyModelMarshaller instance = PolicyModelMarshaller.getXmlMarshaller(false);
instance.marshal(model, storage);
storage.commit();
Element element = document.getDocumentElement();
Node policyElement = element.getFirstChild();
assertEquals(policyElement.getLocalName(), "Policy");
}
use of com.sun.xml.txw2.TypedXmlWriter in project metro-jax-ws by eclipse-ee4j.
the class PolicyModelMarshallerTest method testMarshalPrefixWrite.
public void testMarshalPrefixWrite() throws PolicyException {
PolicySourceModel model = PolicySourceModel.createPolicySourceModel(NamespaceVersion.v1_5, "id", null);
ModelNode root = model.getRootNode();
ModelNode all = root.createChildAllNode();
AssertionData assertion = AssertionData.createAssertionData(new QName("http://schemas.foo.com/", "Assertion"));
all.createChildAssertionNode(assertion);
Document document = builder.newDocument();
TypedXmlWriter storage = TXW.create(new QName("root"), TypedXmlWriter.class, new DomSerializer(document));
PolicyModelMarshaller instance = PolicyModelMarshaller.getXmlMarshaller(false);
instance.marshal(model, storage);
storage.commit();
Element element = document.getDocumentElement();
Node policyElement = element.getFirstChild();
assertEquals(NamespaceVersion.v1_5.getDefaultNamespacePrefix(), policyElement.getPrefix());
NamedNodeMap map = policyElement.getAttributes();
Node id = map.getNamedItemNS(PolicyConstants.WSU_ID.getNamespaceURI(), PolicyConstants.WSU_ID.getLocalPart());
assertEquals(PolicyConstants.WSU_NAMESPACE_PREFIX, id.getPrefix());
}
use of com.sun.xml.txw2.TypedXmlWriter in project metro-jax-ws by eclipse-ee4j.
the class XmlPolicyModelMarshaller method marshal.
/**
* Marshal a policy onto the given TypedXmlWriter.
*
* @param model A policy source model.
* @param writer A typed XML writer.
* @throws PolicyException If marshalling failed.
*/
private void marshal(final PolicySourceModel model, final TypedXmlWriter writer) throws PolicyException {
final TypedXmlWriter policy = writer._element(model.getNamespaceVersion().asQName(XmlToken.Policy), TypedXmlWriter.class);
marshalDefaultPrefixes(model, policy);
marshalPolicyAttributes(model, policy);
marshal(model.getNamespaceVersion(), model.getRootNode(), policy);
}
use of com.sun.xml.txw2.TypedXmlWriter in project metro-jax-ws by eclipse-ee4j.
the class XmlPolicyModelMarshaller method marshal.
/**
* Marshal given ModelNode and child elements on given TypedXmlWriter.
*
* @param nsVersion The WS-Policy version.
* @param rootNode The ModelNode that is marshalled.
* @param writer The TypedXmlWriter onto which the content of the rootNode is marshalled.
*/
private void marshal(final NamespaceVersion nsVersion, final ModelNode rootNode, final TypedXmlWriter writer) {
for (ModelNode node : rootNode) {
final AssertionData data = node.getNodeData();
if (marshallInvisible || data == null || !data.isPrivateAttributeSet()) {
TypedXmlWriter child = null;
if (data == null) {
child = writer._element(nsVersion.asQName(node.getType().getXmlToken()), TypedXmlWriter.class);
} else {
child = writer._element(data.getName(), TypedXmlWriter.class);
final String value = data.getValue();
if (value != null) {
child._pcdata(value);
}
if (data.isOptionalAttributeSet()) {
child._attribute(nsVersion.asQName(XmlToken.Optional), Boolean.TRUE);
}
if (data.isIgnorableAttributeSet()) {
child._attribute(nsVersion.asQName(XmlToken.Ignorable), Boolean.TRUE);
}
for (Entry<QName, String> entry : data.getAttributesSet()) {
child._attribute(entry.getKey(), entry.getValue());
}
}
marshal(nsVersion, node, child);
}
}
}
use of com.sun.xml.txw2.TypedXmlWriter in project metro-jax-ws by eclipse-ee4j.
the class XmlPolicyModelMarshaller method marshal.
/**
* Marshal a policy onto the given StaxSerializer.
*
* @param model A policy source model.
* @param writer A Stax serializer.
* @throws PolicyException If marshalling failed.
*/
private void marshal(final PolicySourceModel model, final StaxSerializer writer) throws PolicyException {
final TypedXmlWriter policy = TXW.create(model.getNamespaceVersion().asQName(XmlToken.Policy), TypedXmlWriter.class, writer);
marshalDefaultPrefixes(model, policy);
marshalPolicyAttributes(model, policy);
marshal(model.getNamespaceVersion(), model.getRootNode(), policy);
policy.commit();
}
Aggregations