src/share/jaxws_classes/com/sun/xml/internal/ws/policy/sourcemodel/PolicyModelGenerator.java

Thu, 12 Oct 2017 19:44:07 +0800

author
aoqi
date
Thu, 12 Oct 2017 19:44:07 +0800
changeset 760
e530533619ec
parent 0
373ffda63c9a
permissions
-rw-r--r--

merge

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation. Oracle designates this
aoqi@0 8 * particular file as subject to the "Classpath" exception as provided
aoqi@0 9 * by Oracle in the LICENSE file that accompanied this code.
aoqi@0 10 *
aoqi@0 11 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 14 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 15 * accompanied this code).
aoqi@0 16 *
aoqi@0 17 * You should have received a copy of the GNU General Public License version
aoqi@0 18 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 20 *
aoqi@0 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 22 * or visit www.oracle.com if you need additional information or have any
aoqi@0 23 * questions.
aoqi@0 24 */
aoqi@0 25
aoqi@0 26 package com.sun.xml.internal.ws.policy.sourcemodel;
aoqi@0 27
aoqi@0 28 import com.sun.xml.internal.ws.policy.AssertionSet;
aoqi@0 29 import com.sun.xml.internal.ws.policy.NestedPolicy;
aoqi@0 30 import com.sun.xml.internal.ws.policy.Policy;
aoqi@0 31 import com.sun.xml.internal.ws.policy.PolicyAssertion;
aoqi@0 32 import com.sun.xml.internal.ws.policy.PolicyException;
aoqi@0 33 import com.sun.xml.internal.ws.policy.privateutil.LocalizationMessages;
aoqi@0 34 import com.sun.xml.internal.ws.policy.privateutil.PolicyLogger;
aoqi@0 35
aoqi@0 36 import java.util.Iterator;
aoqi@0 37
aoqi@0 38 /**
aoqi@0 39 * Translate a policy into a PolicySourceModel.
aoqi@0 40 *
aoqi@0 41 * Code that depends on JAX-WS should use com.sun.xml.internal.ws.api.policy.ModelGenerator
aoqi@0 42 * instead of this class.
aoqi@0 43 *
aoqi@0 44 * @author Marek Potociar
aoqi@0 45 * @author Fabian Ritzmann
aoqi@0 46 */
aoqi@0 47 public abstract class PolicyModelGenerator {
aoqi@0 48
aoqi@0 49 private static final PolicyLogger LOGGER = PolicyLogger.getLogger(PolicyModelGenerator.class);
aoqi@0 50
aoqi@0 51 /**
aoqi@0 52 * This protected constructor avoids direct instantiation from outside of the class
aoqi@0 53 */
aoqi@0 54 protected PolicyModelGenerator() {
aoqi@0 55 // nothing to initialize
aoqi@0 56 }
aoqi@0 57
aoqi@0 58 /**
aoqi@0 59 * Factory method that returns a {@link PolicyModelGenerator} instance.
aoqi@0 60 *
aoqi@0 61 * @return {@link PolicyModelGenerator} instance
aoqi@0 62 */
aoqi@0 63 public static PolicyModelGenerator getGenerator() {
aoqi@0 64 return getNormalizedGenerator(new PolicySourceModelCreator());
aoqi@0 65 }
aoqi@0 66
aoqi@0 67 /**
aoqi@0 68 * Allows derived classes to create instances of the package private
aoqi@0 69 * CompactModelGenerator.
aoqi@0 70 *
aoqi@0 71 * @param creator An implementation of the PolicySourceModelCreator.
aoqi@0 72 * @return An instance of CompactModelGenerator.
aoqi@0 73 */
aoqi@0 74 protected static PolicyModelGenerator getCompactGenerator(PolicySourceModelCreator creator) {
aoqi@0 75 return new CompactModelGenerator(creator);
aoqi@0 76 }
aoqi@0 77
aoqi@0 78 /**
aoqi@0 79 * Allows derived classes to create instances of the package private
aoqi@0 80 * NormalizedModelGenerator.
aoqi@0 81 *
aoqi@0 82 * @param creator An implementation of the PolicySourceModelCreator.
aoqi@0 83 * @return An instance of NormalizedModelGenerator.
aoqi@0 84 */
aoqi@0 85 protected static PolicyModelGenerator getNormalizedGenerator(PolicySourceModelCreator creator) {
aoqi@0 86 return new NormalizedModelGenerator(creator);
aoqi@0 87 }
aoqi@0 88
aoqi@0 89 /**
aoqi@0 90 * This method translates a {@link Policy} into a
aoqi@0 91 * {@link com.sun.xml.internal.ws.policy.sourcemodel policy infoset}. The resulting
aoqi@0 92 * PolicySourceModel is disconnected from the input policy, thus any
aoqi@0 93 * additional changes in the policy will have no effect on the PolicySourceModel.
aoqi@0 94 *
aoqi@0 95 * @param policy The policy to be translated into an infoset. May be null.
aoqi@0 96 * @return translated The policy infoset. May be null if the input policy was
aoqi@0 97 * null.
aoqi@0 98 * @throws PolicyException in case Policy translation fails.
aoqi@0 99 */
aoqi@0 100 public abstract PolicySourceModel translate(final Policy policy) throws PolicyException;
aoqi@0 101
aoqi@0 102 /**
aoqi@0 103 * Iterates through a nested policy and returns the corresponding policy info model.
aoqi@0 104 *
aoqi@0 105 * @param parentAssertion The parent node.
aoqi@0 106 * @param policy The nested policy.
aoqi@0 107 * @return The nested policy translated to the policy info model.
aoqi@0 108 */
aoqi@0 109 protected abstract ModelNode translate(final ModelNode parentAssertion, final NestedPolicy policy);
aoqi@0 110
aoqi@0 111 /**
aoqi@0 112 * Add the contents of the assertion set as child node to the given model node.
aoqi@0 113 *
aoqi@0 114 * @param node The content of this assertion set are added as child nodes to this node.
aoqi@0 115 * May not be null.
aoqi@0 116 * @param assertions The assertions that are to be added to the node. May not be null.
aoqi@0 117 */
aoqi@0 118 protected void translate(final ModelNode node, final AssertionSet assertions) {
aoqi@0 119 for (PolicyAssertion assertion : assertions) {
aoqi@0 120 final AssertionData data = AssertionData.createAssertionData(assertion.getName(), assertion.getValue(), assertion.getAttributes(), assertion.isOptional(), assertion.isIgnorable());
aoqi@0 121 final ModelNode assertionNode = node.createChildAssertionNode(data);
aoqi@0 122 if (assertion.hasNestedPolicy()) {
aoqi@0 123 translate(assertionNode, assertion.getNestedPolicy());
aoqi@0 124 }
aoqi@0 125 if (assertion.hasParameters()) {
aoqi@0 126 translate(assertionNode, assertion.getParametersIterator());
aoqi@0 127 }
aoqi@0 128 }
aoqi@0 129 }
aoqi@0 130
aoqi@0 131 /**
aoqi@0 132 * Iterates through all contained assertions and adds them to the info model.
aoqi@0 133 *
aoqi@0 134 * @param assertionParametersIterator The contained assertions.
aoqi@0 135 * @param assertionNode The node to which the assertions are added as child nodes
aoqi@0 136 */
aoqi@0 137 protected void translate(final ModelNode assertionNode, final Iterator<PolicyAssertion> assertionParametersIterator) {
aoqi@0 138 while (assertionParametersIterator.hasNext()) {
aoqi@0 139 final PolicyAssertion assertionParameter = assertionParametersIterator.next();
aoqi@0 140 final AssertionData data = AssertionData.createAssertionParameterData(assertionParameter.getName(), assertionParameter.getValue(), assertionParameter.getAttributes());
aoqi@0 141 final ModelNode assertionParameterNode = assertionNode.createChildAssertionParameterNode(data);
aoqi@0 142 if (assertionParameter.hasNestedPolicy()) {
aoqi@0 143 throw LOGGER.logSevereException(new IllegalStateException(LocalizationMessages.WSP_0005_UNEXPECTED_POLICY_ELEMENT_FOUND_IN_ASSERTION_PARAM(assertionParameter)));
aoqi@0 144 }
aoqi@0 145 if (assertionParameter.hasNestedAssertions()) {
aoqi@0 146 translate(assertionParameterNode, assertionParameter.getNestedAssertionsIterator());
aoqi@0 147 }
aoqi@0 148 }
aoqi@0 149 }
aoqi@0 150
aoqi@0 151
aoqi@0 152 /**
aoqi@0 153 * Allows derived classes to pass their own implementation of PolicySourceModelCreator
aoqi@0 154 * into the PolicyModelGenerator instance.
aoqi@0 155 */
aoqi@0 156 protected static class PolicySourceModelCreator {
aoqi@0 157
aoqi@0 158 /**
aoqi@0 159 * Create an instance of the PolicySourceModel.
aoqi@0 160 *
aoqi@0 161 * @param policy The policy that underlies the created PolicySourceModel.
aoqi@0 162 * @return An instance of the PolicySourceModel.
aoqi@0 163 */
aoqi@0 164 protected PolicySourceModel create(final Policy policy) {
aoqi@0 165 return PolicySourceModel.createPolicySourceModel(policy.getNamespaceVersion(),
aoqi@0 166 policy.getId(), policy.getName());
aoqi@0 167 }
aoqi@0 168
aoqi@0 169 }
aoqi@0 170
aoqi@0 171 }

mercurial