|
Java example source code file (AssertionData.java)
The AssertionData.java Java example source code/* * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package com.sun.xml.internal.ws.policy.sourcemodel; import com.sun.xml.internal.ws.policy.PolicyConstants; import com.sun.xml.internal.ws.policy.privateutil.LocalizationMessages; import com.sun.xml.internal.ws.policy.privateutil.PolicyLogger; import com.sun.xml.internal.ws.policy.privateutil.PolicyUtils; import java.io.Serializable; import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Set; import javax.xml.namespace.QName; /** * Wrapper class for possible data that each "assertion" and "assertion parameter content" policy source model node may * have attached. * <p/> * This data, when stored in an 'assertion' model node, is intended to be used as input parameter when creating * {@link com.sun.xml.internal.ws.policy.PolicyAssertion} objects via {@link com.sun.xml.internal.ws.policy.spi.PolicyAssertionCreator} * implementations. * * @author Marek Potociar (marek.potociar@sun.com) * @author Fabian Ritzmann */ public final class AssertionData implements Cloneable, Serializable { private static final long serialVersionUID = 4416256070795526315L; private static final PolicyLogger LOGGER = PolicyLogger.getLogger(AssertionData.class); private final QName name; private final String value; private final Map<QName, String> attributes; private ModelNode.Type type; private boolean optional; private boolean ignorable; /** * Constructs assertion data wrapper instance for an assertion that does not * contain any value nor any attributes. * * @param name the FQN of the assertion * * @throws IllegalArgumentException in case the {@code type} parameter is not * {@link ModelNode.Type#ASSERTION ASSERTION} or * {@link ModelNode.Type#ASSERTION_PARAMETER_NODE ASSERTION_PARAMETER_NODE} */ public static AssertionData createAssertionData(final QName name) throws IllegalArgumentException { return new AssertionData(name, null, null, ModelNode.Type.ASSERTION, false, false); } /** * Constructs assertion data wrapper instance for an assertion parameter that * does not contain any value nor any attributes. * * @param name the FQN of the assertion parameter * * @throws IllegalArgumentException in case the {@code type} parameter is not * {@link ModelNode.Type#ASSERTION ASSERTION} or * {@link ModelNode.Type#ASSERTION_PARAMETER_NODE ASSERTION_PARAMETER_NODE} */ public static AssertionData createAssertionParameterData(final QName name) throws IllegalArgumentException { return new AssertionData(name, null, null, ModelNode.Type.ASSERTION_PARAMETER_NODE, false, false); } /** * Constructs assertion data wrapper instance for an assertion that does * contain a value or attributes. * * @param name the FQN of the assertion * @param value a {@link String} representation of model node value * @param attributes map of model node's <attribute name, attribute value> pairs * @param optional flag indicating whether the assertion is optional or not * @param ignorable flag indicating whether the assertion is ignorable or not * * @throws IllegalArgumentException in case the {@code type} parameter is not * {@link ModelNode.Type#ASSERTION ASSERTION} or * {@link ModelNode.Type#ASSERTION_PARAMETER_NODE ASSERTION_PARAMETER_NODE} */ public static AssertionData createAssertionData(final QName name, final String value, final Map<QName, String> attributes, boolean optional, boolean ignorable) throws IllegalArgumentException { return new AssertionData(name, value, attributes, ModelNode.Type.ASSERTION, optional, ignorable); } /** * Constructs assertion data wrapper instance for an assertion parameter that * contains a value or attributes * * @param name the FQN of the assertion parameter * @param value a {@link String} representation of model node value * @param attributes map of model node's <attribute name, attribute value> pairs * * @throws IllegalArgumentException in case the {@code type} parameter is not * {@link ModelNode.Type#ASSERTION ASSERTION} or * {@link ModelNode.Type#ASSERTION_PARAMETER_NODE ASSERTION_PARAMETER_NODE} */ public static AssertionData createAssertionParameterData(final QName name, final String value, final Map<QName, String> attributes) throws IllegalArgumentException { return new AssertionData(name, value, attributes, ModelNode.Type.ASSERTION_PARAMETER_NODE, false, false); } /** * Constructs assertion data wrapper instance for an assertion or assertion parameter that contains a value or * some attributes. Whether the data wrapper is constructed for assertion or assertion parameter node is distinguished by * the supplied {@code type} parameter. * * @param name the FQN of the assertion or assertion parameter * @param value a {@link String} representation of model node value * @param attributes map of model node's <attribute name, attribute value> pairs * @param type specifies whether the data will belong to the assertion or assertion parameter node. This is * a workaround solution that allows us to transfer this information about the owner node to * a policy assertion instance factory without actualy having to touch the {@link PolicyAssertionCreator} * interface and protected {@link PolicyAssertion} constructors. * * @throws IllegalArgumentException in case the {@code type} parameter is not * {@link ModelNode.Type#ASSERTION ASSERTION} or * {@link ModelNode.Type#ASSERTION_PARAMETER_NODE ASSERTION_PARAMETER_NODE} */ AssertionData(QName name, String value, Map<QName, String> attributes, ModelNode.Type type, boolean optional, boolean ignorable) throws IllegalArgumentException { this.name = name; this.value = value; this.optional = optional; this.ignorable = ignorable; this.attributes = new HashMap<QName, String>(); if (attributes != null && !attributes.isEmpty()) { this.attributes.putAll(attributes); } setModelNodeType(type); } private void setModelNodeType(final ModelNode.Type type) throws IllegalArgumentException { if (type == ModelNode.Type.ASSERTION || type == ModelNode.Type.ASSERTION_PARAMETER_NODE) { this.type = type; } else { throw LOGGER.logSevereException(new IllegalArgumentException( LocalizationMessages.WSP_0074_CANNOT_CREATE_ASSERTION_BAD_TYPE(type, ModelNode.Type.ASSERTION, ModelNode.Type.ASSERTION_PARAMETER_NODE))); } } /** * Copy constructor. * * @param data The instance that is to be copied. */ AssertionData(final AssertionData data) { this.name = data.name; this.value = data.value; this.attributes = new HashMap<QName, String>(); if (!data.attributes.isEmpty()) { this.attributes.putAll(data.attributes); } this.type = data.type; } @Override protected AssertionData clone() throws CloneNotSupportedException { return (AssertionData) super.clone(); } /** * Returns true if the given attribute exists, false otherwise. * * @param name The name of the attribute. Must not be null. * @return True if the given attribute exists, false otherwise. */ public boolean containsAttribute(final QName name) { synchronized (attributes) { return attributes.containsKey(name); } } @Override public boolean equals(final Object obj) { if (this == obj) { return true; } if (!(obj instanceof AssertionData)) { return false; } boolean result = true; final AssertionData that = (AssertionData) obj; result = result && this.name.equals(that.name); result = result && ((this.value == null) ? that.value == null : this.value.equals(that.value)); synchronized (attributes) { result = result && this.attributes.equals(that.attributes); } return result; } /** * Returns the value of the given attribute. Returns null if the attribute * does not exist. * * @param name The name of the attribute. Must not be null. * @return The value of the given attribute. Returns null if the attribute * does not exist. */ public String getAttributeValue(final QName name) { synchronized (attributes) { return attributes.get(name); } } /** * Returns the disconnected map of attributes attached to the assertion. * <p/> * 'Disconnected' means, that the result of this method will not be synchronized with any consequent assertion's attribute modification. It is * also important to notice that a manipulation with returned set of attributes will not have any effect on the actual assertion's * attributes. * * @return disconnected map of attributes attached to the assertion. */ public Map<QName, String> getAttributes() { synchronized (attributes) { return new HashMap<QName, String>(attributes); } } /** * Returns the disconnected set of attributes attached to the assertion. Each attribute is represented as a single * {@code Map.Entry<attributeName, attributeValue>} element. * <p/> * 'Disconnected' means, that the result of this method will not be synchronized with any consequent assertion's attribute modification. It is * also important to notice that a manipulation with returned set of attributes will not have any effect on the actual assertion's * attributes. * * @return disconnected set of attributes attached to the assertion. */ public Set<Map.Entry Other Java examples (source code examples)Here is a short list of links related to this Java AssertionData.java source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.