1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/jaxws_classes/com/sun/xml/internal/ws/api/config/management/policy/ManagedServiceAssertion.java Wed Apr 27 01:27:09 2016 +0800 1.3 @@ -0,0 +1,391 @@ 1.4 +/* 1.5 + * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. Oracle designates this 1.11 + * particular file as subject to the "Classpath" exception as provided 1.12 + * by Oracle in the LICENSE file that accompanied this code. 1.13 + * 1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.17 + * version 2 for more details (a copy is included in the LICENSE file that 1.18 + * accompanied this code). 1.19 + * 1.20 + * You should have received a copy of the GNU General Public License version 1.21 + * 2 along with this work; if not, write to the Free Software Foundation, 1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.23 + * 1.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.25 + * or visit www.oracle.com if you need additional information or have any 1.26 + * questions. 1.27 + */ 1.28 + 1.29 +package com.sun.xml.internal.ws.api.config.management.policy; 1.30 + 1.31 +import com.sun.istack.internal.logging.Logger; 1.32 +import com.sun.xml.internal.ws.api.server.WSEndpoint; 1.33 +import com.sun.xml.internal.ws.policy.PolicyAssertion; 1.34 +import com.sun.xml.internal.ws.policy.PolicyMap; 1.35 +import com.sun.xml.internal.ws.policy.PolicyConstants; 1.36 +import com.sun.xml.internal.ws.policy.sourcemodel.AssertionData; 1.37 +import com.sun.xml.internal.ws.policy.spi.AssertionCreationException; 1.38 +import com.sun.xml.internal.ws.resources.ManagementMessages; 1.39 + 1.40 +import java.util.Collection; 1.41 +import java.util.HashMap; 1.42 +import java.util.Iterator; 1.43 +import java.util.LinkedList; 1.44 +import java.util.Map; 1.45 +import javax.xml.namespace.QName; 1.46 +import javax.xml.ws.WebServiceException; 1.47 + 1.48 +/** 1.49 + * The server-side ManagedService policy assertion. 1.50 + * 1.51 + * @author Fabian Ritzmann 1.52 + */ 1.53 +public class ManagedServiceAssertion extends ManagementAssertion { 1.54 + 1.55 + public static final QName MANAGED_SERVICE_QNAME = 1.56 + new QName(PolicyConstants.SUN_MANAGEMENT_NAMESPACE, "ManagedService"); 1.57 + 1.58 + private static final QName COMMUNICATION_SERVER_IMPLEMENTATIONS_PARAMETER_QNAME = new QName( 1.59 + PolicyConstants.SUN_MANAGEMENT_NAMESPACE, "CommunicationServerImplementations"); 1.60 + private static final QName COMMUNICATION_SERVER_IMPLEMENTATION_PARAMETER_QNAME = new QName( 1.61 + PolicyConstants.SUN_MANAGEMENT_NAMESPACE, "CommunicationServerImplementation"); 1.62 + private static final QName CONFIGURATOR_IMPLEMENTATION_PARAMETER_QNAME = new QName( 1.63 + PolicyConstants.SUN_MANAGEMENT_NAMESPACE, "ConfiguratorImplementation"); 1.64 + private static final QName CONFIG_SAVER_IMPLEMENTATION_PARAMETER_QNAME = new QName( 1.65 + PolicyConstants.SUN_MANAGEMENT_NAMESPACE, "ConfigSaverImplementation"); 1.66 + private static final QName CONFIG_READER_IMPLEMENTATION_PARAMETER_QNAME = new QName( 1.67 + PolicyConstants.SUN_MANAGEMENT_NAMESPACE, "ConfigReaderImplementation"); 1.68 + private static final QName CLASS_NAME_ATTRIBUTE_QNAME = new QName("className"); 1.69 + /** 1.70 + * The name of the endpointDisposeDelay attribute. 1.71 + */ 1.72 + private static final QName ENDPOINT_DISPOSE_DELAY_ATTRIBUTE_QNAME = new QName("endpointDisposeDelay"); 1.73 + 1.74 + private static final Logger LOGGER = Logger.getLogger(ManagedServiceAssertion.class); 1.75 + 1.76 + /** 1.77 + * Return ManagedService assertion if there is one associated with the endpoint. 1.78 + * 1.79 + * @param endpoint The endpoint. Must not be null. 1.80 + * @return The policy assertion if found. Null otherwise. 1.81 + * @throws WebServiceException If computing the effective policy of the endpoint failed. 1.82 + */ 1.83 + public static ManagedServiceAssertion getAssertion(WSEndpoint endpoint) throws WebServiceException { 1.84 + LOGGER.entering(endpoint); 1.85 + // getPolicyMap is deprecated because it is only supposed to be used by Metro code 1.86 + // and not by other clients. 1.87 + @SuppressWarnings("deprecation") 1.88 + final PolicyMap policyMap = endpoint.getPolicyMap(); 1.89 + final ManagedServiceAssertion assertion = ManagementAssertion.getAssertion(MANAGED_SERVICE_QNAME, 1.90 + policyMap, endpoint.getServiceName(), endpoint.getPortName(), ManagedServiceAssertion.class); 1.91 + LOGGER.exiting(assertion); 1.92 + return assertion; 1.93 + } 1.94 + 1.95 + public ManagedServiceAssertion(AssertionData data, Collection<PolicyAssertion> assertionParameters) 1.96 + throws AssertionCreationException { 1.97 + super(MANAGED_SERVICE_QNAME, data, assertionParameters); 1.98 + } 1.99 + 1.100 + /** 1.101 + * Returns the value of the management attribute. True if unset or set to "true" 1.102 + * or "on". False otherwise. 1.103 + * 1.104 + * @return The value of the management attribute. 1.105 + */ 1.106 + public boolean isManagementEnabled() { 1.107 + final String management = this.getAttributeValue(MANAGEMENT_ATTRIBUTE_QNAME); 1.108 + boolean result = true; 1.109 + if (management != null) { 1.110 + if (management.trim().toLowerCase().equals("on")) { 1.111 + result = true; 1.112 + } 1.113 + else { 1.114 + result = Boolean.parseBoolean(management); 1.115 + } 1.116 + } 1.117 + return result; 1.118 + } 1.119 + 1.120 + /** 1.121 + * Returns the value of the endpointDisposeDelay attribute or the default value 1.122 + * otherwise. 1.123 + * 1.124 + * @param defaultDelay The default value that is returned if this attribute is 1.125 + * not set 1.126 + * @return The value of the endpointDisposeDelay attribute or the default value 1.127 + * otherwise. 1.128 + */ 1.129 + public long getEndpointDisposeDelay(final long defaultDelay) throws WebServiceException { 1.130 + long result = defaultDelay; 1.131 + final String delayText = getAttributeValue(ENDPOINT_DISPOSE_DELAY_ATTRIBUTE_QNAME); 1.132 + if (delayText != null) { 1.133 + try { 1.134 + result = Long.parseLong(delayText); 1.135 + } catch (NumberFormatException e) { 1.136 + throw LOGGER.logSevereException(new WebServiceException( 1.137 + ManagementMessages.WSM_1008_EXPECTED_INTEGER_DISPOSE_DELAY_VALUE(delayText), e)); 1.138 + } 1.139 + } 1.140 + return result; 1.141 + } 1.142 + 1.143 + /** 1.144 + * A list of CommunicationServerImplementation elements that were set as 1.145 + * parameters of this assertion. 1.146 + * 1.147 + * @return A list of CommunicationServerImplementation elements that were set as 1.148 + * parameters of this assertion. May be empty. 1.149 + */ 1.150 + public Collection<ImplementationRecord> getCommunicationServerImplementations() { 1.151 + final Collection<ImplementationRecord> result = new LinkedList<ImplementationRecord>(); 1.152 + final Iterator<PolicyAssertion> parameters = getParametersIterator(); 1.153 + while (parameters.hasNext()) { 1.154 + final PolicyAssertion parameter = parameters.next(); 1.155 + if (COMMUNICATION_SERVER_IMPLEMENTATIONS_PARAMETER_QNAME.equals(parameter.getName())) { 1.156 + final Iterator<PolicyAssertion> implementations = parameter.getParametersIterator(); 1.157 + if (!implementations.hasNext()) { 1.158 + throw LOGGER.logSevereException(new WebServiceException( 1.159 + ManagementMessages.WSM_1005_EXPECTED_COMMUNICATION_CHILD())); 1.160 + } 1.161 + while (implementations.hasNext()) { 1.162 + final PolicyAssertion implementation = implementations.next(); 1.163 + if (COMMUNICATION_SERVER_IMPLEMENTATION_PARAMETER_QNAME.equals(implementation.getName())) { 1.164 + result.add(getImplementation(implementation)); 1.165 + } 1.166 + else { 1.167 + throw LOGGER.logSevereException(new WebServiceException( 1.168 + ManagementMessages.WSM_1004_EXPECTED_XML_TAG( 1.169 + COMMUNICATION_SERVER_IMPLEMENTATION_PARAMETER_QNAME, implementation.getName()))); 1.170 + } 1.171 + } 1.172 + } 1.173 + } 1.174 + return result; 1.175 + } 1.176 + 1.177 + /** 1.178 + * The ConfiguratorImplementation that was set as parameter of this assertion. 1.179 + * 1.180 + * @return The ConfiguratorImplementation that was set as parameter of this assertion. 1.181 + * May be null. 1.182 + */ 1.183 + public ImplementationRecord getConfiguratorImplementation() { 1.184 + return findImplementation(CONFIGURATOR_IMPLEMENTATION_PARAMETER_QNAME); 1.185 + } 1.186 + 1.187 + /** 1.188 + * The ConfigSaverImplementation that was set as parameter of this assertion. 1.189 + * 1.190 + * @return The ConfigSaverImplementation that was set as parameter of this assertion. 1.191 + * May be null. 1.192 + */ 1.193 + public ImplementationRecord getConfigSaverImplementation() { 1.194 + return findImplementation(CONFIG_SAVER_IMPLEMENTATION_PARAMETER_QNAME); 1.195 + } 1.196 + 1.197 + /** 1.198 + * The ConfigReaderImplementation that was set as parameter of this assertion. 1.199 + * 1.200 + * @return The ConfigReaderImplementation that was set as parameter of this assertion. 1.201 + * May be null. 1.202 + */ 1.203 + public ImplementationRecord getConfigReaderImplementation() { 1.204 + return findImplementation(CONFIG_READER_IMPLEMENTATION_PARAMETER_QNAME); 1.205 + } 1.206 + 1.207 + private ImplementationRecord findImplementation(QName implementationName) { 1.208 + final Iterator<PolicyAssertion> parameters = getParametersIterator(); 1.209 + while (parameters.hasNext()) { 1.210 + final PolicyAssertion parameter = parameters.next(); 1.211 + if (implementationName.equals(parameter.getName())) { 1.212 + return getImplementation(parameter); 1.213 + } 1.214 + } 1.215 + return null; 1.216 + } 1.217 + 1.218 + private ImplementationRecord getImplementation(PolicyAssertion rootParameter) { 1.219 + final String className = rootParameter.getAttributeValue(CLASS_NAME_ATTRIBUTE_QNAME); 1.220 + final HashMap<QName, String> parameterMap = new HashMap<QName, String>(); 1.221 + final Iterator<PolicyAssertion> implementationParameters = rootParameter.getParametersIterator(); 1.222 + final Collection<NestedParameters> nestedParameters = new LinkedList<NestedParameters>(); 1.223 + while (implementationParameters.hasNext()) { 1.224 + final PolicyAssertion parameterAssertion = implementationParameters.next(); 1.225 + final QName parameterName = parameterAssertion.getName(); 1.226 + if (parameterAssertion.hasParameters()) { 1.227 + final Map<QName, String> nestedParameterMap = new HashMap<QName, String>(); 1.228 + final Iterator<PolicyAssertion> parameters = parameterAssertion.getParametersIterator(); 1.229 + while (parameters.hasNext()) { 1.230 + final PolicyAssertion parameter = parameters.next(); 1.231 + String value = parameter.getValue(); 1.232 + if (value != null) { 1.233 + value = value.trim(); 1.234 + } 1.235 + nestedParameterMap.put(parameter.getName(), value); 1.236 + } 1.237 + nestedParameters.add(new NestedParameters(parameterName, nestedParameterMap)); 1.238 + } 1.239 + else { 1.240 + String value = parameterAssertion.getValue(); 1.241 + if (value != null) { 1.242 + value = value.trim(); 1.243 + } 1.244 + parameterMap.put(parameterName, value); 1.245 + } 1.246 + } 1.247 + return new ImplementationRecord(className, parameterMap, nestedParameters); 1.248 + } 1.249 + 1.250 + 1.251 + /** 1.252 + * Return the implementation class name along with all parameters for the 1.253 + * implementation. 1.254 + */ 1.255 + public static class ImplementationRecord { 1.256 + 1.257 + private final String implementation; 1.258 + private final Map<QName, String> parameters; 1.259 + private final Collection<NestedParameters> nestedParameters; 1.260 + 1.261 + protected ImplementationRecord(String implementation, Map<QName, String> parameters, 1.262 + Collection<NestedParameters> nestedParameters) { 1.263 + this.implementation = implementation; 1.264 + this.parameters = parameters; 1.265 + this.nestedParameters = nestedParameters; 1.266 + } 1.267 + 1.268 + public String getImplementation() { 1.269 + return this.implementation; 1.270 + } 1.271 + 1.272 + /** 1.273 + * The parameters that were set for this implementation element. 1.274 + * 1.275 + * @return The parameters that were set for this implementation element. 1.276 + * May be null. 1.277 + */ 1.278 + public Map<QName, String> getParameters() { 1.279 + return this.parameters; 1.280 + } 1.281 + 1.282 + /** 1.283 + * Implementation elements may contain element parameters that contain 1.284 + * further parameters. 1.285 + * 1.286 + * @return The nested parameters that were set for this implementation element. 1.287 + * May be null. 1.288 + */ 1.289 + public Collection<NestedParameters> getNestedParameters() { 1.290 + return this.nestedParameters; 1.291 + } 1.292 + 1.293 + @Override 1.294 + public boolean equals(Object obj) { 1.295 + if (obj == null) { 1.296 + return false; 1.297 + } 1.298 + if (getClass() != obj.getClass()) { 1.299 + return false; 1.300 + } 1.301 + final ImplementationRecord other = (ImplementationRecord) obj; 1.302 + if ((this.implementation == null) ? 1.303 + (other.implementation != null) : !this.implementation.equals(other.implementation)) { 1.304 + return false; 1.305 + } 1.306 + if (this.parameters != other.parameters && (this.parameters == null || !this.parameters.equals(other.parameters))) { 1.307 + return false; 1.308 + } 1.309 + if (this.nestedParameters != other.nestedParameters && 1.310 + (this.nestedParameters == null || !this.nestedParameters.equals(other.nestedParameters))) { 1.311 + return false; 1.312 + } 1.313 + return true; 1.314 + } 1.315 + 1.316 + @Override 1.317 + public int hashCode() { 1.318 + int hash = 3; 1.319 + hash = 53 * hash + (this.implementation != null ? this.implementation.hashCode() : 0); 1.320 + hash = 53 * hash + (this.parameters != null ? this.parameters.hashCode() : 0); 1.321 + hash = 53 * hash + (this.nestedParameters != null ? this.nestedParameters.hashCode() : 0); 1.322 + return hash; 1.323 + } 1.324 + 1.325 + @Override 1.326 + public String toString() { 1.327 + final StringBuilder text = new StringBuilder("ImplementationRecord: "); 1.328 + text.append("implementation = \"").append(this.implementation).append("\", "); 1.329 + text.append("parameters = \"").append(this.parameters).append("\", "); 1.330 + text.append("nested parameters = \"").append(this.nestedParameters).append("\""); 1.331 + return text.toString(); 1.332 + } 1.333 + 1.334 + } 1.335 + 1.336 + 1.337 + /** 1.338 + * The nested parameters that may be set as part of an implementation element. 1.339 + */ 1.340 + public static class NestedParameters { 1.341 + 1.342 + private final QName name; 1.343 + private final Map<QName, String> parameters; 1.344 + 1.345 + private NestedParameters(QName name, Map<QName, String> parameters) { 1.346 + this.name = name; 1.347 + this.parameters = parameters; 1.348 + } 1.349 + 1.350 + public QName getName() { 1.351 + return this.name; 1.352 + } 1.353 + 1.354 + public Map<QName, String> getParameters() { 1.355 + return this.parameters; 1.356 + } 1.357 + 1.358 + @Override 1.359 + public boolean equals(Object obj) { 1.360 + if (obj == null) { 1.361 + return false; 1.362 + } 1.363 + if (getClass() != obj.getClass()) { 1.364 + return false; 1.365 + } 1.366 + final NestedParameters other = (NestedParameters) obj; 1.367 + if ((this.name == null) ? (other.name != null) : !this.name.equals(other.name)) { 1.368 + return false; 1.369 + } 1.370 + if (this.parameters != other.parameters && (this.parameters == null || !this.parameters.equals(other.parameters))) { 1.371 + return false; 1.372 + } 1.373 + return true; 1.374 + } 1.375 + 1.376 + @Override 1.377 + public int hashCode() { 1.378 + int hash = 5; 1.379 + hash = 59 * hash + (this.name != null ? this.name.hashCode() : 0); 1.380 + hash = 59 * hash + (this.parameters != null ? this.parameters.hashCode() : 0); 1.381 + return hash; 1.382 + } 1.383 + 1.384 + @Override 1.385 + public String toString() { 1.386 + final StringBuilder text = new StringBuilder("NestedParameters: "); 1.387 + text.append("name = \"").append(this.name).append("\", "); 1.388 + text.append("parameters = \"").append(this.parameters).append("\""); 1.389 + return text.toString(); 1.390 + } 1.391 + 1.392 + } 1.393 + 1.394 +}