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: * @(#)Engine.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 com.sun.jbi.wsdl2.Binding;
032: import com.sun.jbi.wsdl2.BindingOperation;
033: import com.sun.jbi.wsdl2.Description;
034: import com.sun.jbi.wsdl2.Endpoint;
035: import com.sun.jbi.wsdl2.Interface;
036: import com.sun.jbi.wsdl2.InterfaceOperation;
037: import com.sun.jbi.wsdl2.Service;
038: import com.sun.jbi.wsdl2.WsdlWriter;
039:
040: import com.sun.jbi.wsdl2.impl.WsdlFactory;
041:
042: import javax.jbi.component.Component;
043: import javax.jbi.servicedesc.ServiceEndpoint;
044:
045: import javax.xml.namespace.QName;
046:
047: import org.w3c.dom.Document;
048:
049: /** Generic engine skeleton for use with NMS junit/regress tests.
050: * @author Sun Microsystems, Inc.
051: */
052: public abstract class Engine implements Runnable, Component {
053: private Exception mError;
054: private String mFailTxt;
055: protected boolean mIsProvider;
056: protected DeliveryChannelImpl mChannel;
057: protected ServiceEndpoint mEndpoint;
058: protected Document mDocument;
059: protected String mPattern;
060: protected String mEndpointName;
061: protected QName mServiceName;
062: protected Sequencer mSequencer;
063:
064: protected Engine(DeliveryChannelImpl channel) {
065: mChannel = channel;
066: }
067:
068: /** Used for provider cases. */
069: public void init(QName service, String endpoint, String pattern)
070: throws Exception {
071: mPattern = pattern;
072: mEndpointName = endpoint;
073: mServiceName = service;
074: mEndpoint = mChannel.activateEndpoint(service, endpoint);
075: mIsProvider = true;
076: }
077:
078: /** Used in consumer cases. */
079: public void init(QName service) throws Exception {
080: ServiceEndpoint[] refs;
081:
082: refs = mChannel.getEndpointsForService(service);
083: if (refs.length == 0) {
084: throw new Exception("No endpoints found for service: "
085: + service.getLocalPart());
086: }
087:
088: mIsProvider = false;
089: mEndpoint = refs[0];
090: }
091:
092: public void setSequencer(Sequencer sequencer) {
093: mSequencer = sequencer;
094: }
095:
096: public Sequencer getSequencer() {
097: return (mSequencer);
098: }
099:
100: public void run() {
101: try {
102: start();
103: } catch (Exception ex) {
104: mError = ex;
105: }
106: }
107:
108: public void stop() throws Exception {
109: if (mIsProvider) {
110: mChannel.deactivateEndpoint(mEndpoint);
111: }
112:
113: mChannel.close();
114: }
115:
116: public abstract void start() throws Exception;
117:
118: public void checkError() throws Exception {
119: if (mError != null) {
120: throw mError;
121: } else if (mFailTxt != null) {
122: throw new Exception(mFailTxt);
123: }
124: }
125:
126: public void setFailure(String txt) {
127: mFailTxt = txt;
128: }
129:
130: public Document getDescription() {
131: try {
132: WsdlFactory wf = WsdlFactory.newInstance();
133: Description d = wf.newDescription("");
134: Interface i = d.addNewInterface("if1");
135: InterfaceOperation io = i.addNewOperation();
136: Binding b = d.addNewBinding("binding1");
137: Service s = d.addNewService(mServiceName.getLocalPart());
138: Endpoint e = s.addNewEndpoint(mEndpointName, b);
139: BindingOperation bo = b.addNewOperation();
140:
141: io.setName("foobar");
142: io.setPattern(mPattern);
143: bo.setInterfaceOperation(io.getQualifiedName());
144: e.setBinding(b);
145: s.setInterface(i);
146: b.setType("type1");
147: b.setInterface(i);
148: return (d.toXmlDocument());
149: } catch (com.sun.jbi.wsdl2.WsdlException wEx) {
150: System.out.println("Problem creating WSDL: "
151: + wEx.toString());
152: return (null);
153: }
154: }
155:
156: public javax.jbi.component.ComponentLifeCycle getLifeCycle() {
157: return null;
158: }
159:
160: public javax.jbi.component.ServiceUnitManager getServiceUnitManager() {
161: return null;
162: }
163:
164: public Document getServiceDescription(ServiceEndpoint endpoint) {
165: return getDescription();
166: }
167:
168: /** This method is called by JBI to check if this component, in the role of
169: * provider of the service indicated by the given exchange, can actually
170: * perform the operation desired.
171: */
172: public boolean isExchangeWithConsumerOkay(
173: javax.jbi.servicedesc.ServiceEndpoint endpoint,
174: javax.jbi.messaging.MessageExchange exchange) {
175: return true;
176: }
177:
178: /** This method is called by JBI to check if this component, in the role of
179: * consumer of the service indicated by the given exchange, can actually
180: * interact with the the provider completely.
181: */
182: public boolean isExchangeWithProviderOkay(
183: javax.jbi.servicedesc.ServiceEndpoint endpoint,
184: javax.jbi.messaging.MessageExchange exchange) {
185: return true;
186: }
187:
188: public javax.jbi.servicedesc.ServiceEndpoint resolveEndpointReference(
189: org.w3c.dom.DocumentFragment epr) {
190: return null;
191: }
192: }
|