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.transport;
019:
020: import java.util.logging.Logger;
021:
022: import org.apache.cxf.Bus;
023: import org.apache.cxf.service.model.EndpointInfo;
024: import org.apache.cxf.ws.addressing.AttributedURIType;
025: import org.apache.cxf.ws.addressing.EndpointReferenceType;
026: import org.apache.cxf.wsdl.EndpointReferenceUtils;
027:
028: public abstract class AbstractObservable implements Observable {
029:
030: protected MessageObserver incomingObserver;
031:
032: /**
033: * Register a message observer for incoming messages.
034: *
035: * @param observer the observer to notify on receipt of incoming
036: * message
037: */
038: public synchronized void setMessageObserver(MessageObserver observer) {
039: if (observer != incomingObserver) {
040: MessageObserver old = incomingObserver;
041: incomingObserver = observer;
042: if (observer != null) {
043: getLogger().fine(
044: "registering incoming observer: " + observer);
045: if (old == null) {
046: activate();
047: }
048: } else {
049: if (old != null) {
050: getLogger().fine(
051: "unregistering incoming observer: " + old);
052: deactivate();
053: }
054: }
055: }
056: }
057:
058: /**
059: * @return the observer to notify on receipt of incoming message
060: */
061: public MessageObserver getMessageObserver() {
062: return incomingObserver;
063: }
064:
065: /**
066: * Get the target reference .
067: *
068: * @param ei the corresponding EndpointInfo
069: * @return the actual target
070: */
071: protected static EndpointReferenceType getTargetReference(
072: EndpointInfo ei, Bus bus) {
073: return getTargetReference(ei, null, bus);
074: }
075:
076: /**
077: * Get the target endpoint reference.
078: *
079: * @param ei the corresponding EndpointInfo
080: * @param t the given target EPR if available
081: * @param bus the Bus
082: * @return the actual target
083: */
084: protected static EndpointReferenceType getTargetReference(
085: EndpointInfo ei, EndpointReferenceType t, Bus bus) {
086: EndpointReferenceType ref = null;
087: if (null == t) {
088: ref = new EndpointReferenceType();
089: AttributedURIType address = new AttributedURIType();
090: address.setValue(ei.getAddress());
091: ref.setAddress(address);
092: if (ei.getService() != null) {
093: EndpointReferenceUtils.setServiceAndPortName(ref, ei
094: .getService().getName(), ei.getName()
095: .getLocalPart());
096: }
097: } else {
098: ref = t;
099: }
100: return ref;
101: }
102:
103: /**
104: * Activate messages flow.
105: */
106: protected void activate() {
107: // nothing to do by default
108: }
109:
110: /**
111: * Deactivate messages flow.
112: */
113: protected void deactivate() {
114: // nothing to do by default
115: }
116:
117: /**
118: * @return the logger to use
119: */
120: protected abstract Logger getLogger();
121:
122: }
|