1   /**
2    * Copyright (c) 2000-2007 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portal.kernel.lar;
24  
25  import com.liferay.portal.kernel.util.StringMaker;
26  import com.liferay.portal.kernel.util.StringPool;
27  import com.liferay.portal.kernel.zip.ZipReader;
28  import com.liferay.portal.kernel.zip.ZipWriter;
29  
30  import java.io.Serializable;
31  
32  import java.util.Map;
33  import java.util.Set;
34  
35  /**
36   * <a href="PortletDataContext.java.html"><b><i>View Source</i></b></a>
37   *
38   * <p>
39   * Holds context information that is used during exporting adn importing portlet
40   * data.
41   * </p>
42   *
43   * @author Brian Wing Shun Chan
44   * @author Raymond Aug�
45   *
46   */
47  public class PortletDataContext implements Serializable {
48  
49      public PortletDataContext(long companyId, long groupId, Map parameterMap,
50                                Set primaryKeys, ZipReader zipReader) {
51  
52          _companyId = companyId;
53          _groupId = groupId;
54          _parameterMap = parameterMap;
55          _primaryKeys = primaryKeys;
56          _zipReader = zipReader;
57          _zipWriter = null;
58      }
59  
60      public PortletDataContext(long companyId, long groupId, Map parameterMap,
61                                Set primaryKeys, ZipWriter zipWriter) {
62  
63          _companyId = companyId;
64          _groupId = groupId;
65          _parameterMap = parameterMap;
66          _primaryKeys = primaryKeys;
67          _zipReader = null;
68          _zipWriter = zipWriter;
69      }
70  
71      public long getCompanyId() {
72          return _companyId;
73      }
74  
75      public long getGroupId() {
76          return _groupId;
77      }
78  
79      public long getPlid() {
80          return _plid;
81      }
82  
83      public void setPlid(long plid) {
84          _plid = plid;
85      }
86  
87      public Map getParameterMap() {
88          return _parameterMap;
89      }
90  
91      public Set getPrimaryKeys() {
92          return _primaryKeys;
93      }
94  
95      public boolean addPrimaryKey(Class classObj, Object primaryKey) {
96          boolean value = hasPrimaryKey(classObj, primaryKey);
97  
98          if (!value) {
99              _primaryKeys.add(getPrimaryKeyString(classObj, primaryKey));
100         }
101 
102         return value;
103     }
104 
105     public boolean hasPrimaryKey(Class classObj, Object primaryKey) {
106         return _primaryKeys.contains(getPrimaryKeyString(classObj, primaryKey));
107     }
108 
109     public ZipReader getZipReader() {
110         return _zipReader;
111     }
112 
113     public ZipWriter getZipWriter() {
114         return _zipWriter;
115     }
116 
117     protected String getPrimaryKeyString(Class classObj, Object primaryKey) {
118         StringMaker sm = new StringMaker();
119 
120         sm.append(classObj.getName());
121         sm.append(StringPool.POUND);
122         sm.append(primaryKey);
123 
124         return sm.toString();
125     }
126 
127     private long _companyId;
128     private long _groupId;
129     private long _plid;
130     private Map _parameterMap;
131     private Set _primaryKeys;
132     private ZipReader _zipReader;
133     private ZipWriter _zipWriter;
134 
135 }