KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > servicemix > components > xfire > XFireOutBinding


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.components.xfire;
18
19 import org.apache.servicemix.components.util.OutBinding;
20 import org.codehaus.xfire.MessageContext;
21 import org.codehaus.xfire.XFire;
22 import org.codehaus.xfire.exchange.InMessage;
23 import org.codehaus.xfire.transport.Channel;
24 import org.codehaus.xfire.transport.Transport;
25 import org.codehaus.xfire.transport.local.LocalTransport;
26
27 import javax.jbi.JBIException;
28 import javax.jbi.messaging.MessageExchange;
29 import javax.jbi.messaging.NormalizedMessage;
30 import javax.xml.stream.XMLStreamReader;
31
32 public class XFireOutBinding extends OutBinding {
33     private XMarshaler marshaler;
34
35     private XFire xfire;
36
37     public XFireOutBinding()
38     {
39         super();
40
41         this.marshaler = new XMarshaler();
42     }
43     
44     protected void process(MessageExchange messageExchange, NormalizedMessage nm) throws Exception JavaDoc {
45         
46         XMLStreamReader reader = marshaler.createStreamReader(nm);
47         if (reader == null) {
48             throw new JBIException("Could not get source as XMLStreamReader.");
49         }
50
51         InMessage in = new InMessage(reader, "");
52         MessageContext context = new MessageContext();
53         context.setXFire(xfire);
54         context.setService(xfire.getServiceRegistry().getService(getService().getLocalPart()));
55
56         Transport transport = xfire.getTransportManager().getTransport(LocalTransport.BINDING_ID);
57         Channel channel = transport.createChannel();
58         channel.receive(context, in);
59
60         done(messageExchange);
61     }
62
63     public XFire getXfire() {
64         return xfire;
65     }
66
67     public void setXfire(XFire xfire) {
68         this.xfire = xfire;
69     }
70 }
71
Popular Tags