001    /**
002     * Copyright (c) 2000-2011 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.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            public Object clone() {
041                    ServiceContext serviceContext = new ServiceContext();
042    
043                    serviceContext.setAddCommunityPermissions(getAddCommunityPermissions());
044                    serviceContext.setAddGuestPermissions(getAddGuestPermissions());
045                    serviceContext.setAssetCategoryIds(getAssetCategoryIds());
046                    serviceContext.setAssetTagNames(getAssetTagNames());
047                    serviceContext.setAttributes(getAttributes());
048                    serviceContext.setCommand(getCommand());
049                    serviceContext.setCommunityPermissions(getCommunityPermissions());
050                    serviceContext.setCompanyId(getCompanyId());
051                    serviceContext.setCreateDate(getCreateDate());
052                    serviceContext.setExpandoBridgeAttributes(getExpandoBridgeAttributes());
053                    serviceContext.setGuestPermissions(getGuestPermissions());
054                    serviceContext.setLanguageId(getLanguageId());
055                    serviceContext.setLayoutFullURL(getLayoutFullURL());
056                    serviceContext.setLayoutURL(getLayoutURL());
057                    serviceContext.setModifiedDate(getModifiedDate());
058                    serviceContext.setPathMain(getPathMain());
059                    serviceContext.setPlid(getPlid());
060                    serviceContext.setPortalURL(getPortalURL());
061                    serviceContext.setPortletPreferencesIds(getPortletPreferencesIds());
062                    serviceContext.setScopeGroupId(getScopeGroupId());
063                    serviceContext.setUserDisplayURL(getUserDisplayURL());
064                    serviceContext.setUserId(getUserId());
065                    serviceContext.setUuid(getUuid());
066                    serviceContext.setWorkflowAction(getWorkflowAction());
067    
068                    return serviceContext;
069            }
070    
071            public boolean getAddCommunityPermissions() {
072                    return _addCommunityPermissions;
073            }
074    
075            public boolean getAddGuestPermissions() {
076                    return _addGuestPermissions;
077            }
078    
079            public long[] getAssetCategoryIds() {
080                    return _assetCategoryIds;
081            }
082    
083            public String[] getAssetTagNames() {
084                    return _assetTagNames;
085            }
086    
087            public Serializable getAttribute(String name) {
088                    return _attributes.get(name);
089            }
090    
091            public Map<String, Serializable> getAttributes() {
092                    return _attributes;
093            }
094    
095            public String getCommand() {
096                    return _command;
097            }
098    
099            public String[] getCommunityPermissions() {
100                    return _communityPermissions;
101            }
102    
103            public long getCompanyId() {
104                    return _companyId;
105            }
106    
107            public Date getCreateDate() {
108                    return _createDate;
109            }
110    
111            public Date getCreateDate(Date defaultCreateDate) {
112                    if (_createDate != null) {
113                            return _createDate;
114                    }
115                    else if (defaultCreateDate != null) {
116                            return defaultCreateDate;
117                    }
118                    else {
119                            return new Date();
120                    }
121            }
122    
123            public Map<String, Serializable> getExpandoBridgeAttributes() {
124                    return _expandoBridgeAttributes;
125            }
126    
127            public String[] getGuestPermissions() {
128                    return _guestPermissions;
129            }
130    
131            public String getLanguageId() {
132                    return _languageId;
133            }
134    
135            public String getLayoutFullURL() {
136                    return _layoutFullURL;
137            }
138    
139            public String getLayoutURL() {
140                    return _layoutURL;
141            }
142    
143            public Date getModifiedDate() {
144                    return _modifiedDate;
145            }
146    
147            public Date getModifiedDate(Date defaultModifiedDate) {
148                    if (_modifiedDate != null) {
149                            return _modifiedDate;
150                    }
151                    else if (defaultModifiedDate != null) {
152                            return defaultModifiedDate;
153                    }
154                    else {
155                            return new Date();
156                    }
157            }
158    
159            public String getPathMain() {
160                    return _pathMain;
161            }
162    
163            public long getPlid() {
164                    return _plid;
165            }
166    
167            public String getPortalURL() {
168                    return _portalURL;
169            }
170    
171            public PortletPreferencesIds getPortletPreferencesIds() {
172                    return _portletPreferencesIds;
173            }
174    
175            public long getScopeGroupId() {
176                    return _scopeGroupId;
177            }
178    
179            public String getUserDisplayURL() {
180                    return _userDisplayURL;
181            }
182    
183            public long getUserId() {
184                    return _userId;
185            }
186    
187            public String getUuid() {
188                    String uuid = _uuid;
189    
190                    _uuid = null;
191    
192                    return uuid;
193            }
194    
195            public int getWorkflowAction() {
196                    return _workflowAction;
197            }
198    
199            public boolean isCommandAdd() {
200                    if (Validator.equals(_command, Constants.ADD)) {
201                            return true;
202                    }
203                    else {
204                            return false;
205                    }
206            }
207    
208            public boolean isCommandUpdate() {
209                    if (Validator.equals(_command, Constants.UPDATE)) {
210                            return true;
211                    }
212                    else {
213                            return false;
214                    }
215            }
216    
217            public void setAddCommunityPermissions(boolean addCommunityPermissions) {
218                    _addCommunityPermissions = addCommunityPermissions;
219            }
220    
221            public void setAddGuestPermissions(boolean addGuestPermissions) {
222                    _addGuestPermissions = addGuestPermissions;
223            }
224    
225            public void setAssetCategoryIds(long[] assetCategoryIds) {
226                    _assetCategoryIds = assetCategoryIds;
227            }
228    
229            public void setAssetTagNames(String[] assetTagNames) {
230                    _assetTagNames = assetTagNames;
231            }
232    
233            public void setAttribute(String name, Serializable value) {
234                    _attributes.put(name, value);
235            }
236    
237            public void setAttributes(Map<String, Serializable> attributes) {
238                    _attributes = attributes;
239            }
240    
241            public void setCommand(String command) {
242                    _command = command;
243            }
244    
245            public void setCommunityPermissions(String[] communityPermissions) {
246                    _communityPermissions = communityPermissions;
247            }
248    
249            public void setCompanyId(long companyId) {
250                    _companyId = companyId;
251            }
252    
253            public void setCreateDate(Date createDate) {
254                    _createDate = createDate;
255            }
256    
257            public void setExpandoBridgeAttributes(
258                    Map<String, Serializable> expandoBridgeAttributes) {
259    
260                    _expandoBridgeAttributes = expandoBridgeAttributes;
261            }
262    
263            public void setGuestPermissions(String[] guestPermissions) {
264                    _guestPermissions = guestPermissions;
265            }
266    
267            public void setLanguageId(String languageId) {
268                    _languageId = languageId;
269            }
270    
271            public void setLayoutFullURL(String layoutFullURL) {
272                    _layoutFullURL = layoutFullURL;
273            }
274    
275            public void setLayoutURL(String layoutURL) {
276                    _layoutURL = layoutURL;
277            }
278    
279            public void setModifiedDate(Date modifiedDate) {
280                    _modifiedDate = modifiedDate;
281            }
282    
283            public void setPathMain(String pathMain) {
284                    _pathMain = pathMain;
285            }
286    
287            public void setPlid(long plid) {
288                    _plid = plid;
289            }
290    
291            public void setPortalURL(String portalURL) {
292                    _portalURL = portalURL;
293            }
294    
295            public void setPortletPreferencesIds(
296                    PortletPreferencesIds portletPreferencesIds) {
297    
298                    _portletPreferencesIds = portletPreferencesIds;
299            }
300    
301            public void setScopeGroupId(long scopeGroupId) {
302                    _scopeGroupId = scopeGroupId;
303            }
304    
305            public void setUserDisplayURL(String userDisplayURL) {
306                    _userDisplayURL = userDisplayURL;
307            }
308    
309            public void setUserId(long userId) {
310                    _userId = userId;
311            }
312    
313            public void setUuid(String uuid) {
314                    _uuid = uuid;
315            }
316    
317            public void setWorkflowAction(int workflowAction) {
318                    _workflowAction = workflowAction;
319            }
320    
321            private boolean _addCommunityPermissions;
322            private boolean _addGuestPermissions;
323            private long[] _assetCategoryIds;
324            private String[] _assetTagNames;
325            private Map<String, Serializable> _attributes;
326            private String _command;
327            private String[] _communityPermissions;
328            private long _companyId;
329            private Date _createDate;
330            private Map<String, Serializable> _expandoBridgeAttributes;
331            private String[] _guestPermissions;
332            private String _languageId;
333            private String _layoutFullURL;
334            private String _layoutURL;
335            private Date _modifiedDate;
336            private String _pathMain;
337            private String _portalURL;
338            private PortletPreferencesIds _portletPreferencesIds;
339            private long _scopeGroupId;
340            private String _userDisplayURL;
341            private long _plid;
342            private int _workflowAction = WorkflowConstants.ACTION_PUBLISH;
343            private long _userId;
344            private String _uuid;
345    
346    }