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

changeset 0
373ffda63c9a
child 637
9c07ef4934dd
     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/ManagementAssertion.java	Wed Apr 27 01:27:09 2016 +0800
     1.3 @@ -0,0 +1,185 @@
     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.policy.AssertionSet;
    1.33 +import com.sun.xml.internal.ws.policy.Policy;
    1.34 +import com.sun.xml.internal.ws.policy.PolicyAssertion;
    1.35 +import com.sun.xml.internal.ws.policy.PolicyException;
    1.36 +import com.sun.xml.internal.ws.policy.PolicyMap;
    1.37 +import com.sun.xml.internal.ws.policy.PolicyMapKey;
    1.38 +import com.sun.xml.internal.ws.policy.SimpleAssertion;
    1.39 +import com.sun.xml.internal.ws.policy.sourcemodel.AssertionData;
    1.40 +import com.sun.xml.internal.ws.policy.spi.AssertionCreationException;
    1.41 +import com.sun.xml.internal.ws.resources.ManagementMessages;
    1.42 +
    1.43 +import java.util.Collection;
    1.44 +import java.util.Iterator;
    1.45 +import javax.xml.namespace.QName;
    1.46 +import javax.xml.ws.WebServiceException;
    1.47 +
    1.48 +/**
    1.49 + * Base class for the #ManagedClientAssertion and #ManagedServiceAssertion. Provides
    1.50 + * convenience methods to directly access the policy assertion parameters.
    1.51 + *
    1.52 + * @author Fabian Ritzmann
    1.53 + */
    1.54 +public abstract class ManagementAssertion extends SimpleAssertion {
    1.55 +
    1.56 +    /**
    1.57 +     * To be able to distinguish between explicit settings and no setting.
    1.58 +     */
    1.59 +    public static enum Setting { NOT_SET, OFF, ON }
    1.60 +
    1.61 +    /**
    1.62 +     * The name of the management attribute.
    1.63 +     */
    1.64 +    protected static final QName MANAGEMENT_ATTRIBUTE_QNAME = new QName("management");
    1.65 +    /**
    1.66 +     * The name of the monitoring attribute.
    1.67 +     */
    1.68 +    protected static final QName MONITORING_ATTRIBUTE_QNAME = new QName("monitoring");
    1.69 +
    1.70 +    /**
    1.71 +     * The name of the id attribute.
    1.72 +     */
    1.73 +    private static final QName ID_ATTRIBUTE_QNAME = new QName("id");
    1.74 +    /**
    1.75 +     * The name of the start attribute.
    1.76 +     */
    1.77 +    private static final QName START_ATTRIBUTE_QNAME = new QName("start");
    1.78 +
    1.79 +    private static final Logger LOGGER = Logger.getLogger(ManagementAssertion.class);
    1.80 +
    1.81 +    /**
    1.82 +     * Return ManagementAssertion if one can be found in the policy map under
    1.83 +     * the given service and port name.
    1.84 +     *
    1.85 +     * @param <T> The implementation class of the assertion.
    1.86 +     * @param name The fully qualified name of the server or client assertion.
    1.87 +     * @param policyMap The policy map. May be null.
    1.88 +     * @param serviceName The WSDL service name. May not be null.
    1.89 +     * @param portName The WSDL port name. May not be null.
    1.90 +     * @param type The implementation class of the assertion.
    1.91 +     * @return An instance of ManagementAssertion or null.
    1.92 +     * @throws WebServiceException If computing the effective policy of the endpoint scope failed.
    1.93 +     */
    1.94 +    protected static <T extends ManagementAssertion> T getAssertion(final QName name,
    1.95 +            final PolicyMap policyMap, QName serviceName, QName portName, Class<T> type)
    1.96 +            throws WebServiceException {
    1.97 +        try {
    1.98 +            PolicyAssertion assertion = null;
    1.99 +            if (policyMap != null) {
   1.100 +                final PolicyMapKey key = PolicyMap.createWsdlEndpointScopeKey(serviceName, portName);
   1.101 +                final Policy policy = policyMap.getEndpointEffectivePolicy(key);
   1.102 +                if (policy != null) {
   1.103 +                    final Iterator<AssertionSet> assertionSets = policy.iterator();
   1.104 +                    if (assertionSets.hasNext()) {
   1.105 +                        final AssertionSet assertionSet = assertionSets.next();
   1.106 +                        final Iterator<PolicyAssertion> assertions = assertionSet.get(name).iterator();
   1.107 +                        if (assertions.hasNext()) {
   1.108 +                            assertion = assertions.next();
   1.109 +                        }
   1.110 +                    }
   1.111 +                }
   1.112 +            }
   1.113 +            return assertion == null ? null : assertion.getImplementation(type);
   1.114 +        } catch (PolicyException ex) {
   1.115 +            throw LOGGER.logSevereException(new WebServiceException(
   1.116 +                    ManagementMessages.WSM_1001_FAILED_ASSERTION(name), ex));
   1.117 +        }
   1.118 +    }
   1.119 +
   1.120 +    /**
   1.121 +     * Create a new ManagementAssertion instance.
   1.122 +     *
   1.123 +     * @param name The fully qualified name of the server or client assertion. Must
   1.124 +     *   not be null.
   1.125 +     * @param data The assertion data. Must not be null.
   1.126 +     * @param assertionParameters Parameters of the assertion. May be null.
   1.127 +     * @throws AssertionCreationException Thrown if the creation of the assertion failed.
   1.128 +     */
   1.129 +    protected ManagementAssertion(final QName name, AssertionData data, Collection<PolicyAssertion> assertionParameters)
   1.130 +            throws AssertionCreationException {
   1.131 +        super(data, assertionParameters);
   1.132 +        if (!name.equals(data.getName())) {
   1.133 +            throw LOGGER.logSevereException(new AssertionCreationException(data,
   1.134 +                    ManagementMessages.WSM_1002_EXPECTED_MANAGEMENT_ASSERTION(name)));
   1.135 +        }
   1.136 +        if (isManagementEnabled() && !data.containsAttribute(ID_ATTRIBUTE_QNAME)) {
   1.137 +            throw LOGGER.logSevereException(new AssertionCreationException(data,
   1.138 +                    ManagementMessages.WSM_1003_MANAGEMENT_ASSERTION_MISSING_ID(name)));
   1.139 +        }
   1.140 +    }
   1.141 +
   1.142 +    /**
   1.143 +     * Returns the value of the id attribute. May not be null.
   1.144 +     *
   1.145 +     * @return The value of the id attribute.
   1.146 +     */
   1.147 +    public String getId() {
   1.148 +        return this.getAttributeValue((ID_ATTRIBUTE_QNAME));
   1.149 +    }
   1.150 +
   1.151 +    /**
   1.152 +     * Returns the value of the start attribute. May be null.
   1.153 +     *
   1.154 +     * @return The value of the start attribute.
   1.155 +     */
   1.156 +    public String getStart() {
   1.157 +        return this.getAttributeValue((START_ATTRIBUTE_QNAME));
   1.158 +    }
   1.159 +
   1.160 +    /**
   1.161 +     * Returns the value of the managment attribute depending on whether this is
   1.162 +     * a client-side or server-side assertion.
   1.163 +     *
   1.164 +     * @return The value of the managment attribute.
   1.165 +     */
   1.166 +    public abstract boolean isManagementEnabled();
   1.167 +
   1.168 +    /**
   1.169 +     * Returns the value of the monitoring attribute.
   1.170 +     *
   1.171 +     * @return The value of the monitoring attribute.
   1.172 +     */
   1.173 +    public Setting monitoringAttribute() {
   1.174 +        final String monitoring = this.getAttributeValue(MONITORING_ATTRIBUTE_QNAME);
   1.175 +        Setting result = Setting.NOT_SET;
   1.176 +        if (monitoring != null) {
   1.177 +            if (monitoring.trim().toLowerCase().equals("on")
   1.178 +                || Boolean.parseBoolean(monitoring)) {
   1.179 +                result = Setting.ON;
   1.180 +            }
   1.181 +            else {
   1.182 +                result = Setting.OFF;
   1.183 +            }
   1.184 +        }
   1.185 +        return result;
   1.186 +    }
   1.187 +
   1.188 +}

mercurial