1 9 package org.jboss.portal.core.plugins.page; 10 11 import java.util.Collection ; 12 import java.util.Collections ; 13 import java.util.HashMap ; 14 import java.util.Iterator ; 15 import java.util.Map ; 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 30 public class PageRepository 31 extends PluginService 32 { 33 34 private static final Logger log = Logger.getLogger(PageRepository.class); 35 36 private String defaultPageName; 37 38 private Map pages; 39 private Page defaultPage; 40 private Map windowIDToPage; 41 private Portal portal; 42 43 private PageSetMetaData metaData; 44 45 public PageRepository() 46 { 47 pages = Collections.synchronizedMap(new HashMap ()); 48 windowIDToPage = Collections.synchronizedMap(new HashMap ()); 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 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 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 String name = page.getName(); 95 pages.put(name, page); 96 97 for (Iterator 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 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 String name = page.getName(); 117 pages.remove(name); 118 119 for (Iterator i = page.getLocations().iterator();i.hasNext();) 121 { 122 WindowLocation windowLocation = (WindowLocation)i.next(); 123 windowIDToPage.remove(windowLocation.getID()); 124 } 125 126 if (name.equals(defaultPageName)) 128 { 129 defaultPage = null; 130 } 131 log.debug("Removed page " + name); 132 } 133 134 public Collection 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 |