1 16 19 20 package org.apache.pluto.portalImpl.om.servlet.impl; 21 22 import java.util.Collection ; 23 import java.util.HashMap ; 24 import java.util.Iterator ; 25 import java.util.Vector ; 26 27 import org.apache.pluto.om.servlet.ServletDefinition; 28 import org.apache.pluto.om.servlet.ServletDefinitionList; 29 import org.apache.pluto.om.servlet.ServletDefinitionListCtrl; 30 import org.apache.pluto.om.servlet.WebApplicationDefinition; 31 import org.apache.pluto.portalImpl.om.common.AbstractSupportSet; 32 import org.apache.pluto.portalImpl.om.common.Support; 33 import org.apache.pluto.portalImpl.xml.XmlException; 34 import org.apache.pluto.util.StringUtils; 35 36 public class ServletDefinitionListImpl extends AbstractSupportSet 37 implements ServletDefinitionList, ServletDefinitionListCtrl, java.io.Serializable , Support { 38 39 41 public ServletDefinition get(String name) 42 { 43 Iterator iterator = this.iterator(); 44 while (iterator.hasNext()) { 45 ServletDefinition servletDefinition = (ServletDefinition)iterator.next(); 46 if (servletDefinition.getServletName().equals(name)) { 47 return servletDefinition; 48 } 49 } 50 return null; 51 } 52 53 55 public ServletDefinition add(String name, String className) 56 { 57 ServletDefinitionImpl servletDefinition = new ServletDefinitionImpl(); 58 servletDefinition.setServletName(name); 59 servletDefinition.setServletClass(className); 60 61 super.add(servletDefinition); 62 63 return servletDefinition; 64 } 65 66 public ServletDefinition remove(String name) 67 { 68 Iterator iterator = this.iterator(); 69 while (iterator.hasNext()) { 70 ServletDefinition servletDefinition = (ServletDefinition)iterator.next(); 71 if (servletDefinition.getServletName().equals(name)) { 72 super.remove(servletDefinition); 73 return servletDefinition; 74 } 75 } 76 return null; 77 } 78 79 public void remove(ServletDefinition servletDefinition) 80 { 81 super.remove(servletDefinition); 82 } 83 84 86 public void preBuild(Object parameter) throws Exception 87 { 88 Vector structure = (Vector )parameter; 89 WebApplicationDefinition webApplicationDefinition = (WebApplicationDefinition)structure.get(0); 90 Collection servletMappings = (Collection )structure.get(1); 91 HashMap servletMap = (HashMap )structure.get(2); 92 93 HashMap mappings = new HashMap (servletMappings.size()); 95 Iterator iterator = servletMappings.iterator(); 96 while (iterator.hasNext()) { 97 ServletMappingImpl servletMapping = (ServletMappingImpl)iterator.next(); 98 mappings.put(servletMapping.getServletName(),servletMapping); 99 } 100 iterator = this.iterator(); 102 while (iterator.hasNext()) { 103 ServletDefinition servlet = (ServletDefinition)iterator.next(); 104 ((Support)servlet).preBuild(webApplicationDefinition); 105 106 if (servlet.getInitParameterSet() != null) { 107 if (servlet.getInitParameterSet().get("portlet-guid") != null) { 108 String guid = servlet.getInitParameterSet().get("portlet-guid").getValue(); 109 servletMap.put(guid, servlet); 110 111 ServletMappingImpl servletMapping = (ServletMappingImpl)mappings.get(servlet.getServletName()); 112 if (mappings==null) { 113 throw new XmlException("No corresponding servlet mapping found for servlet name '"+servlet.getServletName()+"'"); 114 } 115 ((Support)servlet).postBuild(servletMapping); 116 117 } 118 } 119 } 120 121 } 122 123 126 public void postBuild(Object parameter) throws Exception { 127 } 128 129 132 public void postLoad(Object parameter) throws Exception { 133 Iterator iterator = this.iterator(); 134 while (iterator.hasNext()) { 135 ((ServletDefinitionImpl)iterator.next()).postLoad(parameter); 136 } 137 138 } 139 140 143 public void postStore(Object parameter) throws Exception { 144 } 145 146 149 public void preStore(Object parameter) throws Exception { 150 } 151 152 154 public String toString() 155 { 156 return toString(0); 157 } 158 159 public String toString(int indent) 160 { 161 StringBuffer buffer = new StringBuffer (50); 162 StringUtils.newLine(buffer,indent); 163 buffer.append(getClass().toString()); 164 buffer.append(": "); 165 Iterator iterator = this.iterator(); 166 while (iterator.hasNext()) { 167 buffer.append(((ServletDefinitionImpl)iterator.next()).toString(indent+2)); 168 } 169 return buffer.toString(); 170 } 171 } 172 | Popular Tags |