KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > servicemix > eip > support > ExchangeTarget


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17 package org.apache.servicemix.eip.support;
18
19 import javax.jbi.component.ComponentContext;
20 import javax.jbi.messaging.MessageExchange;
21 import javax.jbi.messaging.MessagingException;
22 import javax.jbi.servicedesc.ServiceEndpoint;
23 import javax.xml.namespace.QName JavaDoc;
24
25 import org.apache.servicemix.jbi.resolver.URIResolver;
26 import org.springframework.beans.factory.InitializingBean;
27
28 /**
29  * An ExchangeTarget may be used to specify the target of an exchange,
30  * while retaining all the JBI features (interface based routing, service
31  * name based routing or endpoint routing).
32  *
33  * @author gnodet
34  * @version $Revision: 376451 $
35  * @org.apache.xbean.XBean element="exchange-target"
36  */

37 public class ExchangeTarget implements InitializingBean {
38
39     private QName JavaDoc _interface;
40
41     private QName JavaDoc operation;
42
43     private QName JavaDoc service;
44
45     private String JavaDoc endpoint;
46     
47     private String JavaDoc uri;
48
49     /**
50      * @return Returns the endpoint.
51      */

52     public String JavaDoc getEndpoint() {
53         return endpoint;
54     }
55
56     /**
57      * @param endpoint
58      * The endpoint to set.
59      */

60     public void setEndpoint(String JavaDoc endpoint) {
61         this.endpoint = endpoint;
62     }
63
64     /**
65      * @return Returns the interface name.
66      */

67     public QName JavaDoc getInterface() {
68         return _interface;
69     }
70
71     /**
72      * @param interface name
73      * The interface name to set.
74      */

75     public void setInterface(QName JavaDoc _interface) {
76         this._interface = _interface;
77     }
78
79     /**
80      * @return Returns the operation name.
81      */

82     public QName JavaDoc getOperation() {
83         return operation;
84     }
85
86     /**
87      * @param operation
88      * The operation to set.
89      */

90     public void setOperation(QName JavaDoc operation) {
91         this.operation = operation;
92     }
93
94     /**
95      * @return Returns the service.
96      */

97     public QName JavaDoc getService() {
98         return service;
99     }
100
101     /**
102      * @param service
103      * The service to set.
104      */

105     public void setService(QName JavaDoc service) {
106         this.service = service;
107     }
108
109     /**
110      * @return the uri
111      */

112     public String JavaDoc getUri() {
113         return uri;
114     }
115
116     /**
117      * @param uri the uri to set
118      */

119     public void setUri(String JavaDoc uri) {
120         this.uri = uri;
121     }
122
123     /**
124      * Configures the target on the newly created exchange
125      * @param exchange the exchange to configure
126      * @throws MessagingException if the target could not be configured
127      */

128     public void configureTarget(MessageExchange exchange, ComponentContext context) throws MessagingException {
129         if (_interface == null && service == null && uri == null) {
130             throw new MessagingException("interface, service or uri should be specified");
131         }
132         if (uri != null) {
133             URIResolver.configureExchange(exchange, context, uri);
134         }
135         if (_interface != null) {
136             exchange.setInterfaceName(_interface);
137         }
138         if (operation != null) {
139             exchange.setOperation(operation);
140         }
141         if (service != null) {
142             exchange.setService(service);
143             if (endpoint != null) {
144                 ServiceEndpoint se = context.getEndpoint(service, endpoint);
145                 exchange.setEndpoint(se);
146             }
147         }
148     }
149
150     /* (non-Javadoc)
151      * @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
152      */

153     public void afterPropertiesSet() throws Exception JavaDoc {
154         if (_interface == null && service == null && uri == null) {
155             throw new MessagingException("interface, service or uri should be specified");
156         }
157     }
158
159 }
160
Popular Tags