1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portal.kernel.poller;
24  
25  import com.liferay.portal.kernel.util.GetterUtil;
26  
27  /**
28   * <a href="BasePollerProcessor.java.html"><b><i>View Source</i></b></a>
29   *
30   * @author Brian Wing Shun Chan
31   */
32  public abstract class BasePollerProcessor implements PollerProcessor {
33  
34      public void receive(
35              PollerRequest pollerRequest, PollerResponse pollerResponse)
36          throws PollerException {
37  
38          try {
39              doReceive(pollerRequest, pollerResponse);
40          }
41          catch (Exception e) {
42              throw new PollerException(e);
43          }
44      }
45  
46      public void send(PollerRequest pollerRequest) throws PollerException {
47          try {
48              doSend(pollerRequest);
49          }
50          catch (Exception e) {
51              throw new PollerException(e);
52          }
53      }
54  
55      protected abstract void doReceive(
56              PollerRequest pollerRequest, PollerResponse pollerResponse)
57          throws Exception;
58  
59      protected abstract void doSend(PollerRequest pollerRequest)
60          throws Exception;
61  
62      protected boolean getBoolean(PollerRequest pollerRequest, String name) {
63          return getBoolean(pollerRequest, name, GetterUtil.DEFAULT_BOOLEAN);
64      }
65  
66      protected boolean getBoolean(
67          PollerRequest pollerRequest, String name, boolean defaultValue) {
68  
69          return GetterUtil.getBoolean(
70              pollerRequest.getParameterMap().get(name), defaultValue);
71      }
72  
73      protected double getDouble(
74          PollerRequest pollerRequest, String name) {
75  
76          return getDouble(pollerRequest, name, -1);
77      }
78  
79      protected double getDouble(
80          PollerRequest pollerRequest, String name, double defaultValue) {
81  
82          return GetterUtil.getDouble(
83              pollerRequest.getParameterMap().get(name), defaultValue);
84      }
85  
86      protected int getInteger(PollerRequest pollerRequest, String name) {
87          return getInteger(pollerRequest, name, -1);
88      }
89  
90      protected int getInteger(
91          PollerRequest pollerRequest, String name, int defaultValue) {
92  
93          return GetterUtil.getInteger(
94              pollerRequest.getParameterMap().get(name), defaultValue);
95      }
96  
97      protected long getLong(PollerRequest pollerRequest, String name) {
98          return getLong(pollerRequest, name, -1);
99      }
100 
101     protected long getLong(
102         PollerRequest pollerRequest, String name, long defaultValue) {
103 
104         return GetterUtil.getLong(
105             pollerRequest.getParameterMap().get(name), defaultValue);
106     }
107 
108     protected String getString(PollerRequest pollerRequest, String name) {
109         return getString(pollerRequest, name, null);
110     }
111 
112     protected String getString(
113         PollerRequest pollerRequest, String name, String defaultValue) {
114 
115         return GetterUtil.getString(
116             pollerRequest.getParameterMap().get(name), defaultValue);
117     }
118 
119 }