Thu, 12 Oct 2017 19:44:07 +0800
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.sourcemodel.wspolicy.NamespaceVersion; |
aoqi@0 | 29 | import com.sun.xml.internal.ws.policy.PolicyConstants; |
aoqi@0 | 30 | import com.sun.xml.internal.ws.policy.PolicyException; |
aoqi@0 | 31 | import com.sun.xml.internal.ws.policy.privateutil.LocalizationMessages; |
aoqi@0 | 32 | import com.sun.xml.internal.ws.policy.privateutil.PolicyLogger; |
aoqi@0 | 33 | import com.sun.xml.internal.ws.policy.privateutil.PolicyUtils; |
aoqi@0 | 34 | import com.sun.xml.internal.ws.policy.spi.PrefixMapper; |
aoqi@0 | 35 | |
aoqi@0 | 36 | import java.util.Collection; |
aoqi@0 | 37 | import java.util.HashMap; |
aoqi@0 | 38 | import java.util.HashSet; |
aoqi@0 | 39 | import java.util.LinkedList; |
aoqi@0 | 40 | import java.util.List; |
aoqi@0 | 41 | import java.util.Map; |
aoqi@0 | 42 | import java.util.Map.Entry; |
aoqi@0 | 43 | import java.util.Queue; |
aoqi@0 | 44 | import java.util.Set; |
aoqi@0 | 45 | import javax.xml.namespace.QName; |
aoqi@0 | 46 | |
aoqi@0 | 47 | /** |
aoqi@0 | 48 | * This class is a root of unmarshaled policy source structure. Each instance of the class contains factory method |
aoqi@0 | 49 | * to create new {@link com.sun.xml.internal.ws.policy.sourcemodel.ModelNode} instances associated with the actual model instance. |
aoqi@0 | 50 | * |
aoqi@0 | 51 | * @author Marek Potociar |
aoqi@0 | 52 | * @author Fabian Ritzmann |
aoqi@0 | 53 | */ |
aoqi@0 | 54 | public class PolicySourceModel implements Cloneable { |
aoqi@0 | 55 | |
aoqi@0 | 56 | private static final PolicyLogger LOGGER = PolicyLogger.getLogger(PolicySourceModel.class); |
aoqi@0 | 57 | |
aoqi@0 | 58 | private static final Map<String, String> DEFAULT_NAMESPACE_TO_PREFIX = new HashMap<String, String>(); |
aoqi@0 | 59 | static { |
aoqi@0 | 60 | PrefixMapper[] prefixMappers = PolicyUtils.ServiceProvider.load(PrefixMapper.class); |
aoqi@0 | 61 | if (prefixMappers != null) { |
aoqi@0 | 62 | for (PrefixMapper mapper: prefixMappers) { |
aoqi@0 | 63 | DEFAULT_NAMESPACE_TO_PREFIX.putAll(mapper.getPrefixMap()); |
aoqi@0 | 64 | } |
aoqi@0 | 65 | } |
aoqi@0 | 66 | |
aoqi@0 | 67 | for (NamespaceVersion version : NamespaceVersion.values()) { |
aoqi@0 | 68 | DEFAULT_NAMESPACE_TO_PREFIX.put(version.toString(), version.getDefaultNamespacePrefix()); |
aoqi@0 | 69 | } |
aoqi@0 | 70 | DEFAULT_NAMESPACE_TO_PREFIX.put(PolicyConstants.WSU_NAMESPACE_URI, |
aoqi@0 | 71 | PolicyConstants.WSU_NAMESPACE_PREFIX); |
aoqi@0 | 72 | DEFAULT_NAMESPACE_TO_PREFIX.put(PolicyConstants.SUN_POLICY_NAMESPACE_URI, |
aoqi@0 | 73 | PolicyConstants.SUN_POLICY_NAMESPACE_PREFIX); |
aoqi@0 | 74 | } |
aoqi@0 | 75 | |
aoqi@0 | 76 | // Map namespaces to prefixes |
aoqi@0 | 77 | private final Map<String, String> namespaceToPrefix = |
aoqi@0 | 78 | new HashMap<String, String>(DEFAULT_NAMESPACE_TO_PREFIX); |
aoqi@0 | 79 | |
aoqi@0 | 80 | private ModelNode rootNode; |
aoqi@0 | 81 | private final String policyId; |
aoqi@0 | 82 | private final String policyName; |
aoqi@0 | 83 | private final NamespaceVersion nsVersion; |
aoqi@0 | 84 | private final List<ModelNode> references = new LinkedList<ModelNode>(); // links to policy reference nodes |
aoqi@0 | 85 | private boolean expanded = false; |
aoqi@0 | 86 | |
aoqi@0 | 87 | |
aoqi@0 | 88 | /** |
aoqi@0 | 89 | * Factory method that creates new policy source model instance. |
aoqi@0 | 90 | * |
aoqi@0 | 91 | * This method is only intended to be used by code that has no dependencies on |
aoqi@0 | 92 | * JAX-WS. Otherwise use com.sun.xml.internal.ws.policy.api.SourceModel. |
aoqi@0 | 93 | * |
aoqi@0 | 94 | * @param nsVersion The policy version |
aoqi@0 | 95 | * @return Newly created policy source model instance. |
aoqi@0 | 96 | */ |
aoqi@0 | 97 | public static PolicySourceModel createPolicySourceModel(final NamespaceVersion nsVersion) { |
aoqi@0 | 98 | return new PolicySourceModel(nsVersion); |
aoqi@0 | 99 | } |
aoqi@0 | 100 | |
aoqi@0 | 101 | /** |
aoqi@0 | 102 | * Factory method that creates new policy source model instance and initializes it according to parameters provided. |
aoqi@0 | 103 | * |
aoqi@0 | 104 | * This method is only intended to be used by code that has no dependencies on |
aoqi@0 | 105 | * JAX-WS. Otherwise use com.sun.xml.internal.ws.policy.api.SourceModel. |
aoqi@0 | 106 | * |
aoqi@0 | 107 | * @param nsVersion The policy version |
aoqi@0 | 108 | * @param policyId local policy identifier - relative URI. May be {@code null}. |
aoqi@0 | 109 | * @param policyName global policy identifier - absolute policy expression URI. May be {@code null}. |
aoqi@0 | 110 | * @return Newly created policy source model instance with its name and id properly set. |
aoqi@0 | 111 | */ |
aoqi@0 | 112 | public static PolicySourceModel createPolicySourceModel(final NamespaceVersion nsVersion, final String policyId, final String policyName) { |
aoqi@0 | 113 | return new PolicySourceModel(nsVersion, policyId, policyName); |
aoqi@0 | 114 | } |
aoqi@0 | 115 | |
aoqi@0 | 116 | /** |
aoqi@0 | 117 | * Constructor that creates a new policy source model instance without any |
aoqi@0 | 118 | * id or name identifier. The namespace-to-prefix map is initialized with mapping |
aoqi@0 | 119 | * of policy namespace to the default value set by |
aoqi@0 | 120 | * {@link PolicyConstants#POLICY_NAMESPACE_PREFIX POLICY_NAMESPACE_PREFIX constant}. |
aoqi@0 | 121 | * |
aoqi@0 | 122 | * @param nsVersion The WS-Policy version. |
aoqi@0 | 123 | */ |
aoqi@0 | 124 | private PolicySourceModel(NamespaceVersion nsVersion) { |
aoqi@0 | 125 | this(nsVersion, null, null); |
aoqi@0 | 126 | } |
aoqi@0 | 127 | |
aoqi@0 | 128 | /** |
aoqi@0 | 129 | * Constructor that creates a new policy source model instance with given |
aoqi@0 | 130 | * id or name identifier. |
aoqi@0 | 131 | * |
aoqi@0 | 132 | * @param nsVersion The WS-Policy version. |
aoqi@0 | 133 | * @param policyId Relative policy reference within an XML document. May be {@code null}. |
aoqi@0 | 134 | * @param policyName Absolute IRI of policy expression. May be {@code null}. |
aoqi@0 | 135 | */ |
aoqi@0 | 136 | private PolicySourceModel(NamespaceVersion nsVersion, String policyId, String policyName) { |
aoqi@0 | 137 | this(nsVersion, policyId, policyName, null); |
aoqi@0 | 138 | } |
aoqi@0 | 139 | |
aoqi@0 | 140 | /** |
aoqi@0 | 141 | * Constructor that creates a new policy source model instance with given |
aoqi@0 | 142 | * id or name identifier and a set of PrefixMappers. |
aoqi@0 | 143 | * |
aoqi@0 | 144 | * This constructor is intended to be used by the JAX-WS com.sun.xml.internal.ws.policy.api.SourceModel. |
aoqi@0 | 145 | * |
aoqi@0 | 146 | * @param nsVersion The WS-Policy version. |
aoqi@0 | 147 | * @param policyId Relative policy reference within an XML document. May be {@code null}. |
aoqi@0 | 148 | * @param policyName Absolute IRI of policy expression. May be {@code null}. |
aoqi@0 | 149 | * @param prefixMappers A collection of PrefixMappers to be used with this instance. May be {@code null}. |
aoqi@0 | 150 | */ |
aoqi@0 | 151 | protected PolicySourceModel(NamespaceVersion nsVersion, String policyId, |
aoqi@0 | 152 | String policyName, Collection<PrefixMapper> prefixMappers) { |
aoqi@0 | 153 | this.rootNode = ModelNode.createRootPolicyNode(this); |
aoqi@0 | 154 | this.nsVersion = nsVersion; |
aoqi@0 | 155 | this.policyId = policyId; |
aoqi@0 | 156 | this.policyName = policyName; |
aoqi@0 | 157 | if (prefixMappers != null) { |
aoqi@0 | 158 | for (PrefixMapper prefixMapper : prefixMappers) { |
aoqi@0 | 159 | this.namespaceToPrefix.putAll(prefixMapper.getPrefixMap()); |
aoqi@0 | 160 | } |
aoqi@0 | 161 | } |
aoqi@0 | 162 | } |
aoqi@0 | 163 | |
aoqi@0 | 164 | /** |
aoqi@0 | 165 | * Returns a root node of this policy source model. It is allways of POLICY type. |
aoqi@0 | 166 | * |
aoqi@0 | 167 | * @return root policy source model node - allways of POLICY type. |
aoqi@0 | 168 | */ |
aoqi@0 | 169 | public ModelNode getRootNode() { |
aoqi@0 | 170 | return rootNode; |
aoqi@0 | 171 | } |
aoqi@0 | 172 | |
aoqi@0 | 173 | /** |
aoqi@0 | 174 | * Returns a policy name of this policy source model. |
aoqi@0 | 175 | * |
aoqi@0 | 176 | * @return policy name. |
aoqi@0 | 177 | */ |
aoqi@0 | 178 | public String getPolicyName() { |
aoqi@0 | 179 | return policyName; |
aoqi@0 | 180 | } |
aoqi@0 | 181 | |
aoqi@0 | 182 | /** |
aoqi@0 | 183 | * Returns a policy ID of this policy source model. |
aoqi@0 | 184 | * |
aoqi@0 | 185 | * @return policy ID. |
aoqi@0 | 186 | */ |
aoqi@0 | 187 | public String getPolicyId() { |
aoqi@0 | 188 | return policyId; |
aoqi@0 | 189 | } |
aoqi@0 | 190 | |
aoqi@0 | 191 | /** |
aoqi@0 | 192 | * Returns an original namespace version of this policy source model. |
aoqi@0 | 193 | * |
aoqi@0 | 194 | * @return namespace version. |
aoqi@0 | 195 | */ |
aoqi@0 | 196 | public NamespaceVersion getNamespaceVersion() { |
aoqi@0 | 197 | return nsVersion; |
aoqi@0 | 198 | } |
aoqi@0 | 199 | |
aoqi@0 | 200 | /** |
aoqi@0 | 201 | * Provides information about how namespaces used in this {@link PolicySourceModel} |
aoqi@0 | 202 | * instance should be mapped to their default prefixes when marshalled. |
aoqi@0 | 203 | * |
aoqi@0 | 204 | * @return immutable map that holds information about namespaces used in the |
aoqi@0 | 205 | * model and their mapping to prefixes that should be used when marshalling |
aoqi@0 | 206 | * this model. |
aoqi@0 | 207 | * @throws PolicyException Thrown if one of the prefix mappers threw an exception. |
aoqi@0 | 208 | */ |
aoqi@0 | 209 | Map<String, String> getNamespaceToPrefixMapping() throws PolicyException { |
aoqi@0 | 210 | final Map<String, String> nsToPrefixMap = new HashMap<String, String>(); |
aoqi@0 | 211 | |
aoqi@0 | 212 | final Collection<String> namespaces = getUsedNamespaces(); |
aoqi@0 | 213 | for (String namespace : namespaces) { |
aoqi@0 | 214 | final String prefix = getDefaultPrefix(namespace); |
aoqi@0 | 215 | if (prefix != null) { |
aoqi@0 | 216 | nsToPrefixMap.put(namespace, prefix); |
aoqi@0 | 217 | } |
aoqi@0 | 218 | } |
aoqi@0 | 219 | |
aoqi@0 | 220 | return nsToPrefixMap; |
aoqi@0 | 221 | } |
aoqi@0 | 222 | |
aoqi@0 | 223 | /** |
aoqi@0 | 224 | * An {@code Object.equals(Object obj)} method override. |
aoqi@0 | 225 | * <p/> |
aoqi@0 | 226 | * When child nodes are tested for equality, the parent policy source model is not considered. Thus two different |
aoqi@0 | 227 | * policy source models instances may be equal based on their node content. |
aoqi@0 | 228 | */ |
aoqi@0 | 229 | @Override |
aoqi@0 | 230 | public boolean equals(final Object obj) { |
aoqi@0 | 231 | if (this == obj) { |
aoqi@0 | 232 | return true; |
aoqi@0 | 233 | } |
aoqi@0 | 234 | |
aoqi@0 | 235 | if (!(obj instanceof PolicySourceModel)) { |
aoqi@0 | 236 | return false; |
aoqi@0 | 237 | } |
aoqi@0 | 238 | |
aoqi@0 | 239 | boolean result = true; |
aoqi@0 | 240 | final PolicySourceModel that = (PolicySourceModel) obj; |
aoqi@0 | 241 | |
aoqi@0 | 242 | result = result && ((this.policyId == null) ? that.policyId == null : this.policyId.equals(that.policyId)); |
aoqi@0 | 243 | result = result && ((this.policyName == null) ? that.policyName == null : this.policyName.equals(that.policyName)); |
aoqi@0 | 244 | result = result && this.rootNode.equals(that.rootNode); |
aoqi@0 | 245 | |
aoqi@0 | 246 | return result; |
aoqi@0 | 247 | } |
aoqi@0 | 248 | |
aoqi@0 | 249 | /** |
aoqi@0 | 250 | * An {@code Object.hashCode()} method override. |
aoqi@0 | 251 | */ |
aoqi@0 | 252 | @Override |
aoqi@0 | 253 | public int hashCode() { |
aoqi@0 | 254 | int result = 17; |
aoqi@0 | 255 | |
aoqi@0 | 256 | result = 37 * result + ((this.policyId == null) ? 0 : this.policyId.hashCode()); |
aoqi@0 | 257 | result = 37 * result + ((this.policyName == null) ? 0 : this.policyName.hashCode()); |
aoqi@0 | 258 | result = 37 * result + this.rootNode.hashCode(); |
aoqi@0 | 259 | |
aoqi@0 | 260 | return result; |
aoqi@0 | 261 | } |
aoqi@0 | 262 | |
aoqi@0 | 263 | /** |
aoqi@0 | 264 | * Returns a string representation of the object. In general, the <code>toString</code> method |
aoqi@0 | 265 | * returns a string that "textually represents" this object. |
aoqi@0 | 266 | * |
aoqi@0 | 267 | * @return a string representation of the object. |
aoqi@0 | 268 | */ |
aoqi@0 | 269 | @Override |
aoqi@0 | 270 | public String toString() { |
aoqi@0 | 271 | final String innerIndent = PolicyUtils.Text.createIndent(1); |
aoqi@0 | 272 | final StringBuffer buffer = new StringBuffer(60); |
aoqi@0 | 273 | |
aoqi@0 | 274 | buffer.append("Policy source model {").append(PolicyUtils.Text.NEW_LINE); |
aoqi@0 | 275 | buffer.append(innerIndent).append("policy id = '").append(policyId).append('\'').append(PolicyUtils.Text.NEW_LINE); |
aoqi@0 | 276 | buffer.append(innerIndent).append("policy name = '").append(policyName).append('\'').append(PolicyUtils.Text.NEW_LINE); |
aoqi@0 | 277 | rootNode.toString(1, buffer).append(PolicyUtils.Text.NEW_LINE).append('}'); |
aoqi@0 | 278 | |
aoqi@0 | 279 | return buffer.toString(); |
aoqi@0 | 280 | } |
aoqi@0 | 281 | |
aoqi@0 | 282 | @Override |
aoqi@0 | 283 | protected PolicySourceModel clone() throws CloneNotSupportedException { |
aoqi@0 | 284 | final PolicySourceModel clone = (PolicySourceModel) super.clone(); |
aoqi@0 | 285 | |
aoqi@0 | 286 | clone.rootNode = this.rootNode.clone(); |
aoqi@0 | 287 | try { |
aoqi@0 | 288 | clone.rootNode.setParentModel(clone); |
aoqi@0 | 289 | } catch (IllegalAccessException e) { |
aoqi@0 | 290 | throw LOGGER.logSevereException(new CloneNotSupportedException(LocalizationMessages.WSP_0013_UNABLE_TO_SET_PARENT_MODEL_ON_ROOT()), e); |
aoqi@0 | 291 | } |
aoqi@0 | 292 | |
aoqi@0 | 293 | return clone; |
aoqi@0 | 294 | } |
aoqi@0 | 295 | |
aoqi@0 | 296 | /** |
aoqi@0 | 297 | * Returns a boolean value indicating whether this policy source model contains references to another policy source models. |
aoqi@0 | 298 | * <p/> |
aoqi@0 | 299 | * Every source model that references other policies must be expanded before it can be translated into a Policy objects. See |
aoqi@0 | 300 | * {@link #expand(PolicySourceModelContext)} and {@link #isExpanded()} for more details. |
aoqi@0 | 301 | * |
aoqi@0 | 302 | * @return {@code true} or {code false} depending on whether this policy source model contains references to another policy source models. |
aoqi@0 | 303 | */ |
aoqi@0 | 304 | public boolean containsPolicyReferences() { |
aoqi@0 | 305 | return !references.isEmpty(); |
aoqi@0 | 306 | } |
aoqi@0 | 307 | |
aoqi@0 | 308 | /** |
aoqi@0 | 309 | * Returns a boolean value indicating whether this policy source model contains is already expanded (i.e. contains no unexpanded |
aoqi@0 | 310 | * policy references) or not. This means that if model does not originally contain any policy references, it is considered as expanded, |
aoqi@0 | 311 | * thus this method returns {@code true} in such case. Also this method does not check whether the references policy source models are expanded |
aoqi@0 | 312 | * as well, so after expanding this model a value of {@code true} is returned even if referenced models are not expanded yet. Thus each model |
aoqi@0 | 313 | * can be considered to be fully expanded only if all policy source models stored in PolicySourceModelContext instance are expanded, provided the |
aoqi@0 | 314 | * PolicySourceModelContext instance contains full set of policy source models. |
aoqi@0 | 315 | * <p/> |
aoqi@0 | 316 | * Every source model that references other policies must be expanded before it can be translated into a Policy object. See |
aoqi@0 | 317 | * {@link #expand(PolicySourceModelContext)} and {@link #containsPolicyReferences()} for more details. |
aoqi@0 | 318 | * |
aoqi@0 | 319 | * @return {@code true} or {@code false} depending on whether this policy source model contains is expanded or not. |
aoqi@0 | 320 | */ |
aoqi@0 | 321 | private boolean isExpanded() { |
aoqi@0 | 322 | return references.isEmpty() || expanded; |
aoqi@0 | 323 | } |
aoqi@0 | 324 | |
aoqi@0 | 325 | /** |
aoqi@0 | 326 | * Expands current policy model. This means, that if this model contains any (unexpanded) policy references, then the method expands those |
aoqi@0 | 327 | * references by placing the content of the referenced policy source models under the policy reference nodes. This operation merely creates |
aoqi@0 | 328 | * a link between this and referenced policy source models. Thus any change in the referenced models will be visible wihtin this model as well. |
aoqi@0 | 329 | * <p/> |
aoqi@0 | 330 | * Please, notice that the method does not check if the referenced models are already expanded nor does the method try to expand unexpanded |
aoqi@0 | 331 | * referenced models. This must be preformed manually within client's code. Consecutive calls of this method will have no effect. |
aoqi@0 | 332 | * <p/> |
aoqi@0 | 333 | * Every source model that references other policies must be expanded before it can be translated into a Policy object. See |
aoqi@0 | 334 | * {@link #isExpanded()} and {@link #containsPolicyReferences()} for more details. |
aoqi@0 | 335 | * |
aoqi@0 | 336 | * @param context a policy source model context holding the set of unmarshalled policy source models within the same context. |
aoqi@0 | 337 | * @throws PolicyException Thrown if a referenced policy could not be resolved |
aoqi@0 | 338 | */ |
aoqi@0 | 339 | public synchronized void expand(final PolicySourceModelContext context) throws PolicyException { |
aoqi@0 | 340 | if (!isExpanded()) { |
aoqi@0 | 341 | for (ModelNode reference : references) { |
aoqi@0 | 342 | final PolicyReferenceData refData = reference.getPolicyReferenceData(); |
aoqi@0 | 343 | final String digest = refData.getDigest(); |
aoqi@0 | 344 | PolicySourceModel referencedModel; |
aoqi@0 | 345 | if (digest == null) { |
aoqi@0 | 346 | referencedModel = context.retrieveModel(refData.getReferencedModelUri()); |
aoqi@0 | 347 | } else { |
aoqi@0 | 348 | referencedModel = context.retrieveModel(refData.getReferencedModelUri(), refData.getDigestAlgorithmUri(), digest); |
aoqi@0 | 349 | } |
aoqi@0 | 350 | |
aoqi@0 | 351 | reference.setReferencedModel(referencedModel); |
aoqi@0 | 352 | } |
aoqi@0 | 353 | expanded = true; |
aoqi@0 | 354 | } |
aoqi@0 | 355 | } |
aoqi@0 | 356 | |
aoqi@0 | 357 | /** |
aoqi@0 | 358 | * Adds new policy reference to the policy source model. The method is used by |
aoqi@0 | 359 | * the ModelNode instances of type POLICY_REFERENCE that need to register themselves |
aoqi@0 | 360 | * as policy references in the model. |
aoqi@0 | 361 | * |
aoqi@0 | 362 | * @param node policy reference model node to be registered as a policy reference |
aoqi@0 | 363 | * in this model. |
aoqi@0 | 364 | */ |
aoqi@0 | 365 | void addNewPolicyReference(final ModelNode node) { |
aoqi@0 | 366 | if (node.getType() != ModelNode.Type.POLICY_REFERENCE) { |
aoqi@0 | 367 | throw new IllegalArgumentException(LocalizationMessages.WSP_0042_POLICY_REFERENCE_NODE_EXPECTED_INSTEAD_OF(node.getType())); |
aoqi@0 | 368 | } |
aoqi@0 | 369 | |
aoqi@0 | 370 | references.add(node); |
aoqi@0 | 371 | } |
aoqi@0 | 372 | |
aoqi@0 | 373 | /** |
aoqi@0 | 374 | * Iterates through policy vocabulary and extracts set of namespaces used in |
aoqi@0 | 375 | * the policy expression. |
aoqi@0 | 376 | * |
aoqi@0 | 377 | * @return collection of used namespaces within given policy instance |
aoqi@0 | 378 | * @throws PolicyException Thrown if internal processing failed. |
aoqi@0 | 379 | */ |
aoqi@0 | 380 | private Collection<String> getUsedNamespaces() throws PolicyException { |
aoqi@0 | 381 | final Set<String> namespaces = new HashSet<String>(); |
aoqi@0 | 382 | namespaces.add(getNamespaceVersion().toString()); |
aoqi@0 | 383 | |
aoqi@0 | 384 | if (this.policyId != null) { |
aoqi@0 | 385 | namespaces.add(PolicyConstants.WSU_NAMESPACE_URI); |
aoqi@0 | 386 | } |
aoqi@0 | 387 | |
aoqi@0 | 388 | final Queue<ModelNode> nodesToBeProcessed = new LinkedList<ModelNode>(); |
aoqi@0 | 389 | nodesToBeProcessed.add(rootNode); |
aoqi@0 | 390 | |
aoqi@0 | 391 | ModelNode processedNode; |
aoqi@0 | 392 | while ((processedNode = nodesToBeProcessed.poll()) != null) { |
aoqi@0 | 393 | for (ModelNode child : processedNode.getChildren()) { |
aoqi@0 | 394 | if (child.hasChildren()) { |
aoqi@0 | 395 | if (!nodesToBeProcessed.offer(child)) { |
aoqi@0 | 396 | throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0081_UNABLE_TO_INSERT_CHILD(nodesToBeProcessed, child))); |
aoqi@0 | 397 | } |
aoqi@0 | 398 | } |
aoqi@0 | 399 | |
aoqi@0 | 400 | if (child.isDomainSpecific()) { |
aoqi@0 | 401 | final AssertionData nodeData = child.getNodeData(); |
aoqi@0 | 402 | namespaces.add(nodeData.getName().getNamespaceURI()); |
aoqi@0 | 403 | if (nodeData.isPrivateAttributeSet()) { |
aoqi@0 | 404 | namespaces.add(PolicyConstants.SUN_POLICY_NAMESPACE_URI); |
aoqi@0 | 405 | } |
aoqi@0 | 406 | |
aoqi@0 | 407 | for (Entry<QName, String> attribute : nodeData.getAttributesSet()) { |
aoqi@0 | 408 | namespaces.add(attribute.getKey().getNamespaceURI()); |
aoqi@0 | 409 | } |
aoqi@0 | 410 | } |
aoqi@0 | 411 | } |
aoqi@0 | 412 | } |
aoqi@0 | 413 | |
aoqi@0 | 414 | return namespaces; |
aoqi@0 | 415 | } |
aoqi@0 | 416 | |
aoqi@0 | 417 | /** |
aoqi@0 | 418 | * Method retrieves default prefix for given namespace. Method returns null if |
aoqi@0 | 419 | * no default prefix is defined.. |
aoqi@0 | 420 | * |
aoqi@0 | 421 | * @param namespace to get default prefix for. |
aoqi@0 | 422 | * @return default prefix for given namespace. May return {@code null} if the |
aoqi@0 | 423 | * default prefix for given namespace is not defined. |
aoqi@0 | 424 | */ |
aoqi@0 | 425 | private String getDefaultPrefix(final String namespace) { |
aoqi@0 | 426 | return namespaceToPrefix.get(namespace); |
aoqi@0 | 427 | } |
aoqi@0 | 428 | } |