FileDocCategorySizeDatePackage
PolicyModelGenerator.javaAPI DocExample7682Tue May 29 16:56:38 BST 2007com.sun.xml.ws.policy.sourcemodel

PolicyModelGenerator

public final class PolicyModelGenerator extends Object
author
Marek Potociar

Fields Summary
private static final com.sun.xml.ws.policy.privateutil.PolicyLogger
LOGGER
private static final PolicyModelGenerator
generator
Constructors Summary
private PolicyModelGenerator()
This private constructor avoids direct instantiation from outside of the class

    
                    
      
        // nothing to initialize
    
Methods Summary
public static com.sun.xml.ws.policy.sourcemodel.PolicyModelGeneratorgetGenerator()
Factory method that returns {@link PolicyModelGenerator} instance.

return
{@link PolicyModelGenerator} instance

        return generator;
    
public PolicySourceModeltranslate(com.sun.xml.ws.policy.Policy policy)
This method translates a {@link Policy} into a {@link com.sun.xml.ws.policy.sourcemodel policy infoset}. The resulting PolicySourceModel is disconnected from the input policy, thus any additional changes in the policy will have no effect on the PolicySourceModel.

param
policy The policy to be translated into an infoset. May be null.
return
translated The policy infoset. May be null if the input policy was null.
throws
PolicyException in case Policy translation fails.

        LOGGER.entering(policy);
        
        PolicySourceModel model = null;
        
        if (policy == null) {
            LOGGER.fine(LocalizationMessages.WSP_0047_POLICY_IS_NULL_RETURNING());
        } else {
            model = PolicySourceModel.createPolicySourceModel(policy.getId(), policy.getName());
            
            final ModelNode rootNode = model.getRootNode();
            final ModelNode exactlyOneNode = rootNode.createChildExactlyOneNode();
            for (AssertionSet set : policy) {
                final ModelNode alternativeNode = exactlyOneNode.createChildAllNode();
                for (PolicyAssertion assertion : set) {
                    final AssertionData data = AssertionData.createAssertionData(assertion.getName(), assertion.getValue(), assertion.getAttributes());
                    final ModelNode assertionNode = alternativeNode.createChildAssertionNode(data);
                    if (assertion.hasNestedPolicy()) {
                        translate(assertionNode, assertion.getNestedPolicy());
                    }
                    if (assertion.hasNestedAssertions()) {
                        translate(assertion.getNestedAssertionsIterator(), assertionNode);
                    }
                }
            }
        }
        
        LOGGER.exiting(model);
        return model;
    
private ModelNodetranslate(ModelNode parentAssertion, com.sun.xml.ws.policy.NestedPolicy policy)
Iterates through a nested policy and return the corresponding policy info model.

param
policy The nested policy
return
The nested policy translated to the policy info model

        final ModelNode nestedPolicyRoot = parentAssertion.createChildPolicyNode();
        final ModelNode exactlyOneNode = nestedPolicyRoot.createChildExactlyOneNode();
        final AssertionSet set = policy.getAssertionSet();
        final ModelNode alternativeNode = exactlyOneNode.createChildAllNode();
        for (PolicyAssertion assertion : set) {
            final AssertionData data = AssertionData.createAssertionData(assertion.getName(), assertion.getValue(), assertion.getAttributes());
            final ModelNode assertionNode = alternativeNode.createChildAssertionNode(data);
            if (assertion.hasNestedPolicy()) {
                translate(assertionNode, assertion.getNestedPolicy());
            }
            if (assertion.hasNestedAssertions()) {
                translate(assertion.getNestedAssertionsIterator(), assertionNode);
            }
        }
        return nestedPolicyRoot;
    
private voidtranslate(java.util.Iterator assertionParametersIterator, ModelNode assertionNode)
Iterates through all contained assertions and adds them to the info model.

param
assertions The set of contained assertions
param
assertionNode The node to which the assertions are added as child nodes

        while (assertionParametersIterator.hasNext()) {
            final PolicyAssertion assertionParameter = assertionParametersIterator.next();
            final AssertionData data = AssertionData.createAssertionParameterData(assertionParameter.getName(), assertionParameter.getValue(), assertionParameter.getAttributes());
            final ModelNode assertionParameterNode = assertionNode.createChildAssertionParameterNode(data);
            if (assertionParameter.hasNestedPolicy()) {
                throw LOGGER.logSevereException(new IllegalStateException(LocalizationMessages.WSP_0005_UNEXPECTED_POLICY_ELEMENT_FOUND_IN_ASSERTION_PARAM(assertionParameter)));
            }
            if (assertionParameter.hasNestedAssertions()) {
                translate(assertionParameter.getNestedAssertionsIterator(), assertionParameterNode);
            }
        }