001    /**
002     * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portal.kernel.poller;
016    
017    import com.liferay.portal.kernel.util.StringBundler;
018    import com.liferay.portal.kernel.util.Validator;
019    
020    import java.util.Collections;
021    import java.util.Map;
022    
023    import javax.servlet.http.HttpServletRequest;
024    
025    /**
026     * @author Brian Wing Shun Chan
027     */
028    public class PollerRequest {
029    
030            public PollerRequest(
031                    HttpServletRequest request, PollerHeader pollerHeader, String portletId,
032                    Map<String, String> parameterMap, String chunkId,
033                    boolean receiveRequest) {
034    
035                    _request = request;
036                    _pollerHeader = pollerHeader;
037                    _portletId = portletId;
038                    _parameterMap = parameterMap;
039                    _chunkId = chunkId;
040                    _receiveRequest = receiveRequest;
041            }
042    
043            @Override
044            public boolean equals(Object obj) {
045                    if (this == obj) {
046                            return true;
047                    }
048    
049                    if (!(obj instanceof PollerRequest)) {
050                            return false;
051                    }
052    
053                    PollerRequest portletRequest = (PollerRequest)obj;
054    
055                    if (Validator.equals(_portletId, portletRequest._portletId)) {
056                            return true;
057                    }
058    
059                    return false;
060            }
061    
062            public long getBrowserKey() {
063                    return _pollerHeader.getBrowserKey();
064            }
065    
066            public String getChunkId() {
067                    return _chunkId;
068            }
069    
070            public long getCompanyId() {
071                    return _pollerHeader.getCompanyId();
072            }
073    
074            public Map<String, String> getParameterMap() {
075                    return _parameterMap;
076            }
077    
078            public PollerHeader getPollerHeader() {
079                    return _pollerHeader;
080            }
081    
082            public String getPortletId() {
083                    return _portletId;
084            }
085    
086            public String[] getPortletIds() {
087                    return _pollerHeader.getPortletIds();
088            }
089    
090            public HttpServletRequest getRequest() {
091                    return _request;
092            }
093    
094            public long getTimestamp() {
095                    return _pollerHeader.getTimestamp();
096            }
097    
098            public long getUserId() {
099                    return _pollerHeader.getUserId();
100            }
101    
102            @Override
103            public int hashCode() {
104                    if (_portletId != null) {
105                            return _portletId.hashCode();
106                    }
107                    else {
108                            return 0;
109                    }
110            }
111    
112            public boolean isInitialRequest() {
113                    return _pollerHeader.isInitialRequest();
114            }
115    
116            public boolean isReceiveRequest() {
117                    return _receiveRequest;
118            }
119    
120            public boolean isStartPolling() {
121                    return _pollerHeader.isStartPolling();
122            }
123    
124            @Override
125            public String toString() {
126                    StringBundler sb = new StringBundler(11);
127    
128                    sb.append("{chunkId=");
129                    sb.append(_chunkId);
130                    sb.append(", parameterMap=");
131                    sb.append(_parameterMap);
132                    sb.append(", pollerHeader=");
133                    sb.append(_pollerHeader);
134                    sb.append(", portletId=");
135                    sb.append(_portletId);
136                    sb.append(", receiveRequest=");
137                    sb.append(_receiveRequest);
138                    sb.append("}");
139    
140                    return sb.toString();
141            }
142    
143            private String _chunkId;
144            private Map<String, String> _parameterMap = Collections.emptyMap();
145            private PollerHeader _pollerHeader;
146            private String _portletId;
147            private boolean _receiveRequest;
148            private HttpServletRequest _request;
149    
150    }