KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > servicemix > wsn > AbstractPublisher


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;
18
19 import java.util.List JavaDoc;
20
21 import javax.jws.WebMethod;
22 import javax.jws.WebParam;
23 import javax.jws.WebResult;
24 import javax.jws.WebService;
25
26 import org.oasis_open.docs.wsn.b_2.InvalidTopicExpressionFaultType;
27 import org.oasis_open.docs.wsn.b_2.NotificationMessageHolderType;
28 import org.oasis_open.docs.wsn.b_2.TopicExpressionType;
29 import org.oasis_open.docs.wsn.br_2.DestroyRegistration;
30 import org.oasis_open.docs.wsn.br_2.DestroyRegistrationResponse;
31 import org.oasis_open.docs.wsn.br_2.PublisherRegistrationFailedFaultType;
32 import org.oasis_open.docs.wsn.br_2.RegisterPublisher;
33 import org.oasis_open.docs.wsn.br_2.ResourceNotDestroyedFaultType;
34 import org.apache.servicemix.wsn.jaxws.InvalidTopicExpressionFault;
35 import org.apache.servicemix.wsn.jaxws.PublisherRegistrationFailedFault;
36 import org.apache.servicemix.wsn.jaxws.PublisherRegistrationManager;
37 import org.apache.servicemix.wsn.jaxws.PublisherRegistrationRejectedFault;
38 import org.apache.servicemix.wsn.jaxws.ResourceNotDestroyedFault;
39 import org.apache.servicemix.wsn.jaxws.ResourceUnknownFault;
40 import org.apache.servicemix.wsn.jaxws.TopicNotSupportedFault;
41 import org.w3._2005._08.addressing.EndpointReferenceType;
42
43 @WebService(endpointInterface = "org.apache.servicemix.wsn.jaxws.PublisherRegistrationManager")
44 public abstract class AbstractPublisher extends AbstractEndpoint
45                                         implements PublisherRegistrationManager {
46
47     protected EndpointReferenceType publisherReference;
48     protected boolean demand;
49     protected List JavaDoc<TopicExpressionType> topic;
50     
51     public AbstractPublisher(String JavaDoc name) {
52         super(name);
53     }
54     
55     /**
56      *
57      * @param destroyRequest
58      * @return
59      * returns org.oasis_open.docs.wsn.br_1.DestroyResponse
60      * @throws ResourceNotDestroyedFault
61      * @throws ResourceUnknownFault
62      */

63     @WebMethod(operationName = "DestroyRegistration")
64     @WebResult(name = "DestroyRegistrationResponse", targetNamespace = "http://docs.oasis-open.org/wsn/br-2", partName = "DestroyRegistrationResponse")
65     public DestroyRegistrationResponse destroyRegistration(
66         @WebParam(name = "DestroyRegistration", targetNamespace = "http://docs.oasis-open.org/wsn/br-2", partName = "DestroyRegistrationRequest")
67         DestroyRegistration destroyRegistrationRequest)
68         throws ResourceNotDestroyedFault, ResourceUnknownFault {
69         
70         destroy();
71         return new DestroyRegistrationResponse();
72     }
73     
74     public abstract void notify(NotificationMessageHolderType messageHolder);
75
76     protected void destroy() throws ResourceNotDestroyedFault {
77         try {
78             unregister();
79         } catch (EndpointRegistrationException e) {
80             ResourceNotDestroyedFaultType fault = new ResourceNotDestroyedFaultType();
81             throw new ResourceNotDestroyedFault("Error unregistering endpoint", fault, e);
82         }
83     }
84
85     protected String JavaDoc createAddress() {
86         return "http://servicemix.org/wsnotification/Publisher/" + getName();
87     }
88
89     public void create(RegisterPublisher registerPublisherRequest) throws InvalidTopicExpressionFault, PublisherRegistrationFailedFault, PublisherRegistrationRejectedFault, ResourceUnknownFault, TopicNotSupportedFault {
90         validatePublisher(registerPublisherRequest);
91         start();
92     }
93     
94     protected void validatePublisher(RegisterPublisher registerPublisherRequest) throws InvalidTopicExpressionFault, PublisherRegistrationFailedFault, PublisherRegistrationRejectedFault, ResourceUnknownFault, TopicNotSupportedFault {
95         // Check consumer reference
96
publisherReference = registerPublisherRequest.getPublisherReference();
97         // Check topic
98
topic = registerPublisherRequest.getTopic();
99         // Check demand based
100
demand = registerPublisherRequest.isDemand() != null ? registerPublisherRequest.isDemand().booleanValue() : false;
101         // Check all parameters
102
if (publisherReference == null) {
103             PublisherRegistrationFailedFaultType fault = new PublisherRegistrationFailedFaultType();
104             throw new PublisherRegistrationFailedFault("Invalid PublisherReference: null", fault);
105         }
106         if (demand) {
107             if (topic == null || topic.size() == 0) {
108                 InvalidTopicExpressionFaultType fault = new InvalidTopicExpressionFaultType();
109                 throw new InvalidTopicExpressionFault("Must specify at least one topic for demand-based publishing", fault);
110             }
111         }
112     }
113     
114     protected abstract void start() throws PublisherRegistrationFailedFault;
115 }
116
Popular Tags