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:
037: package com.sun.xml.ws.policy;
038:
039: import com.sun.xml.ws.policy.privateutil.LocalizationMessages;
040: import com.sun.xml.ws.policy.privateutil.PolicyLogger;
041:
042: /**
043: * The class serves as a base for specific policy map mutator implementations. It provides common methods that allow
044: * concrete mutator implementations to connect and disconnect to/from a policy map instance.
045: *
046: * @author Marek Potociar (marek.potociar@sun.com)
047: */
048: public abstract class PolicyMapMutator {
049: private static final PolicyLogger LOGGER = PolicyLogger
050: .getLogger(PolicyMapMutator.class);
051:
052: private PolicyMap map = null;
053:
054: /**
055: * Creates a new instance of PolicyMapMutator. This class cannot be extended from outside of this package.
056: */
057: PolicyMapMutator() {
058: // nothing to instantiate
059: }
060:
061: /**
062: * The method is used to connect the policy map mutator instance to the map it should mutate.
063: *
064: * @param map the policy map instance that will be mutable by this mutator.
065: * @throws IllegalStateException in case this mutator object is already connected to a policy map.
066: */
067: void connect(final PolicyMap map) {
068: if (isConnected()) {
069: throw LOGGER
070: .logSevereException(new IllegalStateException(
071: LocalizationMessages
072: .WSP_0044_POLICY_MAP_MUTATOR_ALREADY_CONNECTED()));
073: }
074:
075: this .map = map;
076: }
077:
078: /**
079: * Can be used to retrieve the policy map currently connected to this mutator. Will return {@code null} if not connected.
080: *
081: * @return policy map currently connected to this mutator. May return {@code null} if the mutator is not connected.
082: *
083: * @see #isConnected()
084: * @see #disconnect()
085: */
086: public PolicyMap getMap() {
087: return this .map;
088: }
089:
090: /**
091: * Disconnects the mutator from the policy map object it is connected to. Method must be called prior to connecting this
092: * mutator instance to another policy map.
093: * <p/>
094: * This operation is irreversible: you cannot connect the mutator to the same policy map instance once you disconnect from it.
095: * Multiple consequent calls of this method will have no effect.
096: */
097: public void disconnect() {
098: this .map = null;
099: }
100:
101: /**
102: * This method provides connection status information of the policy map mutator instance.
103: *
104: * @return {@code true} if the mutator instance is connected to a policy map, otherwise returns {@code false}.
105: */
106: public boolean isConnected() {
107: return this.map != null;
108: }
109: }
|