src/share/jaxws_classes/com/sun/xml/internal/ws/api/config/management/policy/ManagementAssertion.java

Tue, 09 Apr 2013 14:51:13 +0100

author
alanb
date
Tue, 09 Apr 2013 14:51:13 +0100
changeset 368
0989ad8c0860
parent 286
f50545b5e2f1
child 637
9c07ef4934dd
permissions
-rw-r--r--

8010393: Update JAX-WS RI to 2.2.9-b12941
Reviewed-by: alanb, erikj
Contributed-by: miroslav.kos@oracle.com, martin.grebac@oracle.com

ohair@286 1 /*
alanb@368 2 * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
ohair@286 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
ohair@286 4 *
ohair@286 5 * This code is free software; you can redistribute it and/or modify it
ohair@286 6 * under the terms of the GNU General Public License version 2 only, as
ohair@286 7 * published by the Free Software Foundation. Oracle designates this
ohair@286 8 * particular file as subject to the "Classpath" exception as provided
ohair@286 9 * by Oracle in the LICENSE file that accompanied this code.
ohair@286 10 *
ohair@286 11 * This code is distributed in the hope that it will be useful, but WITHOUT
ohair@286 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ohair@286 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
ohair@286 14 * version 2 for more details (a copy is included in the LICENSE file that
ohair@286 15 * accompanied this code).
ohair@286 16 *
ohair@286 17 * You should have received a copy of the GNU General Public License version
ohair@286 18 * 2 along with this work; if not, write to the Free Software Foundation,
ohair@286 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
ohair@286 20 *
ohair@286 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ohair@286 22 * or visit www.oracle.com if you need additional information or have any
ohair@286 23 * questions.
ohair@286 24 */
ohair@286 25
ohair@286 26 package com.sun.xml.internal.ws.api.config.management.policy;
ohair@286 27
ohair@286 28 import com.sun.istack.internal.logging.Logger;
ohair@286 29 import com.sun.xml.internal.ws.policy.AssertionSet;
ohair@286 30 import com.sun.xml.internal.ws.policy.Policy;
ohair@286 31 import com.sun.xml.internal.ws.policy.PolicyAssertion;
ohair@286 32 import com.sun.xml.internal.ws.policy.PolicyException;
ohair@286 33 import com.sun.xml.internal.ws.policy.PolicyMap;
ohair@286 34 import com.sun.xml.internal.ws.policy.PolicyMapKey;
ohair@286 35 import com.sun.xml.internal.ws.policy.SimpleAssertion;
ohair@286 36 import com.sun.xml.internal.ws.policy.sourcemodel.AssertionData;
ohair@286 37 import com.sun.xml.internal.ws.policy.spi.AssertionCreationException;
ohair@286 38 import com.sun.xml.internal.ws.resources.ManagementMessages;
ohair@286 39
ohair@286 40 import java.util.Collection;
ohair@286 41 import java.util.Iterator;
ohair@286 42 import javax.xml.namespace.QName;
ohair@286 43 import javax.xml.ws.WebServiceException;
ohair@286 44
ohair@286 45 /**
ohair@286 46 * Base class for the #ManagedClientAssertion and #ManagedServiceAssertion. Provides
ohair@286 47 * convenience methods to directly access the policy assertion parameters.
ohair@286 48 *
ohair@286 49 * @author Fabian Ritzmann
ohair@286 50 */
ohair@286 51 public abstract class ManagementAssertion extends SimpleAssertion {
ohair@286 52
ohair@286 53 /**
ohair@286 54 * To be able to distinguish between explicit settings and no setting.
ohair@286 55 */
ohair@286 56 public static enum Setting { NOT_SET, OFF, ON }
ohair@286 57
ohair@286 58 /**
ohair@286 59 * The name of the management attribute.
ohair@286 60 */
ohair@286 61 protected static final QName MANAGEMENT_ATTRIBUTE_QNAME = new QName("management");
ohair@286 62 /**
ohair@286 63 * The name of the monitoring attribute.
ohair@286 64 */
ohair@286 65 protected static final QName MONITORING_ATTRIBUTE_QNAME = new QName("monitoring");
ohair@286 66
ohair@286 67 /**
ohair@286 68 * The name of the id attribute.
ohair@286 69 */
ohair@286 70 private static final QName ID_ATTRIBUTE_QNAME = new QName("id");
ohair@286 71 /**
ohair@286 72 * The name of the start attribute.
ohair@286 73 */
ohair@286 74 private static final QName START_ATTRIBUTE_QNAME = new QName("start");
ohair@286 75
ohair@286 76 private static final Logger LOGGER = Logger.getLogger(ManagementAssertion.class);
ohair@286 77
ohair@286 78 /**
ohair@286 79 * Return ManagementAssertion if one can be found in the policy map under
ohair@286 80 * the given service and port name.
ohair@286 81 *
ohair@286 82 * @param <T> The implementation class of the assertion.
ohair@286 83 * @param name The fully qualified name of the server or client assertion.
ohair@286 84 * @param policyMap The policy map. May be null.
ohair@286 85 * @param serviceName The WSDL service name. May not be null.
ohair@286 86 * @param portName The WSDL port name. May not be null.
ohair@286 87 * @param type The implementation class of the assertion.
ohair@286 88 * @return An instance of ManagementAssertion or null.
ohair@286 89 * @throws WebServiceException If computing the effective policy of the endpoint scope failed.
ohair@286 90 */
ohair@286 91 protected static <T extends ManagementAssertion> T getAssertion(final QName name,
ohair@286 92 final PolicyMap policyMap, QName serviceName, QName portName, Class<T> type)
ohair@286 93 throws WebServiceException {
ohair@286 94 try {
ohair@286 95 PolicyAssertion assertion = null;
ohair@286 96 if (policyMap != null) {
ohair@286 97 final PolicyMapKey key = PolicyMap.createWsdlEndpointScopeKey(serviceName, portName);
ohair@286 98 final Policy policy = policyMap.getEndpointEffectivePolicy(key);
ohair@286 99 if (policy != null) {
ohair@286 100 final Iterator<AssertionSet> assertionSets = policy.iterator();
ohair@286 101 if (assertionSets.hasNext()) {
ohair@286 102 final AssertionSet assertionSet = assertionSets.next();
ohair@286 103 final Iterator<PolicyAssertion> assertions = assertionSet.get(name).iterator();
ohair@286 104 if (assertions.hasNext()) {
ohair@286 105 assertion = assertions.next();
ohair@286 106 }
ohair@286 107 }
ohair@286 108 }
ohair@286 109 }
ohair@286 110 return assertion == null ? null : assertion.getImplementation(type);
ohair@286 111 } catch (PolicyException ex) {
ohair@286 112 throw LOGGER.logSevereException(new WebServiceException(
ohair@286 113 ManagementMessages.WSM_1001_FAILED_ASSERTION(name), ex));
ohair@286 114 }
ohair@286 115 }
ohair@286 116
ohair@286 117 /**
ohair@286 118 * Create a new ManagementAssertion instance.
ohair@286 119 *
ohair@286 120 * @param name The fully qualified name of the server or client assertion. Must
ohair@286 121 * not be null.
ohair@286 122 * @param data The assertion data. Must not be null.
ohair@286 123 * @param assertionParameters Parameters of the assertion. May be null.
ohair@286 124 * @throws AssertionCreationException Thrown if the creation of the assertion failed.
ohair@286 125 */
ohair@286 126 protected ManagementAssertion(final QName name, AssertionData data, Collection<PolicyAssertion> assertionParameters)
ohair@286 127 throws AssertionCreationException {
ohair@286 128 super(data, assertionParameters);
ohair@286 129 if (!name.equals(data.getName())) {
ohair@286 130 throw LOGGER.logSevereException(new AssertionCreationException(data,
ohair@286 131 ManagementMessages.WSM_1002_EXPECTED_MANAGEMENT_ASSERTION(name)));
ohair@286 132 }
ohair@286 133 if (isManagementEnabled() && !data.containsAttribute(ID_ATTRIBUTE_QNAME)) {
ohair@286 134 throw LOGGER.logSevereException(new AssertionCreationException(data,
ohair@286 135 ManagementMessages.WSM_1003_MANAGEMENT_ASSERTION_MISSING_ID(name)));
ohair@286 136 }
ohair@286 137 }
ohair@286 138
ohair@286 139 /**
ohair@286 140 * Returns the value of the id attribute. May not be null.
ohair@286 141 *
ohair@286 142 * @return The value of the id attribute.
ohair@286 143 */
ohair@286 144 public String getId() {
ohair@286 145 return this.getAttributeValue((ID_ATTRIBUTE_QNAME));
ohair@286 146 }
ohair@286 147
ohair@286 148 /**
ohair@286 149 * Returns the value of the start attribute. May be null.
ohair@286 150 *
ohair@286 151 * @return The value of the start attribute.
ohair@286 152 */
ohair@286 153 public String getStart() {
ohair@286 154 return this.getAttributeValue((START_ATTRIBUTE_QNAME));
ohair@286 155 }
ohair@286 156
ohair@286 157 /**
ohair@286 158 * Returns the value of the managment attribute depending on whether this is
ohair@286 159 * a client-side or server-side assertion.
ohair@286 160 *
ohair@286 161 * @return The value of the managment attribute.
ohair@286 162 */
ohair@286 163 public abstract boolean isManagementEnabled();
ohair@286 164
ohair@286 165 /**
ohair@286 166 * Returns the value of the monitoring attribute.
ohair@286 167 *
ohair@286 168 * @return The value of the monitoring attribute.
ohair@286 169 */
ohair@286 170 public Setting monitoringAttribute() {
ohair@286 171 final String monitoring = this.getAttributeValue(MONITORING_ATTRIBUTE_QNAME);
ohair@286 172 Setting result = Setting.NOT_SET;
ohair@286 173 if (monitoring != null) {
ohair@286 174 if (monitoring.trim().toLowerCase().equals("on")
ohair@286 175 || Boolean.parseBoolean(monitoring)) {
ohair@286 176 result = Setting.ON;
ohair@286 177 }
ohair@286 178 else {
ohair@286 179 result = Setting.OFF;
ohair@286 180 }
ohair@286 181 }
ohair@286 182 return result;
ohair@286 183 }
ohair@286 184
ohair@286 185 }

mercurial