src/share/jaxws_classes/com/sun/xml/internal/ws/policy/jaxws/BuilderHandler.java

Thu, 31 Aug 2017 15:18:52 +0800

author
aoqi
date
Thu, 31 Aug 2017 15:18:52 +0800
changeset 637
9c07ef4934dd
parent 368
0989ad8c0860
parent 0
373ffda63c9a
permissions
-rw-r--r--

merge

     1 /*
     2  * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     8  * particular file as subject to the "Classpath" exception as provided
     9  * by Oracle in the LICENSE file that accompanied this code.
    10  *
    11  * This code is distributed in the hope that it will be useful, but WITHOUT
    12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    14  * version 2 for more details (a copy is included in the LICENSE file that
    15  * accompanied this code).
    16  *
    17  * You should have received a copy of the GNU General Public License version
    18  * 2 along with this work; if not, write to the Free Software Foundation,
    19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    20  *
    21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    22  * or visit www.oracle.com if you need additional information or have any
    23  * questions.
    24  */
    26 package com.sun.xml.internal.ws.policy.jaxws;
    28 import com.sun.xml.internal.ws.api.policy.ModelTranslator;
    29 import com.sun.xml.internal.ws.policy.Policy;
    30 import com.sun.xml.internal.ws.policy.PolicyException;
    31 import com.sun.xml.internal.ws.policy.PolicyMapExtender;
    32 import com.sun.xml.internal.ws.policy.PolicySubject;
    33 import com.sun.xml.internal.ws.resources.PolicyMessages;
    34 import com.sun.xml.internal.ws.policy.privateutil.PolicyLogger;
    35 import com.sun.xml.internal.ws.policy.sourcemodel.PolicySourceModel;
    37 import java.util.ArrayList;
    38 import java.util.Collection;
    39 import java.util.Map;
    41 /**
    42  *
    43  * @author Jakub Podlesak (jakub.podlesak at sun.com)
    44  */
    45 abstract class BuilderHandler{
    47     private static final PolicyLogger LOGGER = PolicyLogger.getLogger(BuilderHandler.class);
    49     Map<String,PolicySourceModel> policyStore;
    50     Collection<String> policyURIs;
    51     Object policySubject;
    53     /**
    54      * Creates a new instance of BuilderHandler
    55      */
    56     BuilderHandler(Collection<String> policyURIs, Map<String,PolicySourceModel> policyStore, Object policySubject) {
    57         this.policyStore = policyStore;
    58         this.policyURIs = policyURIs;
    59         this.policySubject = policySubject;
    60     }
    62     final void populate(final PolicyMapExtender policyMapExtender) throws PolicyException {
    63         if (null == policyMapExtender) {
    64             throw LOGGER.logSevereException(new PolicyException(PolicyMessages.WSP_1006_POLICY_MAP_EXTENDER_CAN_NOT_BE_NULL()));
    65         }
    67         doPopulate(policyMapExtender);
    68     }
    70     protected abstract void doPopulate(final PolicyMapExtender policyMapExtender) throws PolicyException;
    72     final Collection<Policy> getPolicies() throws PolicyException {
    73         if (null == policyURIs) {
    74             throw LOGGER.logSevereException(new PolicyException(PolicyMessages.WSP_1004_POLICY_URIS_CAN_NOT_BE_NULL()));
    75         }
    76         if (null == policyStore) {
    77             throw LOGGER.logSevereException(new PolicyException(PolicyMessages.WSP_1010_NO_POLICIES_DEFINED()));
    78         }
    80         final Collection<Policy> result = new ArrayList<Policy>(policyURIs.size());
    82         for (String policyURI : policyURIs) {
    83             final PolicySourceModel sourceModel = policyStore.get(policyURI);
    84             if (sourceModel == null) {
    85                 throw LOGGER.logSevereException(new PolicyException(PolicyMessages.WSP_1005_POLICY_REFERENCE_DOES_NOT_EXIST(policyURI)));
    86             } else {
    87                 result.add(ModelTranslator.getTranslator().translate(sourceModel));
    88             }
    89         }
    91         return result;
    92     }
    94     final Collection<PolicySubject> getPolicySubjects() throws PolicyException {
    95         final Collection<Policy> policies = getPolicies();
    96         final Collection<PolicySubject> result =  new ArrayList<PolicySubject>(policies.size());
    97         for (Policy policy : policies) {
    98             result.add(new PolicySubject(policySubject, policy));
    99         }
   100         return result;
   101     }
   102 }

mercurial