001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */package org.apache.cxf.ws.addressing;
019:
020: import org.apache.cxf.message.Message;
021: import org.apache.cxf.transport.Conduit;
022:
023: /**
024: * Holder for utility methods relating to contexts.
025: */
026: public final class WSAContextUtils {
027:
028: private static final String TO_PROPERTY = "org.apache.cxf.ws.addressing.to";
029: private static final String REPLYTO_PROPERTY = "org.apache.cxf.ws.addressing.replyto";
030: private static final String USING_PROPERTY = "org.apache.cxf.ws.addressing.using";
031:
032: /**
033: * Prevents instantiation.
034: */
035: private WSAContextUtils() {
036: }
037:
038: /**
039: * Store UsingAddressing override flag in the context
040: *
041: * @param override true if UsingAddressing should be overridden
042: * @param message the current message
043: */
044: public static void storeUsingAddressing(boolean override,
045: Message message) {
046: message.put(USING_PROPERTY, Boolean.valueOf(override));
047: }
048:
049: /**
050: * Retrieve UsingAddressing override flag from the context
051: *
052: * @param message the current message
053: * @return true if UsingAddressing should be overridden
054: */
055: public static boolean retrieveUsingAddressing(Message message) {
056: Boolean override = (Boolean) message.get(USING_PROPERTY);
057: return override != null && override.booleanValue();
058: }
059:
060: /**
061: * Store To EPR in the context
062: *
063: * @param to the To EPR
064: * @param message the current message
065: */
066: public static void storeTo(EndpointReferenceType to, Message message) {
067: message.put(TO_PROPERTY, to);
068: }
069:
070: /**
071: * Retrieve To EPR from the context.
072: *
073: * @param conduit the Conduit if available
074: * @param message the current message
075: * @return the retrieved EPR
076: */
077: public static EndpointReferenceType retrieveTo(Conduit conduit,
078: Message message) {
079: EndpointReferenceType to = null;
080: if (conduit != null) {
081: to = conduit.getTarget();
082: } else {
083: to = (EndpointReferenceType) message.get(TO_PROPERTY);
084: }
085: return to;
086: }
087:
088: /**
089: * Store ReplyTo EPR in the context
090: *
091: * @param replyTo the ReplyTo EPR
092: * @param message the current message
093: */
094: public static void storeReplyTo(EndpointReferenceType replyTo,
095: Message message) {
096: message.put(REPLYTO_PROPERTY, replyTo);
097: }
098:
099: /**
100: * Retrieve ReplyTo EPR from the context.
101: *
102: * @param conduit the Conduit if available
103: * @param message the current message
104: * @return the retrieved EPR
105: */
106: public static EndpointReferenceType retrieveReplyTo(
107: Conduit conduit, Message message) {
108: return conduit != null ? conduit.getBackChannel().getAddress()
109: : (EndpointReferenceType) message.get(REPLYTO_PROPERTY);
110: }
111: }
|