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.endpoint;
019:
020: import java.io.IOException;
021:
022: import org.apache.cxf.message.Exchange;
023: import org.apache.cxf.message.Message;
024: import org.apache.cxf.transport.Conduit;
025: import org.apache.cxf.transport.MessageObserver;
026:
027: /**
028: * Strategy for retreival of a pre-existing Conduit to mediate an
029: * outbound message.
030: */
031: public class PreexistingConduitSelector implements ConduitSelector {
032:
033: private Conduit selectedConduit;
034: private Endpoint endpoint;
035:
036: /**
037: * Constructor.
038: *
039: * @param c the pre-existing Conduit.
040: */
041: public PreexistingConduitSelector(Conduit c) {
042: this (c, null);
043: }
044:
045: /**
046: * Constructor.
047: *
048: * @param c the pre-existing Conduit.
049: * @param e the target Endpoint
050: */
051: public PreexistingConduitSelector(Conduit c, Endpoint e) {
052: selectedConduit = c;
053: endpoint = e;
054: }
055:
056: /**
057: * Called prior to the interceptor chain being traversed.
058: *
059: * @param message the current Message
060: */
061: public void prepare(Message message) {
062: MessageObserver observer = message.getExchange().get(
063: MessageObserver.class);
064: if (observer != null) {
065: selectedConduit.setMessageObserver(observer);
066: }
067: }
068:
069: /**
070: * Called when a Conduit is actually required.
071: *
072: * @param message
073: * @return the Conduit to use for mediation of the message
074: */
075: public Conduit selectConduit(Message message) {
076: return selectedConduit;
077: }
078:
079: /**
080: * Called on completion of the MEP for which the Conduit was required.
081: *
082: * @param exchange represents the completed MEP
083: */
084: public void complete(Exchange exchange) {
085: try {
086: if (exchange.getInMessage() != null) {
087: selectedConduit.close(exchange.getInMessage());
088: }
089: } catch (IOException e) {
090: //IGNORE
091: }
092: }
093:
094: /**
095: * @return the encapsulated Endpoint
096: */
097: public Endpoint getEndpoint() {
098: return endpoint;
099: }
100:
101: /**
102: * @param ep the endpoint to encapsulate
103: */
104: public void setEndpoint(Endpoint ep) {
105: endpoint = ep;
106: }
107: }
|