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.rm;
019:
020: import org.apache.cxf.message.Message;
021: import org.apache.cxf.message.MessageUtils;
022: import org.apache.cxf.ws.addressing.AddressingProperties;
023: import org.apache.cxf.ws.addressing.AddressingPropertiesImpl;
024: import org.apache.cxf.ws.addressing.VersionTransformer;
025:
026: /**
027: * Holder for utility methods relating to contexts.
028: */
029:
030: public final class RMContextUtils {
031:
032: /**
033: * Prevents instantiation.
034: */
035: protected RMContextUtils() {
036: }
037:
038: /**
039: * @return a generated UUID
040: */
041: public static String generateUUID() {
042: return org.apache.cxf.ws.addressing.ContextUtils.generateUUID();
043: }
044:
045: /**
046: * Determine if message is currently being processed on server side.
047: *
048: * @param message the current Message
049: * @return true iff message is currently being processed on server side
050: */
051: public static boolean isServerSide(Message message) {
052: return message.getExchange().getDestination() != null;
053: }
054:
055: /**
056: * Checks if the action String belongs to an RM protocol message.
057: *
058: * @param action the action
059: * @return true iff the action is not one of the RM protocol actions.
060: */
061: public static boolean isRMProtocolMessage(String action) {
062: return RMConstants.getCreateSequenceAction().equals(action)
063: || RMConstants.getCreateSequenceResponseAction()
064: .equals(action)
065: || RMConstants.getTerminateSequenceAction().equals(
066: action)
067: || RMConstants.getLastMessageAction().equals(action)
068: || RMConstants.getSequenceAcknowledgmentAction()
069: .equals(action)
070: || RMConstants.getSequenceInfoAction().equals(action);
071: }
072:
073: /**
074: * Retrieve the RM properties from the current message.
075: *
076: * @param message the current message
077: * @param outbound true iff the message direction is outbound
078: * @return the RM properties
079: */
080: public static RMProperties retrieveRMProperties(Message message,
081: boolean outbound) {
082: if (outbound) {
083: return (RMProperties) message.get(getRMPropertiesKey(true));
084: } else {
085: Message m = null;
086: if (MessageUtils.isOutbound(message)) {
087: // the in properties are only available on the in message
088: m = message.getExchange().getInMessage();
089: if (null == m) {
090: m = message.getExchange().getInFaultMessage();
091: }
092: } else {
093: m = message;
094: }
095: if (null != m) {
096: return (RMProperties) m.get(getRMPropertiesKey(false));
097: }
098: }
099: return null;
100:
101: }
102:
103: /**
104: * Store the RM properties in the current message.
105: *
106: * @param message the current message
107: * @param rmps the RM properties
108: * @param outbound iff the message direction is outbound
109: */
110: public static void storeRMProperties(Message message,
111: RMProperties rmps, boolean outbound) {
112: String key = getRMPropertiesKey(outbound);
113: message.put(key, rmps);
114: }
115:
116: /**
117: * Retrieves the addressing properties from the current message.
118: *
119: * @param message the current message
120: * @param isProviderContext true if the binding provider request context
121: * available to the client application as opposed to the message
122: * context visible to handlers
123: * @param isOutbound true iff the message is outbound
124: * @return the current addressing properties
125: */
126: public static AddressingPropertiesImpl retrieveMAPs(
127: Message message, boolean isProviderContext,
128: boolean isOutbound) {
129: return org.apache.cxf.ws.addressing.ContextUtils.retrieveMAPs(
130: message, isProviderContext, isOutbound);
131: }
132:
133: /**
134: * Store MAPs in the message.
135: *
136: * @param maps the MAPs to store
137: * @param message the current message
138: * @param isOutbound true iff the message is outbound
139: * @param isRequestor true iff the current messaging role is that of
140: * requestor
141: * @param handler true if HANDLER scope, APPLICATION scope otherwise
142: */
143: public static void storeMAPs(AddressingProperties maps,
144: Message message, boolean isOutbound, boolean isRequestor) {
145: org.apache.cxf.ws.addressing.ContextUtils.storeMAPs(maps,
146: message, isOutbound, isRequestor);
147: }
148:
149: /**
150: * Ensures the appropriate version of WS-Addressing is used.
151: *
152: * @param maps the addressing properties
153: */
154: public static void ensureExposedVersion(AddressingProperties maps) {
155: ((AddressingPropertiesImpl) maps)
156: .exposeAs(VersionTransformer.Names200408.WSA_NAMESPACE_NAME);
157: }
158:
159: public static String getRMPropertiesKey(boolean outbound) {
160: return outbound ? RMMessageConstants.RM_PROPERTIES_OUTBOUND
161: : RMMessageConstants.RM_PROPERTIES_INBOUND;
162: }
163: }
|