FileDocCategorySizeDatePackage
XmlPolicyModelMarshaller.javaAPI DocExample7151Tue May 29 16:56:40 BST 2007com.sun.xml.ws.policy.sourcemodel

XmlPolicyModelMarshaller

public final class XmlPolicyModelMarshaller extends PolicyModelMarshaller

Fields Summary
private static final com.sun.xml.ws.policy.privateutil.PolicyLogger
LOGGER
private final boolean
marshallInvisible
Constructors Summary
XmlPolicyModelMarshaller(boolean marshallInvisible)

    
      
        this.marshallInvisible = marshallInvisible;
    
Methods Summary
public voidmarshal(PolicySourceModel model, java.lang.Object storage)

        if (storage instanceof TypedXmlWriter) {
            marshal(model, (TypedXmlWriter) storage);
        } else if (storage instanceof XMLStreamWriter) {
            marshal(model, (XMLStreamWriter) storage);
        } else {
            throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0022_STORAGE_TYPE_NOT_SUPPORTED(storage.getClass().getName())));
        }
    
public voidmarshal(java.util.Collection models, java.lang.Object storage)

        for (PolicySourceModel model : models) {
            marshal(model, storage);
        }
    
private voidmarshal(PolicySourceModel model, com.sun.xml.txw2.TypedXmlWriter writer)
Marshal a policy onto the given TypedXmlWriter.

param
model A policy source model.
param
writer A typed XML writer.

        final TypedXmlWriter policy = writer._element(PolicyConstants.POLICY, TypedXmlWriter.class);
        marshalPolicyAttributes(model, policy);
        marshal(model.getRootNode(), policy);
    
private voidmarshal(PolicySourceModel model, javax.xml.stream.XMLStreamWriter writer)
Marshal a policy onto the given XMLStreamWriter.

param
model A policy source model.
param
writer An XML stream writer.

        final StaxSerializer serializer = new StaxSerializer(writer);
        final TypedXmlWriter policy = TXW.create(PolicyConstants.POLICY, TypedXmlWriter.class, serializer);
        
        final Map<String, String> nsMap = model.getNamespaceToPrefixMapping();
        
        if (!marshallInvisible && nsMap.containsKey(PolicyConstants.SUN_POLICY_NAMESPACE_URI)) {
            nsMap.remove(PolicyConstants.SUN_POLICY_NAMESPACE_URI);
        }
        
        for (Map.Entry<String, String> nsMappingEntry : nsMap.entrySet()) {
            policy._namespace(nsMappingEntry.getKey(), nsMappingEntry.getValue());
        }
        
        marshalPolicyAttributes(model, policy);
        marshal(model.getRootNode(), policy);
        policy.commit();
        serializer.flush();
    
private voidmarshal(ModelNode rootNode, com.sun.xml.txw2.TypedXmlWriter writer)
Marshal given ModelNode and child elements on given TypedXmlWriter.

param
rootNode The ModelNode that is marshalled.
param
writer The TypedXmlWriter onto which the content of the rootNode is marshalled.

        for (ModelNode node : rootNode) {
            final AssertionData data = node.getNodeData();
            if (marshallInvisible || data == null || !data.isPrivateAttributeSet()) {
                TypedXmlWriter child = null;
                if (data == null) {
                    child = writer._element(node.getType().asQName(), TypedXmlWriter.class);
                } else {
                    child = writer._element(data.getName(), TypedXmlWriter.class);
                    final String value = data.getValue();
                    if (value != null) {
                        child._pcdata(value);
                    }
                    for (Entry<QName, String> entry : data.getAttributesSet()) {
                        child._attribute(entry.getKey(), entry.getValue());
                    }
                }
                marshal(node, child);
            }
        }
    
private static voidmarshalPolicyAttributes(PolicySourceModel model, com.sun.xml.txw2.TypedXmlWriter writer)
Marshal the Policy root element attributes onto the TypedXmlWriter.

param
model The policy source model.
param
writer The typed XML writer.

        final String policyId = model.getPolicyId();
        if (policyId != null) {
            writer._attribute(PolicyConstants.WSU_ID, policyId);
        }
        
        final String policyName = model.getPolicyName();
        if (policyName != null) {
            writer._attribute(PolicyConstants.POLICY_NAME, policyName);
        }