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

Tue, 06 Mar 2012 16:09:35 -0800

author
ohair
date
Tue, 06 Mar 2012 16:09:35 -0800
changeset 286
f50545b5e2f1
child 368
0989ad8c0860
permissions
-rw-r--r--

7150322: Stop using drop source bundles in jaxws
Reviewed-by: darcy, ohrstrom

ohair@286 1 /*
ohair@286 2 * Copyright (c) 1997, 2010, 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.api.server.WSEndpoint;
ohair@286 30 import com.sun.xml.internal.ws.policy.PolicyAssertion;
ohair@286 31 import com.sun.xml.internal.ws.policy.PolicyMap;
ohair@286 32 import com.sun.xml.internal.ws.policy.PolicyConstants;
ohair@286 33 import com.sun.xml.internal.ws.policy.sourcemodel.AssertionData;
ohair@286 34 import com.sun.xml.internal.ws.policy.spi.AssertionCreationException;
ohair@286 35 import com.sun.xml.internal.ws.resources.ManagementMessages;
ohair@286 36
ohair@286 37 import java.util.Collection;
ohair@286 38 import java.util.HashMap;
ohair@286 39 import java.util.Iterator;
ohair@286 40 import java.util.LinkedList;
ohair@286 41 import java.util.Map;
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 * The server-side ManagedService policy assertion.
ohair@286 47 *
ohair@286 48 * @author Fabian Ritzmann
ohair@286 49 */
ohair@286 50 public class ManagedServiceAssertion extends ManagementAssertion {
ohair@286 51
ohair@286 52 public static final QName MANAGED_SERVICE_QNAME =
ohair@286 53 new QName(PolicyConstants.SUN_MANAGEMENT_NAMESPACE, "ManagedService");
ohair@286 54
ohair@286 55 private static final QName COMMUNICATION_SERVER_IMPLEMENTATIONS_PARAMETER_QNAME = new QName(
ohair@286 56 PolicyConstants.SUN_MANAGEMENT_NAMESPACE, "CommunicationServerImplementations");
ohair@286 57 private static final QName COMMUNICATION_SERVER_IMPLEMENTATION_PARAMETER_QNAME = new QName(
ohair@286 58 PolicyConstants.SUN_MANAGEMENT_NAMESPACE, "CommunicationServerImplementation");
ohair@286 59 private static final QName CONFIGURATOR_IMPLEMENTATION_PARAMETER_QNAME = new QName(
ohair@286 60 PolicyConstants.SUN_MANAGEMENT_NAMESPACE, "ConfiguratorImplementation");
ohair@286 61 private static final QName CONFIG_SAVER_IMPLEMENTATION_PARAMETER_QNAME = new QName(
ohair@286 62 PolicyConstants.SUN_MANAGEMENT_NAMESPACE, "ConfigSaverImplementation");
ohair@286 63 private static final QName CONFIG_READER_IMPLEMENTATION_PARAMETER_QNAME = new QName(
ohair@286 64 PolicyConstants.SUN_MANAGEMENT_NAMESPACE, "ConfigReaderImplementation");
ohair@286 65 private static final QName CLASS_NAME_ATTRIBUTE_QNAME = new QName("className");
ohair@286 66 /**
ohair@286 67 * The name of the endpointDisposeDelay attribute.
ohair@286 68 */
ohair@286 69 private static final QName ENDPOINT_DISPOSE_DELAY_ATTRIBUTE_QNAME = new QName("endpointDisposeDelay");
ohair@286 70
ohair@286 71 private static final Logger LOGGER = Logger.getLogger(ManagedServiceAssertion.class);
ohair@286 72
ohair@286 73 /**
ohair@286 74 * Return ManagedService assertion if there is one associated with the endpoint.
ohair@286 75 *
ohair@286 76 * @param endpoint The endpoint. Must not be null.
ohair@286 77 * @return The policy assertion if found. Null otherwise.
ohair@286 78 * @throws WebServiceException If computing the effective policy of the endpoint failed.
ohair@286 79 */
ohair@286 80 public static ManagedServiceAssertion getAssertion(WSEndpoint endpoint) throws WebServiceException {
ohair@286 81 LOGGER.entering(endpoint);
ohair@286 82 // getPolicyMap is deprecated because it is only supposed to be used by Metro code
ohair@286 83 // and not by other clients.
ohair@286 84 @SuppressWarnings("deprecation")
ohair@286 85 final PolicyMap policyMap = endpoint.getPolicyMap();
ohair@286 86 final ManagedServiceAssertion assertion = ManagementAssertion.getAssertion(MANAGED_SERVICE_QNAME,
ohair@286 87 policyMap, endpoint.getServiceName(), endpoint.getPortName(), ManagedServiceAssertion.class);
ohair@286 88 LOGGER.exiting(assertion);
ohair@286 89 return assertion;
ohair@286 90 }
ohair@286 91
ohair@286 92 public ManagedServiceAssertion(AssertionData data, Collection<PolicyAssertion> assertionParameters)
ohair@286 93 throws AssertionCreationException {
ohair@286 94 super(MANAGED_SERVICE_QNAME, data, assertionParameters);
ohair@286 95 }
ohair@286 96
ohair@286 97 /**
ohair@286 98 * Returns the value of the management attribute. True if unset or set to "true"
ohair@286 99 * or "on". False otherwise.
ohair@286 100 *
ohair@286 101 * @return The value of the management attribute.
ohair@286 102 */
ohair@286 103 public boolean isManagementEnabled() {
ohair@286 104 final String management = this.getAttributeValue(MANAGEMENT_ATTRIBUTE_QNAME);
ohair@286 105 boolean result = true;
ohair@286 106 if (management != null) {
ohair@286 107 if (management.trim().toLowerCase().equals("on")) {
ohair@286 108 result = true;
ohair@286 109 }
ohair@286 110 else {
ohair@286 111 result = Boolean.parseBoolean(management);
ohair@286 112 }
ohair@286 113 }
ohair@286 114 return result;
ohair@286 115 }
ohair@286 116
ohair@286 117 /**
ohair@286 118 * Returns the value of the endpointDisposeDelay attribute or the default value
ohair@286 119 * otherwise.
ohair@286 120 *
ohair@286 121 * @param defaultDelay The default value that is returned if this attribute is
ohair@286 122 * not set
ohair@286 123 * @return The value of the endpointDisposeDelay attribute or the default value
ohair@286 124 * otherwise.
ohair@286 125 */
ohair@286 126 public long getEndpointDisposeDelay(final long defaultDelay) throws WebServiceException {
ohair@286 127 long result = defaultDelay;
ohair@286 128 final String delayText = getAttributeValue(ENDPOINT_DISPOSE_DELAY_ATTRIBUTE_QNAME);
ohair@286 129 if (delayText != null) {
ohair@286 130 try {
ohair@286 131 result = Long.parseLong(delayText);
ohair@286 132 } catch (NumberFormatException e) {
ohair@286 133 throw LOGGER.logSevereException(new WebServiceException(
ohair@286 134 ManagementMessages.WSM_1008_EXPECTED_INTEGER_DISPOSE_DELAY_VALUE(delayText), e));
ohair@286 135 }
ohair@286 136 }
ohair@286 137 return result;
ohair@286 138 }
ohair@286 139
ohair@286 140 /**
ohair@286 141 * A list of CommunicationServerImplementation elements that were set as
ohair@286 142 * parameters of this assertion.
ohair@286 143 *
ohair@286 144 * @return A list of CommunicationServerImplementation elements that were set as
ohair@286 145 * parameters of this assertion. May be empty.
ohair@286 146 */
ohair@286 147 public Collection<ImplementationRecord> getCommunicationServerImplementations() {
ohair@286 148 final Collection<ImplementationRecord> result = new LinkedList<ImplementationRecord>();
ohair@286 149 final Iterator<PolicyAssertion> parameters = getParametersIterator();
ohair@286 150 while (parameters.hasNext()) {
ohair@286 151 final PolicyAssertion parameter = parameters.next();
ohair@286 152 if (COMMUNICATION_SERVER_IMPLEMENTATIONS_PARAMETER_QNAME.equals(parameter.getName())) {
ohair@286 153 final Iterator<PolicyAssertion> implementations = parameter.getParametersIterator();
ohair@286 154 if (!implementations.hasNext()) {
ohair@286 155 throw LOGGER.logSevereException(new WebServiceException(
ohair@286 156 ManagementMessages.WSM_1005_EXPECTED_COMMUNICATION_CHILD()));
ohair@286 157 }
ohair@286 158 while (implementations.hasNext()) {
ohair@286 159 final PolicyAssertion implementation = implementations.next();
ohair@286 160 if (COMMUNICATION_SERVER_IMPLEMENTATION_PARAMETER_QNAME.equals(implementation.getName())) {
ohair@286 161 result.add(getImplementation(implementation));
ohair@286 162 }
ohair@286 163 else {
ohair@286 164 throw LOGGER.logSevereException(new WebServiceException(
ohair@286 165 ManagementMessages.WSM_1004_EXPECTED_XML_TAG(
ohair@286 166 COMMUNICATION_SERVER_IMPLEMENTATION_PARAMETER_QNAME, implementation.getName())));
ohair@286 167 }
ohair@286 168 }
ohair@286 169 }
ohair@286 170 }
ohair@286 171 return result;
ohair@286 172 }
ohair@286 173
ohair@286 174 /**
ohair@286 175 * The ConfiguratorImplementation that was set as parameter of this assertion.
ohair@286 176 *
ohair@286 177 * @return The ConfiguratorImplementation that was set as parameter of this assertion.
ohair@286 178 * May be null.
ohair@286 179 */
ohair@286 180 public ImplementationRecord getConfiguratorImplementation() {
ohair@286 181 return findImplementation(CONFIGURATOR_IMPLEMENTATION_PARAMETER_QNAME);
ohair@286 182 }
ohair@286 183
ohair@286 184 /**
ohair@286 185 * The ConfigSaverImplementation that was set as parameter of this assertion.
ohair@286 186 *
ohair@286 187 * @return The ConfigSaverImplementation that was set as parameter of this assertion.
ohair@286 188 * May be null.
ohair@286 189 */
ohair@286 190 public ImplementationRecord getConfigSaverImplementation() {
ohair@286 191 return findImplementation(CONFIG_SAVER_IMPLEMENTATION_PARAMETER_QNAME);
ohair@286 192 }
ohair@286 193
ohair@286 194 /**
ohair@286 195 * The ConfigReaderImplementation that was set as parameter of this assertion.
ohair@286 196 *
ohair@286 197 * @return The ConfigReaderImplementation that was set as parameter of this assertion.
ohair@286 198 * May be null.
ohair@286 199 */
ohair@286 200 public ImplementationRecord getConfigReaderImplementation() {
ohair@286 201 return findImplementation(CONFIG_READER_IMPLEMENTATION_PARAMETER_QNAME);
ohair@286 202 }
ohair@286 203
ohair@286 204 private ImplementationRecord findImplementation(QName implementationName) {
ohair@286 205 final Iterator<PolicyAssertion> parameters = getParametersIterator();
ohair@286 206 while (parameters.hasNext()) {
ohair@286 207 final PolicyAssertion parameter = parameters.next();
ohair@286 208 if (implementationName.equals(parameter.getName())) {
ohair@286 209 return getImplementation(parameter);
ohair@286 210 }
ohair@286 211 }
ohair@286 212 return null;
ohair@286 213 }
ohair@286 214
ohair@286 215 private ImplementationRecord getImplementation(PolicyAssertion rootParameter) {
ohair@286 216 final String className = rootParameter.getAttributeValue(CLASS_NAME_ATTRIBUTE_QNAME);
ohair@286 217 final HashMap<QName, String> parameterMap = new HashMap<QName, String>();
ohair@286 218 final Iterator<PolicyAssertion> implementationParameters = rootParameter.getParametersIterator();
ohair@286 219 final Collection<NestedParameters> nestedParameters = new LinkedList<NestedParameters>();
ohair@286 220 while (implementationParameters.hasNext()) {
ohair@286 221 final PolicyAssertion parameterAssertion = implementationParameters.next();
ohair@286 222 final QName parameterName = parameterAssertion.getName();
ohair@286 223 if (parameterAssertion.hasParameters()) {
ohair@286 224 final Map<QName, String> nestedParameterMap = new HashMap<QName, String>();
ohair@286 225 final Iterator<PolicyAssertion> parameters = parameterAssertion.getParametersIterator();
ohair@286 226 while (parameters.hasNext()) {
ohair@286 227 final PolicyAssertion parameter = parameters.next();
ohair@286 228 String value = parameter.getValue();
ohair@286 229 if (value != null) {
ohair@286 230 value = value.trim();
ohair@286 231 }
ohair@286 232 nestedParameterMap.put(parameter.getName(), value);
ohair@286 233 }
ohair@286 234 nestedParameters.add(new NestedParameters(parameterName, nestedParameterMap));
ohair@286 235 }
ohair@286 236 else {
ohair@286 237 String value = parameterAssertion.getValue();
ohair@286 238 if (value != null) {
ohair@286 239 value = value.trim();
ohair@286 240 }
ohair@286 241 parameterMap.put(parameterName, value);
ohair@286 242 }
ohair@286 243 }
ohair@286 244 return new ImplementationRecord(className, parameterMap, nestedParameters);
ohair@286 245 }
ohair@286 246
ohair@286 247
ohair@286 248 /**
ohair@286 249 * Return the implementation class name along with all parameters for the
ohair@286 250 * implementation.
ohair@286 251 */
ohair@286 252 public static class ImplementationRecord {
ohair@286 253
ohair@286 254 private final String implementation;
ohair@286 255 private final Map<QName, String> parameters;
ohair@286 256 private final Collection<NestedParameters> nestedParameters;
ohair@286 257
ohair@286 258 protected ImplementationRecord(String implementation, Map<QName, String> parameters,
ohair@286 259 Collection<NestedParameters> nestedParameters) {
ohair@286 260 this.implementation = implementation;
ohair@286 261 this.parameters = parameters;
ohair@286 262 this.nestedParameters = nestedParameters;
ohair@286 263 }
ohair@286 264
ohair@286 265 public String getImplementation() {
ohair@286 266 return this.implementation;
ohair@286 267 }
ohair@286 268
ohair@286 269 /**
ohair@286 270 * The parameters that were set for this implementation element.
ohair@286 271 *
ohair@286 272 * @return The parameters that were set for this implementation element.
ohair@286 273 * May be null.
ohair@286 274 */
ohair@286 275 public Map<QName, String> getParameters() {
ohair@286 276 return this.parameters;
ohair@286 277 }
ohair@286 278
ohair@286 279 /**
ohair@286 280 * Implementation elements may contain element parameters that contain
ohair@286 281 * further parameters.
ohair@286 282 *
ohair@286 283 * @return The nested parameters that were set for this implementation element.
ohair@286 284 * May be null.
ohair@286 285 */
ohair@286 286 public Collection<NestedParameters> getNestedParameters() {
ohair@286 287 return this.nestedParameters;
ohair@286 288 }
ohair@286 289
ohair@286 290 @Override
ohair@286 291 public boolean equals(Object obj) {
ohair@286 292 if (obj == null) {
ohair@286 293 return false;
ohair@286 294 }
ohair@286 295 if (getClass() != obj.getClass()) {
ohair@286 296 return false;
ohair@286 297 }
ohair@286 298 final ImplementationRecord other = (ImplementationRecord) obj;
ohair@286 299 if ((this.implementation == null) ?
ohair@286 300 (other.implementation != null) : !this.implementation.equals(other.implementation)) {
ohair@286 301 return false;
ohair@286 302 }
ohair@286 303 if (this.parameters != other.parameters && (this.parameters == null || !this.parameters.equals(other.parameters))) {
ohair@286 304 return false;
ohair@286 305 }
ohair@286 306 if (this.nestedParameters != other.nestedParameters &&
ohair@286 307 (this.nestedParameters == null || !this.nestedParameters.equals(other.nestedParameters))) {
ohair@286 308 return false;
ohair@286 309 }
ohair@286 310 return true;
ohair@286 311 }
ohair@286 312
ohair@286 313 @Override
ohair@286 314 public int hashCode() {
ohair@286 315 int hash = 3;
ohair@286 316 hash = 53 * hash + (this.implementation != null ? this.implementation.hashCode() : 0);
ohair@286 317 hash = 53 * hash + (this.parameters != null ? this.parameters.hashCode() : 0);
ohair@286 318 hash = 53 * hash + (this.nestedParameters != null ? this.nestedParameters.hashCode() : 0);
ohair@286 319 return hash;
ohair@286 320 }
ohair@286 321
ohair@286 322 @Override
ohair@286 323 public String toString() {
ohair@286 324 final StringBuilder text = new StringBuilder("ImplementationRecord: ");
ohair@286 325 text.append("implementation = \"").append(this.implementation).append("\", ");
ohair@286 326 text.append("parameters = \"").append(this.parameters).append("\", ");
ohair@286 327 text.append("nested parameters = \"").append(this.nestedParameters).append("\"");
ohair@286 328 return text.toString();
ohair@286 329 }
ohair@286 330
ohair@286 331 }
ohair@286 332
ohair@286 333
ohair@286 334 /**
ohair@286 335 * The nested parameters that may be set as part of an implementation element.
ohair@286 336 */
ohair@286 337 public static class NestedParameters {
ohair@286 338
ohair@286 339 private final QName name;
ohair@286 340 private final Map<QName, String> parameters;
ohair@286 341
ohair@286 342 private NestedParameters(QName name, Map<QName, String> parameters) {
ohair@286 343 this.name = name;
ohair@286 344 this.parameters = parameters;
ohair@286 345 }
ohair@286 346
ohair@286 347 public QName getName() {
ohair@286 348 return this.name;
ohair@286 349 }
ohair@286 350
ohair@286 351 public Map<QName, String> getParameters() {
ohair@286 352 return this.parameters;
ohair@286 353 }
ohair@286 354
ohair@286 355 @Override
ohair@286 356 public boolean equals(Object obj) {
ohair@286 357 if (obj == null) {
ohair@286 358 return false;
ohair@286 359 }
ohair@286 360 if (getClass() != obj.getClass()) {
ohair@286 361 return false;
ohair@286 362 }
ohair@286 363 final NestedParameters other = (NestedParameters) obj;
ohair@286 364 if ((this.name == null) ? (other.name != null) : !this.name.equals(other.name)) {
ohair@286 365 return false;
ohair@286 366 }
ohair@286 367 if (this.parameters != other.parameters && (this.parameters == null || !this.parameters.equals(other.parameters))) {
ohair@286 368 return false;
ohair@286 369 }
ohair@286 370 return true;
ohair@286 371 }
ohair@286 372
ohair@286 373 @Override
ohair@286 374 public int hashCode() {
ohair@286 375 int hash = 5;
ohair@286 376 hash = 59 * hash + (this.name != null ? this.name.hashCode() : 0);
ohair@286 377 hash = 59 * hash + (this.parameters != null ? this.parameters.hashCode() : 0);
ohair@286 378 return hash;
ohair@286 379 }
ohair@286 380
ohair@286 381 @Override
ohair@286 382 public String toString() {
ohair@286 383 final StringBuilder text = new StringBuilder("NestedParameters: ");
ohair@286 384 text.append("name = \"").append(this.name).append("\", ");
ohair@286 385 text.append("parameters = \"").append(this.parameters).append("\"");
ohair@286 386 return text.toString();
ohair@286 387 }
ohair@286 388
ohair@286 389 }
ohair@286 390
ohair@286 391 }

mercurial