KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > portal > core > plugins > page > PageRepository


1 /*****************************************
2  * *
3  * JBoss Portal: The OpenSource Portal *
4  * *
5  * Distributable under LGPL license. *
6  * See terms of license at gnu.org. *
7  * *
8  *****************************************/

9 package org.jboss.portal.core.plugins.page;
10
11 import java.util.Collection JavaDoc;
12 import java.util.Collections JavaDoc;
13 import java.util.HashMap JavaDoc;
14 import java.util.Iterator JavaDoc;
15 import java.util.Map JavaDoc;
16
17 import org.apache.log4j.Logger;
18 import org.jboss.portal.common.metadata.MetaData;
19 import org.jboss.portal.core.metadata.PageSetMetaData;
20 import org.jboss.portal.server.ServerObjectID;
21 import org.jboss.portal.server.Portal;
22 import org.jboss.portal.server.kernel.ServiceImplementation;
23 import org.jboss.portal.server.kernel.Service;
24 import org.jboss.portal.server.plugins.PluginService;
25
26 /**
27  * @author <a HREF="mailto:julien@jboss.org">Julien Viet</a>
28  * @version $Revision: 1.5 $
29  */

30 public class PageRepository
31    extends PluginService
32 {
33
34    private static final Logger log = Logger.getLogger(PageRepository.class);
35
36    private String JavaDoc defaultPageName;
37
38    private Map JavaDoc pages;
39    private Page defaultPage;
40    private Map JavaDoc windowIDToPage;
41    private Portal portal;
42
43    private PageSetMetaData metaData;
44
45    public PageRepository()
46    {
47       pages = Collections.synchronizedMap(new HashMap JavaDoc());
48       windowIDToPage = Collections.synchronizedMap(new HashMap JavaDoc());
49    }
50
51    public Portal getPortal()
52    {
53       return portal;
54    }
55
56    public Page getPageByWindow(ServerObjectID id)
57    {
58       return (Page)windowIDToPage.get(id);
59    }
60
61    public Page getPageByName(String JavaDoc name)
62    {
63       return (Page)pages.get(name);
64    }
65
66    public Page getDefaultPage()
67    {
68       return defaultPage;
69    }
70
71    public void start() throws Exception JavaDoc
72    {
73       this.defaultPageName = metaData.getDefaultPageName();
74    }
75
76    public void stop()
77    {
78       this.defaultPageName = null;
79    }
80
81    public void setMetaData(MetaData metaData)
82    {
83       this.metaData = (PageSetMetaData)metaData;
84    }
85
86    public MetaData getMetaData()
87    {
88       return metaData;
89    }
90
91    public void addPage(Page page)
92    {
93       // Add to the page index
94
String JavaDoc name = page.getName();
95       pages.put(name, page);
96
97       // Add to the window id index
98
for (Iterator JavaDoc i = page.getLocations().iterator();i.hasNext();)
99       {
100          WindowLocation location = (WindowLocation)i.next();
101          ServerObjectID windowID = location.getID();
102          windowIDToPage.put(windowID, page);
103       }
104
105       // Set the default page if necessary
106
if (name.equals(defaultPageName))
107       {
108          defaultPage = page;
109       }
110       log.debug("Added page " + name);
111    }
112
113    public void removePage(Page page)
114    {
115       // Remove from the page index
116
String JavaDoc name = page.getName();
117       pages.remove(name);
118
119       // Remove from the window id index
120
for (Iterator JavaDoc i = page.getLocations().iterator();i.hasNext();)
121       {
122          WindowLocation windowLocation = (WindowLocation)i.next();
123          windowIDToPage.remove(windowLocation.getID());
124       }
125
126       // Remove if it is the default page
127
if (name.equals(defaultPageName))
128       {
129          defaultPage = null;
130       }
131       log.debug("Removed page " + name);
132    }
133    
134    public Collection JavaDoc getPages()
135    {
136       return pages.values();
137    }
138
139    public void addIDependOn(ServiceImplementation implementation)
140    {
141       Service service = implementation.getService();
142       if (service instanceof Portal)
143       {
144          portal = (Portal)service;
145       }
146    }
147
148    public void removeIDependOn(ServiceImplementation implementation)
149    {
150       Service service = implementation.getService();
151       if (service instanceof Portal)
152       {
153          portal = null;
154       }
155    }
156 }
157
Popular Tags