KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > servicemix > wsn > jbi > JbiPublisher


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.wsn.jbi;
18
19 import javax.jbi.JBIException;
20 import javax.jbi.component.ComponentContext;
21 import javax.jbi.servicedesc.ServiceEndpoint;
22 import javax.xml.bind.JAXBException;
23 import javax.xml.namespace.QName JavaDoc;
24
25 import org.apache.servicemix.wsn.client.AbstractWSAClient;
26 import org.apache.servicemix.wsn.client.NotificationBroker;
27 import org.apache.servicemix.wsn.client.Subscription;
28 import org.apache.servicemix.wsn.component.WSNLifeCycle;
29 import org.apache.servicemix.wsn.jaxws.InvalidTopicExpressionFault;
30 import org.apache.servicemix.wsn.jaxws.PublisherRegistrationFailedFault;
31 import org.apache.servicemix.wsn.jaxws.PublisherRegistrationRejectedFault;
32 import org.apache.servicemix.wsn.jaxws.ResourceUnknownFault;
33 import org.apache.servicemix.wsn.jaxws.TopicNotSupportedFault;
34 import org.apache.servicemix.wsn.jms.JmsPublisher;
35 import org.oasis_open.docs.wsn.br_2.PublisherRegistrationFailedFaultType;
36 import org.oasis_open.docs.wsn.br_2.RegisterPublisher;
37
38 public class JbiPublisher extends JmsPublisher {
39
40     private WSNLifeCycle lifeCycle;
41     private ServiceEndpoint endpoint;
42     private String JavaDoc notificationBrokerAddress;
43     
44     public JbiPublisher(String JavaDoc name) {
45         super(name);
46     }
47
48     public String JavaDoc getNotificationBrokerAddress() {
49         return notificationBrokerAddress;
50     }
51
52     public void setNotificationBrokerAddress(String JavaDoc notificationBrokerAddress) {
53         this.notificationBrokerAddress = notificationBrokerAddress;
54     }
55     
56     @Override JavaDoc
57     protected Object JavaDoc startSubscription() {
58         Subscription subscription = null;
59         try {
60             NotificationBroker broker = new NotificationBroker(getContext());
61             broker.setResolver(AbstractWSAClient.resolveWSA(publisherReference));
62             subscription = broker.subscribe(AbstractWSAClient.createWSA(notificationBrokerAddress),
63                                                          "noTopic", null);
64         } catch (JBIException e) {
65             // TODO Auto-generated catch block
66
e.printStackTrace();
67         } catch (JAXBException e) {
68             // TODO Auto-generated catch block
69
e.printStackTrace();
70         }
71         return subscription;
72     }
73
74     @Override JavaDoc
75     protected void destroySubscription(Object JavaDoc subscription) {
76         try {
77             ((Subscription) subscription).unsubscribe();
78         } catch (JBIException e) {
79             // TODO Auto-generated catch block
80
e.printStackTrace();
81         }
82     }
83     
84     @Override JavaDoc
85     protected void validatePublisher(RegisterPublisher registerPublisherRequest) throws InvalidTopicExpressionFault, PublisherRegistrationFailedFault, PublisherRegistrationRejectedFault, ResourceUnknownFault, TopicNotSupportedFault {
86         super.validatePublisher(registerPublisherRequest);
87         String JavaDoc[] parts = split(publisherReference.getAddress().getValue());
88         endpoint = getContext().getEndpoint(new QName JavaDoc(parts[0], parts[1]), parts[2]);
89         if (endpoint == null) {
90             PublisherRegistrationFailedFaultType fault = new PublisherRegistrationFailedFaultType();
91             throw new PublisherRegistrationFailedFault("Unable to resolve consumer reference endpoint", fault);
92         }
93     }
94     
95     protected String JavaDoc[] split(String JavaDoc uri) {
96         char sep;
97         if (uri.indexOf('/') > 0) {
98             sep = '/';
99         } else {
100             sep = ':';
101         }
102         int idx1 = uri.lastIndexOf(sep);
103         int idx2 = uri.lastIndexOf(sep, idx1 - 1);
104         String JavaDoc epName = uri.substring(idx1 + 1);
105         String JavaDoc svcName = uri.substring(idx2 + 1, idx1);
106         String JavaDoc nsUri = uri.substring(0, idx2);
107         return new String JavaDoc[] { nsUri, svcName, epName };
108     }
109
110     public ComponentContext getContext() {
111         return lifeCycle.getContext();
112     }
113
114     public WSNLifeCycle getLifeCycle() {
115         return lifeCycle;
116     }
117
118     public void setLifeCycle(WSNLifeCycle lifeCycle) {
119         this.lifeCycle = lifeCycle;
120     }
121
122 }
123
Popular Tags