1   /**
2    * Copyright (c) 2000-2009 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.lar;
24  
25  import javax.portlet.PortletPreferences;
26  
27  /**
28   * <a href="InvokerPortletDataHandler.java.html"><b><i>View Source</i></b></a>
29   *
30   * @author Bruno Farache
31   *
32   */
33  public class InvokerPortletDataHandler implements PortletDataHandler {
34  
35      public InvokerPortletDataHandler(
36          PortletDataHandler portletDataHandler, ClassLoader classLoader) {
37  
38          _portletDataHandler = portletDataHandler;
39          _classLoader = classLoader;
40      }
41  
42      public PortletPreferences deleteData(
43              PortletDataContext context, String portletId,
44              PortletPreferences preferences)
45          throws PortletDataException {
46  
47          Thread currentThread = Thread.currentThread();
48  
49          ClassLoader contextClassLoader = currentThread.getContextClassLoader();
50  
51          try {
52              currentThread.setContextClassLoader(_classLoader);
53  
54              return _portletDataHandler.deleteData(
55                  context, portletId, preferences);
56          }
57          finally {
58              currentThread.setContextClassLoader(contextClassLoader);
59          }
60      }
61  
62      public String exportData(
63              PortletDataContext context, String portletId,
64              PortletPreferences preferences)
65          throws PortletDataException {
66  
67          Thread currentThread = Thread.currentThread();
68  
69          ClassLoader contextClassLoader = currentThread.getContextClassLoader();
70  
71          try {
72              currentThread.setContextClassLoader(_classLoader);
73  
74              return _portletDataHandler.exportData(
75                  context, portletId, preferences);
76          }
77          finally {
78              currentThread.setContextClassLoader(contextClassLoader);
79          }
80      }
81  
82      public PortletDataHandlerControl[] getExportControls()
83          throws PortletDataException {
84  
85          Thread currentThread = Thread.currentThread();
86  
87          ClassLoader contextClassLoader = currentThread.getContextClassLoader();
88  
89          try {
90              currentThread.setContextClassLoader(_classLoader);
91  
92              return _portletDataHandler.getExportControls();
93          }
94          finally {
95              currentThread.setContextClassLoader(contextClassLoader);
96          }
97      }
98  
99      public PortletDataHandlerControl[] getImportControls()
100         throws PortletDataException {
101 
102         Thread currentThread = Thread.currentThread();
103 
104         ClassLoader contextClassLoader = currentThread.getContextClassLoader();
105 
106         try {
107             currentThread.setContextClassLoader(_classLoader);
108 
109             return _portletDataHandler.getImportControls();
110         }
111         finally {
112             currentThread.setContextClassLoader(contextClassLoader);
113         }
114     }
115 
116     public PortletPreferences importData(
117             PortletDataContext context, String portletId,
118             PortletPreferences preferences, String data)
119         throws PortletDataException {
120 
121         Thread currentThread = Thread.currentThread();
122 
123         ClassLoader contextClassLoader = currentThread.getContextClassLoader();
124 
125         try {
126             currentThread.setContextClassLoader(_classLoader);
127 
128             return _portletDataHandler.importData(
129                 context, portletId, preferences, data);
130         }
131         finally {
132             currentThread.setContextClassLoader(contextClassLoader);
133         }
134     }
135 
136     public boolean isPublishToLiveByDefault() {
137         Thread currentThread = Thread.currentThread();
138 
139         ClassLoader contextClassLoader = currentThread.getContextClassLoader();
140 
141         try {
142             currentThread.setContextClassLoader(_classLoader);
143 
144             return _portletDataHandler.isPublishToLiveByDefault();
145         }
146         finally {
147             currentThread.setContextClassLoader(contextClassLoader);
148         }
149     }
150 
151     private PortletDataHandler _portletDataHandler;
152     private ClassLoader _classLoader;
153 
154 }