1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
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 }