KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > infoglue > deliver > portal > services > PortletWindowRegistryServiceImpl


1 /* ===============================================================================
2  *
3  * Part of the InfoGlue Content Management Platform (www.infoglue.org)
4  *
5  * ===============================================================================
6  *
7  * Copyright (C)
8  *
9  * This program is free software; you can redistribute it and/or modify it under
10  * the terms of the GNU General Public License version 2, as published by the
11  * Free Software Foundation. See the file LICENSE.html for more information.
12  *
13  * This program is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY, including the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along with
18  * this program; if not, write to the Free Software Foundation, Inc. / 59 Temple
19  * Place, Suite 330 / Boston, MA 02111-1307 / USA.
20  *
21  * ===============================================================================
22  */

23 package org.infoglue.deliver.portal.services;
24
25 import java.util.Collections JavaDoc;
26 import java.util.Hashtable JavaDoc;
27 import java.util.Iterator JavaDoc;
28 import java.util.Map JavaDoc;
29
30 import javax.naming.NameNotFoundException JavaDoc;
31
32 import org.apache.commons.logging.Log;
33 import org.apache.commons.logging.LogFactory;
34 import org.apache.pluto.om.entity.PortletApplicationEntity;
35 import org.apache.pluto.om.entity.PortletApplicationEntityList;
36 import org.apache.pluto.om.entity.PortletEntity;
37 import org.apache.pluto.om.window.PortletWindow;
38 import org.apache.pluto.om.window.PortletWindowListCtrl;
39 import org.apache.pluto.portalImpl.services.Service;
40 import org.apache.pluto.portalImpl.services.portletentityregistry.PortletEntityRegistry;
41 import org.apache.pluto.portalImpl.util.ObjectID;
42 import org.infoglue.deliver.portal.om.PortletWindowImpl;
43
44 /**
45  * This is the registry service for PortletWindow:s.
46  *
47  * @author jand
48  *
49  */

50 public class PortletWindowRegistryServiceImpl extends Service implements PortletWindowRegistryService
51 {
52     private static final Log log = LogFactory.getLog(PortletWindowRegistryServiceImpl.class);
53
54     /** Window-id to window */
55     private static Map JavaDoc wid2win = Collections.synchronizedMap(new Hashtable JavaDoc());
56
57     public synchronized PortletWindow createPortletWindow(String JavaDoc windowID, String JavaDoc entityID) throws NameNotFoundException JavaDoc
58     {
59         PortletWindow window = (PortletWindow) wid2win.get(windowID);
60
61         if (window == null)
62         {
63             log.debug("Found no portletwindow with id[" + windowID + "], registring new instance");
64
65             PortletApplicationEntityList applicationList = PortletEntityRegistry.getPortletApplicationEntityList();
66             Iterator JavaDoc portletApplicationEntityListIterator = applicationList.iterator();
67             while(portletApplicationEntityListIterator.hasNext())
68             {
69                 PortletApplicationEntity pae = (PortletApplicationEntity)portletApplicationEntityListIterator.next();
70                 log.debug("Available application: " + pae.getId());
71             }
72             
73             PortletEntity entity = PortletEntityRegistry.getPortletEntity(ObjectID.createFromString(entityID));
74
75             if (entity == null)
76             {
77                 log.fatal("Couldn't find entity with id: " + entityID);
78                 throw new NameNotFoundException JavaDoc("Portlet entity not found: " + entityID);
79             }
80             
81             window = new PortletWindowImpl(windowID, entity);
82
83             ((PortletWindowListCtrl) entity.getPortletWindowList()).add(window);
84
85             wid2win.put(windowID, window);
86         }
87
88         return window;
89     }
90
91     /**
92      * Get a portlet-window by id.
93      *
94      * @param id
95      * Id of window
96      * @return portlet-window with attached portlet-entity, or null
97      */

98     public PortletWindow getPortletWindow(String JavaDoc id) {
99         return (PortletWindow) wid2win.get(id);
100     }
101
102 }
Popular Tags