001: /*
002: * BEGIN_HEADER - DO NOT EDIT
003: *
004: * The contents of this file are subject to the terms
005: * of the Common Development and Distribution License
006: * (the "License"). You may not use this file except
007: * in compliance with the License.
008: *
009: * You can obtain a copy of the license at
010: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
011: * See the License for the specific language governing
012: * permissions and limitations under the License.
013: *
014: * When distributing Covered Code, include this CDDL
015: * HEADER in each file and include the License file at
016: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
017: * If applicable add the following below this CDDL HEADER,
018: * with the fields enclosed by brackets "[]" replaced with
019: * your own identifying information: Portions Copyright
020: * [year] [name of copyright owner]
021: */
022:
023: /*
024: * @(#)Binding.java
025: * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
026: *
027: * END_HEADER - DO NOT EDIT
028: */
029: package com.sun.jbi.messaging;
030:
031: import javax.jbi.servicedesc.ServiceEndpoint;
032:
033: import javax.xml.namespace.QName;
034:
035: /** Generic binding skeleton for use with NMS junit/regress tests.
036: * @author Sun Microsystems, Inc.
037: */
038: public abstract class Binding implements Runnable {
039: private Exception mError;
040: private String mFailTxt;
041: protected boolean mIsProvider;
042: protected DeliveryChannelImpl mChannel;
043: protected ServiceEndpoint mEndpoint;
044: protected Sequencer mSequencer;
045:
046: protected Binding(DeliveryChannelImpl channel) {
047: mChannel = channel;
048: }
049:
050: /** Used for provider cases. */
051: public void init(QName service, String endpoint) throws Exception {
052: mEndpoint = mChannel.activateEndpoint(service, endpoint);
053: mIsProvider = true;
054: }
055:
056: /** Used in consumer cases. */
057: public void init(QName service) throws Exception {
058: ServiceEndpoint[] refs;
059:
060: refs = mChannel.getEndpointsForService(service);
061: if (refs.length == 0) {
062: throw new Exception("No endpoints found for service: "
063: + service.getLocalPart());
064: }
065:
066: mIsProvider = false;
067: mEndpoint = refs[0];
068: }
069:
070: public void setSequencer(Sequencer sequencer) {
071: mSequencer = sequencer;
072: }
073:
074: public Sequencer getSequencer() {
075: return (mSequencer);
076: }
077:
078: public void stop() throws Exception {
079: if (mIsProvider) {
080: mChannel.deactivateEndpoint(mEndpoint);
081: }
082:
083: mChannel.close();
084: }
085:
086: public void run() {
087: try {
088: start();
089: } catch (Exception ex) {
090: mError = ex;
091: }
092: }
093:
094: public abstract void start() throws Exception;
095:
096: public void checkError() throws Exception {
097: if (mError != null) {
098: throw mError;
099: } else if (mFailTxt != null) {
100: throw new Exception(mFailTxt);
101: }
102: }
103:
104: public void setFailure(String txt) {
105: mFailTxt = txt;
106: }
107: }
|