001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common Development
008: * and Distribution License("CDDL") (collectively, the "License"). You
009: * may not use this file except in compliance with the License. You can obtain
010: * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
011: * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
012: * language governing permissions and limitations under the License.
013: *
014: * When distributing the software, include this License Header Notice in each
015: * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
016: * Sun designates this particular file as subject to the "Classpath" exception
017: * as provided by Sun in the GPL Version 2 section of the License file that
018: * accompanied this code. If applicable, add the following below the License
019: * Header, with the fields enclosed by brackets [] replaced by your own
020: * identifying information: "Portions Copyrighted [year]
021: * [name of copyright owner]"
022: *
023: * Contributor(s):
024: *
025: * If you wish your version of this file to be governed by only the CDDL or
026: * only the GPL Version 2, indicate your decision by adding "[Contributor]
027: * elects to include this software in this distribution under the [CDDL or GPL
028: * Version 2] license." If you don't indicate a single choice of license, a
029: * recipient has the option to distribute your version of this file under
030: * either the CDDL, the GPL Version 2 or to extend the choice of license to
031: * its licensees as provided above. However, if you add GPL Version 2 code
032: * and therefore, elected the GPL Version 2 license, then the option applies
033: * only if the new code is made subject to such option by the copyright
034: * holder.
035: */
036: package com.sun.xml.ws.policy.jaxws;
037:
038: import com.sun.xml.ws.policy.Policy;
039: import com.sun.xml.ws.policy.PolicyException;
040: import com.sun.xml.ws.policy.PolicyMapExtender;
041: import com.sun.xml.ws.policy.PolicySubject;
042: import com.sun.xml.ws.policy.jaxws.privateutil.LocalizationMessages;
043: import com.sun.xml.ws.policy.privateutil.PolicyLogger;
044: import com.sun.xml.ws.policy.sourcemodel.PolicyModelTranslator;
045: import com.sun.xml.ws.policy.sourcemodel.PolicySourceModel;
046: import java.util.ArrayList;
047: import java.util.Collection;
048: import java.util.Map;
049:
050: /**
051: *
052: * @author Jakub Podlesak (jakub.podlesak at sun.com)
053: */
054: abstract class BuilderHandler {
055: private static final PolicyLogger LOGGER = PolicyLogger
056: .getLogger(BuilderHandler.class);
057:
058: Map<String, PolicySourceModel> policyStore;
059: Collection<String> policyURIs;
060: Object policySubject;
061:
062: /**
063: * Creates a new instance of BuilderHandler
064: */
065: BuilderHandler(Collection<String> policyURIs,
066: Map<String, PolicySourceModel> policyStore,
067: Object policySubject) {
068: this .policyStore = policyStore;
069: this .policyURIs = policyURIs;
070: this .policySubject = policySubject;
071: }
072:
073: final void populate(final PolicyMapExtender policyMapExtender)
074: throws PolicyException {
075: if (null == policyMapExtender) {
076: throw LOGGER
077: .logSevereException(new PolicyException(
078: LocalizationMessages
079: .WSP_1015_POLICY_MAP_EXTENDER_CAN_NOT_BE_NULL()));
080: }
081:
082: doPopulate(policyMapExtender);
083: }
084:
085: protected abstract void doPopulate(
086: final PolicyMapExtender policyMapExtender)
087: throws PolicyException;
088:
089: final Collection<Policy> getPolicies() throws PolicyException {
090: if (null == policyURIs) {
091: throw LOGGER.logSevereException(new PolicyException(
092: LocalizationMessages
093: .WSP_1013_POLICY_URIS_CAN_NOT_BE_NULL()));
094: }
095: if (null == policyStore) {
096: throw LOGGER
097: .logSevereException(new PolicyException(
098: LocalizationMessages
099: .WSP_1021_NO_POLICIES_DEFINED()));
100: }
101:
102: final Collection<Policy> result = new ArrayList<Policy>(
103: policyURIs.size());
104:
105: for (String policyURI : policyURIs) {
106: final PolicySourceModel sourceModel = policyStore
107: .get(policyURI);
108: if (sourceModel == null) {
109: throw LOGGER
110: .logSevereException(new PolicyException(
111: LocalizationMessages
112: .WSP_1014_POLICY_REFERENCE_DOES_NOT_EXIST(policyURI)));
113: } else {
114: result.add(PolicyModelTranslator.getTranslator()
115: .translate(sourceModel));
116: }
117: }
118:
119: return result;
120: }
121:
122: final Collection<PolicySubject> getPolicySubjects()
123: throws PolicyException {
124: final Collection<Policy> policies = getPolicies();
125: final Collection<PolicySubject> result = new ArrayList<PolicySubject>(
126: policies.size());
127: for (Policy policy : policies) {
128: result.add(new PolicySubject(policySubject, policy));
129: }
130: return result;
131: }
132: }
|