KickJava   Java API By Example, From Geeks To Geeks.

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


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.math.BigInteger JavaDoc;
20 import java.util.List JavaDoc;
21
22 import javax.jws.Oneway;
23 import javax.jws.WebMethod;
24 import javax.jws.WebParam;
25 import javax.jws.WebResult;
26 import javax.jws.WebService;
27
28 import org.apache.commons.logging.Log;
29 import org.apache.commons.logging.LogFactory;
30 import org.oasis_open.docs.wsn.b_2.CreatePullPoint;
31 import org.oasis_open.docs.wsn.b_2.DestroyPullPoint;
32 import org.oasis_open.docs.wsn.b_2.DestroyPullPointResponse;
33 import org.oasis_open.docs.wsn.b_2.GetMessages;
34 import org.oasis_open.docs.wsn.b_2.GetMessagesResponse;
35 import org.oasis_open.docs.wsn.b_2.NotificationMessageHolderType;
36 import org.oasis_open.docs.wsn.b_2.Notify;
37 import org.oasis_open.docs.wsn.b_2.UnableToDestroyPullPointFaultType;
38 import org.apache.servicemix.wsn.jaxws.NotificationConsumer;
39 import org.apache.servicemix.wsn.jaxws.PullPoint;
40 import org.apache.servicemix.wsn.jaxws.ResourceUnknownFault;
41 import org.apache.servicemix.wsn.jaxws.UnableToCreatePullPointFault;
42 import org.apache.servicemix.wsn.jaxws.UnableToDestroyPullPointFault;
43
44 @WebService(endpointInterface = "org.apache.servicemix.wsn.PullPointConsumer")
45 public abstract class AbstractPullPoint extends AbstractEndpoint
46                                         implements PullPoint, NotificationConsumer {
47
48     private static Log log = LogFactory.getLog(AbstractPullPoint.class);
49     
50     protected AbstractCreatePullPoint createPullPoint;
51     
52     public AbstractPullPoint(String JavaDoc name) {
53         super(name);
54     }
55     
56     /**
57      *
58      * @param notify
59      */

60     @WebMethod(operationName = "Notify")
61     @Oneway
62     public void notify(
63         @WebParam(name = "Notify", targetNamespace = "http://docs.oasis-open.org/wsn/b-1", partName = "Notify")
64         Notify notify) {
65     
66         log.debug("Notify");
67         for (NotificationMessageHolderType messageHolder : notify.getNotificationMessage()) {
68             store(messageHolder);
69         }
70     }
71     
72     /**
73      *
74      * @param getMessagesRequest
75      * @return
76      * returns org.oasis_open.docs.wsn.b_1.GetMessagesResponse
77      * @throws ResourceUnknownFault
78      */

79     @WebMethod(operationName = "GetMessages")
80     @WebResult(name = "GetMessagesResponse", targetNamespace = "http://docs.oasis-open.org/wsn/b-1", partName = "GetMessagesResponse")
81     public GetMessagesResponse getMessages(
82         @WebParam(name = "GetMessages", targetNamespace = "http://docs.oasis-open.org/wsn/b-1", partName = "GetMessagesRequest")
83         GetMessages getMessagesRequest)
84         throws ResourceUnknownFault {
85         
86         log.debug("GetMessages");
87         BigInteger JavaDoc max = getMessagesRequest.getMaximumNumber();
88         List JavaDoc<NotificationMessageHolderType> messages = getMessages(max != null ? max.intValue() : 0);
89         GetMessagesResponse response = new GetMessagesResponse();
90         response.getNotificationMessage().addAll(messages);
91         return response;
92     }
93     
94     /**
95      *
96      * @param destroyRequest
97      * @return
98      * returns org.oasis_open.docs.wsn.b_1.DestroyResponse
99      * @throws UnableToDestroyPullPoint
100      */

101     @WebMethod(operationName = "DestroyPullPoint")
102     @WebResult(name = "DestroyPullPointResponse", targetNamespace = "http://docs.oasis-open.org/wsn/b-2", partName = "DestroyPullPointResponse")
103     public DestroyPullPointResponse destroyPullPoint(
104         @WebParam(name = "DestroyPullPoint", targetNamespace = "http://docs.oasis-open.org/wsn/b-2", partName = "DestroyPullPointRequest")
105         DestroyPullPoint destroyPullPointRequest)
106         throws UnableToDestroyPullPointFault {
107         
108         log.debug("Destroy");
109         createPullPoint.destroyPullPoint(getAddress());
110         return new DestroyPullPointResponse();
111     }
112     
113     public void create(CreatePullPoint createPullPointRequest) throws UnableToCreatePullPointFault {
114     }
115     
116     protected abstract void store(NotificationMessageHolderType messageHolder);
117
118     protected abstract List JavaDoc<NotificationMessageHolderType> getMessages(int max) throws ResourceUnknownFault;
119
120     protected void destroy() throws UnableToDestroyPullPointFault {
121         try {
122             unregister();
123         } catch (EndpointRegistrationException e) {
124             UnableToDestroyPullPointFaultType fault = new UnableToDestroyPullPointFaultType();
125             throw new UnableToDestroyPullPointFault("Error unregistering endpoint", fault, e);
126         }
127     }
128
129     protected String JavaDoc createAddress() {
130         return "http://servicemix.org/wsnotification/PullPoint/" + getName();
131     }
132
133     public AbstractCreatePullPoint getCreatePullPoint() {
134         return createPullPoint;
135     }
136
137     public void setCreatePullPoint(AbstractCreatePullPoint createPullPoint) {
138         this.createPullPoint = createPullPoint;
139     }
140 }
141
Popular Tags