1 9 package org.jboss.portal.server; 10 11 import java.util.Collection ; 12 import java.util.Collections ; 13 import java.util.HashMap ; 14 import java.util.Map ; 15 16 import org.jboss.portal.server.kernel.Service; 17 import org.jboss.portal.server.kernel.ServiceImplementation; 18 import org.jboss.portal.server.metadata.InstanceMetaData; 19 import org.jboss.portal.server.metadata.ServerObjectMetaData; 20 import org.jboss.portal.server.user.ServerObjectContext; 21 22 28 public class Instance 29 extends ServerObject 30 { 31 32 protected Component component; 33 protected Map windows; 34 protected InstanceMetaData metaData; 35 36 public Instance(InstanceMetaData metaData) 37 { 38 super(metaData.getName()); 39 this.windows = Collections.synchronizedMap(new HashMap ()); 40 this.metaData = metaData; 41 } 42 43 public ServerObjectContext createContext() 44 { 45 return new InstanceContext(getID()); 46 } 47 48 public ServerObjectMetaData getMetaData() 49 { 50 return metaData; 51 } 52 53 public PortalServer getServer() 54 { 55 return component.getServer(); 56 } 57 58 61 public Component getComponent() 62 { 63 return component; 64 } 65 66 69 public Window getWindow(String name) 70 { 71 return (Window)windows.get(name); 72 } 73 74 77 public Collection getWindows() 78 { 79 return windows.values(); 80 } 81 82 public void addDependsOnMe(ServiceImplementation implementation) 83 { 84 Service service = implementation.getService(); 85 if (service instanceof Window) 86 { 87 Window window = (Window)service; 88 windows.put(window.getName(), window); 89 log.debug("Added window " + window.getName()); 90 } 91 else 92 { 93 super.addDependsOnMe(implementation); 94 } 95 } 96 97 public void removeDependsOnMe(ServiceImplementation implementation) 98 { 99 Service service = implementation.getService(); 100 if (service instanceof Window) 101 { 102 Window window = (Window)service; 103 windows.remove(window.getName()); 104 log.debug("Removed window " + window.getName()); 105 } 106 else 107 { 108 super.removeDependsOnMe(implementation); 109 } 110 } 111 112 public void addIDependOn(ServiceImplementation implementation) 113 { 114 Service service = implementation.getService(); 115 if (service instanceof Component) 116 { 117 component = (Component)service; 118 } 119 else 120 { 121 super.addIDependOn(implementation); 122 } 123 } 124 125 public void removeIDependOn(ServiceImplementation implementation) 126 { 127 Service service = implementation.getService(); 128 if (service instanceof Component) 129 { 130 component = null; 131 } 132 else 133 { 134 super.removeIDependOn(implementation); 135 } 136 } 137 } 138 | Popular Tags |