1 9 package org.jboss.portal.server; 10 11 import java.beans.PropertyEditorManager ; 12 import java.util.Collection ; 13 import java.util.Collections ; 14 import java.util.HashMap ; 15 import java.util.Map ; 16 17 import javax.servlet.ServletContext ; 18 19 import org.jboss.portal.server.invocation.Interceptor; 20 import org.jboss.portal.server.invocation.Invocation; 21 import org.jboss.portal.server.kernel.Kernel; 22 import org.jboss.portal.server.kernel.KernelException; 23 import org.jboss.portal.server.kernel.Service; 24 import org.jboss.portal.server.kernel.ServiceImplementation; 25 import org.jboss.portal.server.kernel.state.State; 26 import org.jboss.portal.server.metadata.PortalServerMetaData; 27 import org.jboss.portal.server.metadata.ServerObjectMetaData; 28 import org.jboss.portal.server.plugins.invocation.InvocationPlugin; 29 import org.jboss.portal.server.util.ServerObjectIDEditor; 30 31 37 public class PortalServer extends ServerObject 38 { 39 40 private Map portals; 41 private Map applications; 42 private ServerManager manager; 43 private PortalServerMetaData metaData; 44 45 public PortalServer(PortalServerMetaData metaData) 46 { 47 super(metaData.getName()); 48 this.metaData = metaData; 49 50 this.portals = Collections.synchronizedMap(new HashMap ()); 51 this.applications = Collections.synchronizedMap(new HashMap ()); 52 } 53 54 public void create(ServerObjectID id) 55 { 56 try 57 { 58 manager.getKernel().create(id); 59 } 60 catch (KernelException e) 61 { 62 e.printStackTrace(); 63 } 64 } 65 66 public void start(ServerObjectID id) 67 { 68 try 69 { 70 manager.getKernel().start(id); 71 } 72 catch (KernelException e) 73 { 74 e.printStackTrace(); 75 } 76 } 77 78 public void stop(ServerObjectID id) 79 { 80 try 81 { 82 manager.getKernel().stop(id); 83 } 84 catch (KernelException e) 85 { 86 e.printStackTrace(); 87 } 88 } 89 90 public void destroy(ServerObjectID id) 91 { 92 try 93 { 94 manager.getKernel().destroy(id); 95 } 96 catch (KernelException e) 97 { 98 e.printStackTrace(); 99 } 100 } 101 102 105 public ServerObject getObject(ServerObjectID id) 106 { 107 return (ServerObject)manager.getKernel().getService(id); 108 } 109 110 public ServerManager getManager() 111 { 112 return manager; 113 } 114 115 public void setManager(ServerManager manager) 116 { 117 this.manager = manager; 118 } 119 120 public PortalServer getServer() 121 { 122 return this; 123 } 124 125 public ServerObjectMetaData getMetaData() 126 { 127 return metaData; 128 } 129 130 public Collection getPortals() 131 { 132 return portals.values(); 133 } 134 135 public Portal getPortal(String name) 136 { 137 return (Portal)portals.get(name); 138 } 139 140 public Portal getDefaultPortal() 141 { 142 return getPortal(PortalConstants.DEFAULT_PORTAL_NAME); 143 } 144 145 public Application getApplication(String name) 146 { 147 return (Application)applications.get(name); 148 } 149 150 public Collection getApplications() 151 { 152 return applications.values(); 153 } 154 155 public void create() throws Exception 156 { 157 PropertyEditorManager.registerEditor(ServerObjectID.class, ServerObjectIDEditor.class); 158 } 159 160 public void destroy() 161 { 162 PropertyEditorManager.registerEditor(ServerObjectID.class, null); 163 } 164 165 public boolean isStarted(ServerObject object) 166 { 167 if (object != null) 168 { 169 Kernel kernel = manager.getKernel(); 170 State state = kernel.getState(object.getID()); 171 return state == State.STARTED; 172 } 173 else 174 { 175 return false; 176 } 177 } 178 179 182 public Object invoke(Invocation invocation) 183 { 184 InvocationPlugin ip = (InvocationPlugin)getPlugin(PortalConstants.PLUGIN_INVOCATION); 185 Interceptor[] stack = ip.getStack(); 186 return invocation.invokeNext(stack); 187 } 188 189 public void addDependsOnMe(ServiceImplementation implementation) 190 { 191 Service service = implementation.getService(); 192 if (service instanceof Portal) 193 { 194 Portal portal = (Portal)service; 196 String name = portal.getName(); 197 198 portals.put(portal.getName(), portal); 200 log.info("Added portal " + name); 201 } 202 else if (service instanceof Application) 203 { 204 Application application = (Application)service; 206 String name = application.getName(); 207 208 applications.put(name, application); 210 log.info("Added application " + name); 211 } 212 else 213 { 214 super.addDependsOnMe(implementation); 215 } 216 } 217 218 public void removeDependsOnMe(ServiceImplementation implementation) 219 { 220 Service service = implementation.getService(); 221 if (service instanceof Portal) 222 { 223 Portal portal = (Portal)service; 225 String name = portal.getName(); 226 227 portals.remove(name); 229 log.info("Removed portal " + name); 230 } 231 else if (service instanceof Application) 232 { 233 Application application = (Application)service; 235 String name = application.getName(); 236 237 applications.remove(name); 239 log.info("Removed application " + name); 240 } 241 else 242 { 243 super.removeDependsOnMe(implementation); 244 } 245 } 246 } 247 | Popular Tags |