001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.kernel.poller;
016    
017    import com.liferay.portal.kernel.util.GetterUtil;
018    
019    /**
020     * @author Brian Wing Shun Chan
021     */
022    public abstract class BasePollerProcessor implements PollerProcessor {
023    
024            public void receive(
025                            PollerRequest pollerRequest, PollerResponse pollerResponse)
026                    throws PollerException {
027    
028                    try {
029                            doReceive(pollerRequest, pollerResponse);
030                    }
031                    catch (Exception e) {
032                            throw new PollerException(e);
033                    }
034            }
035    
036            public void send(PollerRequest pollerRequest) throws PollerException {
037                    try {
038                            doSend(pollerRequest);
039                    }
040                    catch (Exception e) {
041                            throw new PollerException(e);
042                    }
043            }
044    
045            protected abstract void doReceive(
046                            PollerRequest pollerRequest, PollerResponse pollerResponse)
047                    throws Exception;
048    
049            protected abstract void doSend(PollerRequest pollerRequest)
050                    throws Exception;
051    
052            protected boolean getBoolean(PollerRequest pollerRequest, String name) {
053                    return getBoolean(pollerRequest, name, GetterUtil.DEFAULT_BOOLEAN);
054            }
055    
056            protected boolean getBoolean(
057                    PollerRequest pollerRequest, String name, boolean defaultValue) {
058    
059                    return GetterUtil.getBoolean(
060                            pollerRequest.getParameterMap().get(name), defaultValue);
061            }
062    
063            protected double getDouble(
064                    PollerRequest pollerRequest, String name) {
065    
066                    return getDouble(pollerRequest, name, -1);
067            }
068    
069            protected double getDouble(
070                    PollerRequest pollerRequest, String name, double defaultValue) {
071    
072                    return GetterUtil.getDouble(
073                            pollerRequest.getParameterMap().get(name), defaultValue);
074            }
075    
076            protected int getInteger(PollerRequest pollerRequest, String name) {
077                    return getInteger(pollerRequest, name, -1);
078            }
079    
080            protected int getInteger(
081                    PollerRequest pollerRequest, String name, int defaultValue) {
082    
083                    return GetterUtil.getInteger(
084                            pollerRequest.getParameterMap().get(name), defaultValue);
085            }
086    
087            protected long getLong(PollerRequest pollerRequest, String name) {
088                    return getLong(pollerRequest, name, -1);
089            }
090    
091            protected long getLong(
092                    PollerRequest pollerRequest, String name, long defaultValue) {
093    
094                    return GetterUtil.getLong(
095                            pollerRequest.getParameterMap().get(name), defaultValue);
096            }
097    
098            protected String getString(PollerRequest pollerRequest, String name) {
099                    return getString(pollerRequest, name, null);
100            }
101    
102            protected String getString(
103                    PollerRequest pollerRequest, String name, String defaultValue) {
104    
105                    return GetterUtil.getString(
106                            pollerRequest.getParameterMap().get(name), defaultValue);
107            }
108    
109    }