KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > services > portletcontainer > impl > portletAPIImp > persistenceImp > DefaultPersistenceManager


1 /***************************************************************************
2  * Copyright 2001-2003 The eXo Platform SARL All rights reserved. *
3  * Please look at license.txt in info directory for more license detail. *
4  **************************************************************************/

5 package org.exoplatform.services.portletcontainer.impl.portletAPIImp.persistenceImp;
6
7 import javax.portlet.PortletPreferences;
8 import javax.portlet.PreferencesValidator;
9
10 import org.apache.commons.logging.Log;
11 import org.exoplatform.commons.utils.IOUtil;
12 import org.exoplatform.container.PortalContainer;
13 import org.exoplatform.services.log.LogService;
14 import org.exoplatform.services.portletcontainer.helper.PortletWindowInternal;
15 import org.exoplatform.services.portletcontainer.impl.PortletApplicationProxy;
16 import org.exoplatform.services.portletcontainer.impl.portletAPIImp.PortletPreferencesImp;
17 import org.exoplatform.services.portletcontainer.pci.Input;
18 import org.exoplatform.services.portletcontainer.pci.WindowID;
19 import org.exoplatform.services.portletcontainer.pci.model.ExoPortletPreferences;
20 import org.exoplatform.services.portletcontainer.persistence.PortletPreferencesPersister;
21
22
23 /**
24  * Created by The eXo Platform SARL.
25  * Author : Tuan Nguyen
26  * tuan08@users.sourceforge.net
27  * Date: Jun 14, 2003
28  * Time: 1:12:22 PM
29  */

30 public class DefaultPersistenceManager implements PersistenceManager {
31
32   private Log log_;
33
34   public DefaultPersistenceManager(LogService lservice) throws Exception JavaDoc {
35     log_ = lservice.getLog("org.exoplatform.services.portletcontainer");
36   }
37
38   public PortletWindowInternal getWindow(Input input, ExoPortletPreferences defaultPrefs) {
39     WindowID windowID = input.getWindowID();
40     PortalContainer manager = PortalContainer.getInstance();
41     PortletApplicationProxy proxy =
42         (PortletApplicationProxy) manager.getComponentInstance(windowID.getPortletApplicationName());
43     String JavaDoc validatorClassName = null;
44     PreferencesValidator validator = null;
45     if (defaultPrefs != null) {
46       validatorClassName = defaultPrefs.getPreferencesValidator();
47       if (validatorClassName != null) {
48         validator = validator = proxy.getValidator(validatorClassName);
49       }
50     }
51     PortletPreferencesPersister currentPersister = null;
52     if (input.getPortletPreferencesPersister() != null) {
53       currentPersister = input.getPortletPreferencesPersister();
54     } else {
55       PortalContainer container = PortalContainer.getInstance() ;
56       currentPersister =
57         (PortletPreferencesPersister) container.getComponentInstanceOfType(PortletPreferencesPersister.class);
58     }
59     PortletPreferencesImp prefsImp = null;
60     if (!input.isStateSaveOnClient()) {
61       try {
62         ExoPortletPreferences preferences =
63             currentPersister.getPortletPreferences(windowID);
64         if (preferences != null) {
65           prefsImp = new PortletPreferencesImp(validator, defaultPrefs, windowID, currentPersister);
66           prefsImp.setCurrentPreferences(preferences);
67           return new PortletWindowInternal(windowID, prefsImp);
68         }
69       } catch (Exception JavaDoc ex) {
70         log_.error("Error: ", ex);
71       }
72     } else {
73       byte[] portletState = input.getPortletState();
74       if (portletState != null) {
75         try {
76           return new PortletWindowInternal(windowID, (PortletPreferences) IOUtil.deserialize(portletState));
77         } catch (Exception JavaDoc e) {
78              log_.error("Error: ", e);
79         }
80       }
81     }
82     prefsImp = new PortletPreferencesImp(validator, defaultPrefs, windowID, currentPersister);
83     return new PortletWindowInternal(windowID, prefsImp);
84   }
85 }
Popular Tags