001    /**
002     * Copyright (c) 2000-2011 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.service;
016    
017    import com.liferay.portal.kernel.util.Constants;
018    import com.liferay.portal.kernel.util.Validator;
019    import com.liferay.portal.kernel.workflow.WorkflowConstants;
020    import com.liferay.portal.model.PortletPreferencesIds;
021    
022    import java.io.Serializable;
023    
024    import java.util.Date;
025    import java.util.LinkedHashMap;
026    import java.util.Map;
027    
028    /**
029     * @author Raymond Augé
030     * @author Brian Wing Shun Chan
031     * @author Jorge Ferrer
032     */
033    public class ServiceContext implements Cloneable, Serializable {
034    
035            public ServiceContext() {
036                    _attributes = new LinkedHashMap<String, Serializable>();
037                    _expandoBridgeAttributes = new LinkedHashMap<String, Serializable>();
038            }
039    
040            @Override
041            public Object clone() {
042                    ServiceContext serviceContext = new ServiceContext();
043    
044                    serviceContext.setAddCommunityPermissions(getAddCommunityPermissions());
045                    serviceContext.setAddGuestPermissions(getAddGuestPermissions());
046                    serviceContext.setAssetCategoryIds(getAssetCategoryIds());
047                    serviceContext.setAssetTagNames(getAssetTagNames());
048                    serviceContext.setAttributes(getAttributes());
049                    serviceContext.setCommand(getCommand());
050                    serviceContext.setCommunityPermissions(getCommunityPermissions());
051                    serviceContext.setCompanyId(getCompanyId());
052                    serviceContext.setCreateDate(getCreateDate());
053                    serviceContext.setCurrentURL(getCurrentURL());
054                    serviceContext.setExpandoBridgeAttributes(getExpandoBridgeAttributes());
055                    serviceContext.setGuestPermissions(getGuestPermissions());
056                    serviceContext.setHeaders(getHeaders());
057                    serviceContext.setLanguageId(getLanguageId());
058                    serviceContext.setLayoutFullURL(getLayoutFullURL());
059                    serviceContext.setLayoutURL(getLayoutURL());
060                    serviceContext.setModifiedDate(getModifiedDate());
061                    serviceContext.setPathMain(getPathMain());
062                    serviceContext.setPlid(getPlid());
063                    serviceContext.setPortalURL(getPortalURL());
064                    serviceContext.setPortletPreferencesIds(getPortletPreferencesIds());
065                    serviceContext.setRemoteAddr(getRemoteAddr());
066                    serviceContext.setRemoteHost(getRemoteHost());
067                    serviceContext.setScopeGroupId(getScopeGroupId());
068                    serviceContext.setSignedIn(isSignedIn());
069                    serviceContext.setUserDisplayURL(getUserDisplayURL());
070                    serviceContext.setUserId(getUserId());
071                    serviceContext.setUuid(getUuid());
072                    serviceContext.setWorkflowAction(getWorkflowAction());
073    
074                    return serviceContext;
075            }
076    
077            public boolean getAddCommunityPermissions() {
078                    return _addCommunityPermissions;
079            }
080    
081            public boolean getAddGuestPermissions() {
082                    return _addGuestPermissions;
083            }
084    
085            public long[] getAssetCategoryIds() {
086                    return _assetCategoryIds;
087            }
088    
089            public String[] getAssetTagNames() {
090                    return _assetTagNames;
091            }
092    
093            public Serializable getAttribute(String name) {
094                    return _attributes.get(name);
095            }
096    
097            public Map<String, Serializable> getAttributes() {
098                    return _attributes;
099            }
100    
101            public String getCommand() {
102                    return _command;
103            }
104    
105            public String[] getCommunityPermissions() {
106                    return _communityPermissions;
107            }
108    
109            public long getCompanyId() {
110                    return _companyId;
111            }
112    
113            public Date getCreateDate() {
114                    return _createDate;
115            }
116    
117            public Date getCreateDate(Date defaultCreateDate) {
118                    if (_createDate != null) {
119                            return _createDate;
120                    }
121                    else if (defaultCreateDate != null) {
122                            return defaultCreateDate;
123                    }
124                    else {
125                            return new Date();
126                    }
127            }
128    
129            public String getCurrentURL() {
130                    return _currentURL;
131            }
132    
133            public Map<String, Serializable> getExpandoBridgeAttributes() {
134                    return _expandoBridgeAttributes;
135            }
136    
137            public String[] getGuestPermissions() {
138                    return _guestPermissions;
139            }
140    
141            public Map<String, String> getHeaders() {
142                    return _headers;
143            }
144    
145            public String getLanguageId() {
146                    return _languageId;
147            }
148    
149            public String getLayoutFullURL() {
150                    return _layoutFullURL;
151            }
152    
153            public String getLayoutURL() {
154                    return _layoutURL;
155            }
156    
157            public Date getModifiedDate() {
158                    return _modifiedDate;
159            }
160    
161            public Date getModifiedDate(Date defaultModifiedDate) {
162                    if (_modifiedDate != null) {
163                            return _modifiedDate;
164                    }
165                    else if (defaultModifiedDate != null) {
166                            return defaultModifiedDate;
167                    }
168                    else {
169                            return new Date();
170                    }
171            }
172    
173            public String getPathMain() {
174                    return _pathMain;
175            }
176    
177            public long getPlid() {
178                    return _plid;
179            }
180    
181            public String getPortalURL() {
182                    return _portalURL;
183            }
184    
185            public PortletPreferencesIds getPortletPreferencesIds() {
186                    return _portletPreferencesIds;
187            }
188    
189            public String getRemoteAddr() {
190                    return _remoteAddr;
191            }
192    
193            public String getRemoteHost() {
194                    return _remoteHost;
195            }
196    
197            public long getScopeGroupId() {
198                    return _scopeGroupId;
199            }
200    
201            public String getUserDisplayURL() {
202                    return _userDisplayURL;
203            }
204    
205            public long getUserId() {
206                    return _userId;
207            }
208    
209            public String getUuid() {
210                    String uuid = _uuid;
211    
212                    _uuid = null;
213    
214                    return uuid;
215            }
216    
217            public int getWorkflowAction() {
218                    return _workflowAction;
219            }
220    
221            public boolean isCommandAdd() {
222                    if (Validator.equals(_command, Constants.ADD)) {
223                            return true;
224                    }
225                    else {
226                            return false;
227                    }
228            }
229    
230            public boolean isCommandUpdate() {
231                    if (Validator.equals(_command, Constants.UPDATE)) {
232                            return true;
233                    }
234                    else {
235                            return false;
236                    }
237            }
238    
239            public boolean isSignedIn() {
240                    return _signedIn;
241            }
242    
243            public Serializable removeAttribute(String name) {
244                    return _attributes.remove(name);
245            }
246    
247            public void setAddCommunityPermissions(boolean addCommunityPermissions) {
248                    _addCommunityPermissions = addCommunityPermissions;
249            }
250    
251            public void setAddGuestPermissions(boolean addGuestPermissions) {
252                    _addGuestPermissions = addGuestPermissions;
253            }
254    
255            public void setAssetCategoryIds(long[] assetCategoryIds) {
256                    _assetCategoryIds = assetCategoryIds;
257            }
258    
259            public void setAssetTagNames(String[] assetTagNames) {
260                    _assetTagNames = assetTagNames;
261            }
262    
263            public void setAttribute(String name, Serializable value) {
264                    _attributes.put(name, value);
265            }
266    
267            public void setAttributes(Map<String, Serializable> attributes) {
268                    _attributes = attributes;
269            }
270    
271            public void setCommand(String command) {
272                    _command = command;
273            }
274    
275            public void setCommunityPermissions(String[] communityPermissions) {
276                    _communityPermissions = communityPermissions;
277            }
278    
279            public void setCompanyId(long companyId) {
280                    _companyId = companyId;
281            }
282    
283            public void setCreateDate(Date createDate) {
284                    _createDate = createDate;
285            }
286    
287            public void setCurrentURL(String currentURL) {
288                    _currentURL = currentURL;
289            }
290    
291            public void setExpandoBridgeAttributes(
292                    Map<String, Serializable> expandoBridgeAttributes) {
293    
294                    _expandoBridgeAttributes = expandoBridgeAttributes;
295            }
296    
297            public void setGuestPermissions(String[] guestPermissions) {
298                    _guestPermissions = guestPermissions;
299            }
300    
301            public void setHeaders(Map<String, String> headers) {
302                    _headers = headers;
303            }
304    
305            public void setLanguageId(String languageId) {
306                    _languageId = languageId;
307            }
308    
309            public void setLayoutFullURL(String layoutFullURL) {
310                    _layoutFullURL = layoutFullURL;
311            }
312    
313            public void setLayoutURL(String layoutURL) {
314                    _layoutURL = layoutURL;
315            }
316    
317            public void setModifiedDate(Date modifiedDate) {
318                    _modifiedDate = modifiedDate;
319            }
320    
321            public void setPathMain(String pathMain) {
322                    _pathMain = pathMain;
323            }
324    
325            public void setPlid(long plid) {
326                    _plid = plid;
327            }
328    
329            public void setPortalURL(String portalURL) {
330                    _portalURL = portalURL;
331            }
332    
333            public void setPortletPreferencesIds(
334                    PortletPreferencesIds portletPreferencesIds) {
335    
336                    _portletPreferencesIds = portletPreferencesIds;
337            }
338    
339            public void setRemoteAddr(String remoteAddr) {
340                    _remoteAddr = remoteAddr;
341            }
342    
343            public void setRemoteHost(String remoteHost) {
344                    _remoteHost = remoteHost;
345            }
346    
347            public void setScopeGroupId(long scopeGroupId) {
348                    _scopeGroupId = scopeGroupId;
349            }
350    
351            public void setSignedIn(boolean signedIn) {
352                    _signedIn = signedIn;
353            }
354    
355            public void setUserDisplayURL(String userDisplayURL) {
356                    _userDisplayURL = userDisplayURL;
357            }
358    
359            public void setUserId(long userId) {
360                    _userId = userId;
361            }
362    
363            public void setUuid(String uuid) {
364                    _uuid = uuid;
365            }
366    
367            public void setWorkflowAction(int workflowAction) {
368                    _workflowAction = workflowAction;
369            }
370    
371            private boolean _addCommunityPermissions;
372            private boolean _addGuestPermissions;
373            private long[] _assetCategoryIds;
374            private String[] _assetTagNames;
375            private Map<String, Serializable> _attributes;
376            private String _command;
377            private String[] _communityPermissions;
378            private long _companyId;
379            private Date _createDate;
380            private String _currentURL;
381            private Map<String, Serializable> _expandoBridgeAttributes;
382            private String[] _guestPermissions;
383            private Map<String, String> _headers;
384            private String _languageId;
385            private String _layoutFullURL;
386            private String _layoutURL;
387            private Date _modifiedDate;
388            private String _pathMain;
389            private String _portalURL;
390            private PortletPreferencesIds _portletPreferencesIds;
391            private String _remoteAddr;
392            private String _remoteHost;
393            private long _scopeGroupId;
394            private boolean _signedIn;
395            private String _userDisplayURL;
396            private long _plid;
397            private int _workflowAction = WorkflowConstants.ACTION_PUBLISH;
398            private long _userId;
399            private String _uuid;
400    
401    }