1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
13   */
14  
15  package com.liferay.portal.kernel.poller;
16  
17  import com.liferay.portal.kernel.util.GetterUtil;
18  
19  /**
20   * <a href="BasePollerProcessor.java.html"><b><i>View Source</i></b></a>
21   *
22   * @author Brian Wing Shun Chan
23   */
24  public abstract class BasePollerProcessor implements PollerProcessor {
25  
26      public void receive(
27              PollerRequest pollerRequest, PollerResponse pollerResponse)
28          throws PollerException {
29  
30          try {
31              doReceive(pollerRequest, pollerResponse);
32          }
33          catch (Exception e) {
34              throw new PollerException(e);
35          }
36      }
37  
38      public void send(PollerRequest pollerRequest) throws PollerException {
39          try {
40              doSend(pollerRequest);
41          }
42          catch (Exception e) {
43              throw new PollerException(e);
44          }
45      }
46  
47      protected abstract void doReceive(
48              PollerRequest pollerRequest, PollerResponse pollerResponse)
49          throws Exception;
50  
51      protected abstract void doSend(PollerRequest pollerRequest)
52          throws Exception;
53  
54      protected boolean getBoolean(PollerRequest pollerRequest, String name) {
55          return getBoolean(pollerRequest, name, GetterUtil.DEFAULT_BOOLEAN);
56      }
57  
58      protected boolean getBoolean(
59          PollerRequest pollerRequest, String name, boolean defaultValue) {
60  
61          return GetterUtil.getBoolean(
62              pollerRequest.getParameterMap().get(name), defaultValue);
63      }
64  
65      protected double getDouble(
66          PollerRequest pollerRequest, String name) {
67  
68          return getDouble(pollerRequest, name, -1);
69      }
70  
71      protected double getDouble(
72          PollerRequest pollerRequest, String name, double defaultValue) {
73  
74          return GetterUtil.getDouble(
75              pollerRequest.getParameterMap().get(name), defaultValue);
76      }
77  
78      protected int getInteger(PollerRequest pollerRequest, String name) {
79          return getInteger(pollerRequest, name, -1);
80      }
81  
82      protected int getInteger(
83          PollerRequest pollerRequest, String name, int defaultValue) {
84  
85          return GetterUtil.getInteger(
86              pollerRequest.getParameterMap().get(name), defaultValue);
87      }
88  
89      protected long getLong(PollerRequest pollerRequest, String name) {
90          return getLong(pollerRequest, name, -1);
91      }
92  
93      protected long getLong(
94          PollerRequest pollerRequest, String name, long defaultValue) {
95  
96          return GetterUtil.getLong(
97              pollerRequest.getParameterMap().get(name), defaultValue);
98      }
99  
100     protected String getString(PollerRequest pollerRequest, String name) {
101         return getString(pollerRequest, name, null);
102     }
103 
104     protected String getString(
105         PollerRequest pollerRequest, String name, String defaultValue) {
106 
107         return GetterUtil.getString(
108             pollerRequest.getParameterMap().get(name), defaultValue);
109     }
110 
111 }