1 16 package org.apache.axis.deployment.wsdd; 17 18 import org.apache.axis.ConfigurationException; 19 import org.apache.axis.encoding.SerializationContext; 20 import org.apache.axis.handlers.soap.SOAPService; 21 import org.apache.axis.MessageContext; 22 import org.apache.axis.utils.Messages; 23 import org.w3c.dom.Element ; 24 import org.xml.sax.helpers.AttributesImpl ; 25 26 import javax.xml.namespace.QName ; 27 import java.io.IOException ; 28 import java.util.Iterator ; 29 import java.util.Vector ; 30 31 32 37 public class WSDDUndeployment 38 extends WSDDElement 39 implements WSDDTypeMappingContainer 40 { 41 private Vector handlers = new Vector (); 42 private Vector chains = new Vector (); 43 private Vector services = new Vector (); 44 private Vector transports = new Vector (); 45 private Vector typeMappings = new Vector (); 46 47 public void addHandler(QName handler) 48 { 49 handlers.add(handler); 50 } 51 52 public void addChain(QName chain) 53 { 54 chains.add(chain); 55 } 56 57 public void addTransport(QName transport) 58 { 59 transports.add(transport); 60 } 61 62 public void addService(QName service) 63 { 64 services.add(service); 65 } 66 67 public void deployTypeMapping(WSDDTypeMapping typeMapping) 68 throws WSDDException 69 { 70 typeMappings.add(typeMapping); 71 } 72 73 76 public WSDDUndeployment() 77 { 78 } 79 80 private QName getQName(Element el) throws WSDDException 81 { 82 String attr = el.getAttribute(ATTR_NAME); 83 if (attr == null || "".equals(attr)) 84 throw new WSDDException(Messages.getMessage("badNameAttr00")); 85 return new QName ("", attr); 86 } 87 88 94 public WSDDUndeployment(Element e) 95 throws WSDDException 96 { 97 super(e); 98 99 Element [] elements = getChildElements(e, ELEM_WSDD_HANDLER); 100 int i; 101 102 for (i = 0; i < elements.length; i++) { 103 addHandler(getQName(elements[i])); 104 } 105 106 elements = getChildElements(e, ELEM_WSDD_CHAIN); 107 for (i = 0; i < elements.length; i++) { 108 addChain(getQName(elements[i])); 109 } 110 111 elements = getChildElements(e, ELEM_WSDD_TRANSPORT); 112 for (i = 0; i < elements.length; i++) { 113 addTransport(getQName(elements[i])); 114 } 115 116 elements = getChildElements(e, ELEM_WSDD_SERVICE); 117 for (i = 0; i < elements.length; i++) { 118 addService(getQName(elements[i])); 119 } 120 121 136 } 137 138 protected QName getElementName() 139 { 140 return QNAME_UNDEPLOY; 141 } 142 143 public void undeployFromRegistry(WSDDDeployment registry) 144 throws ConfigurationException 145 { 146 QName qname; 147 for (int n = 0; n < handlers.size(); n++) { 148 qname = (QName )handlers.get(n); 149 registry.undeployHandler(qname); 150 } 151 152 for (int n = 0; n < chains.size(); n++) { 153 qname = (QName )chains.get(n); 154 registry.undeployHandler(qname); 155 } 156 157 for (int n = 0; n < transports.size(); n++) { 158 qname = (QName )transports.get(n); 159 registry.undeployTransport(qname); 160 } 161 162 for (int n = 0; n < services.size(); n++) { 163 qname = (QName )services.get(n); 164 165 try { 166 String sname = qname.getLocalPart(); 167 MessageContext messageContext = MessageContext.getCurrentContext(); 168 if (messageContext != null) { 169 SOAPService service = messageContext.getAxisEngine() 170 .getService(sname); 171 if ( service != null ) service.clearSessions(); 172 } 173 } catch(Exception exp) { 174 throw new ConfigurationException(exp); 175 } 176 registry.undeployService(qname); 177 } 178 } 179 180 private void writeElement(SerializationContext context, 181 QName elementQName, 182 QName qname) 183 throws IOException 184 { 185 AttributesImpl attrs = new org.xml.sax.helpers.AttributesImpl (); 186 attrs.addAttribute("", ATTR_NAME, ATTR_NAME, "CDATA", 187 context.qName2String(qname)); 188 189 context.startElement(elementQName, attrs); 190 context.endElement(); 191 } 192 193 public void writeToContext(SerializationContext context) 194 throws IOException 195 { 196 context.registerPrefixForURI(NS_PREFIX_WSDD, URI_WSDD); 197 context.startElement(WSDDConstants.QNAME_UNDEPLOY, null); 198 199 Iterator i = handlers.iterator(); 200 QName qname; 201 while (i.hasNext()) { 202 qname = (QName )i.next(); 203 writeElement(context, QNAME_HANDLER, qname); 204 } 205 206 i = chains.iterator(); 207 while (i.hasNext()) { 208 qname = (QName )i.next(); 209 writeElement(context, QNAME_CHAIN, qname); 210 } 211 212 i = services.iterator(); 213 while (i.hasNext()) { 214 qname = (QName )i.next(); 215 writeElement(context, QNAME_SERVICE, qname); 216 } 217 218 i = transports.iterator(); 219 while (i.hasNext()) { 220 qname = (QName )i.next(); 221 writeElement(context, QNAME_TRANSPORT, qname); 222 } 223 224 i = typeMappings.iterator(); 225 while (i.hasNext()) { 226 WSDDTypeMapping mapping = (WSDDTypeMapping)i.next(); 227 mapping.writeToContext(context); 228 } 229 230 context.endElement(); 231 } 232 233 237 public WSDDTypeMapping[] getTypeMappings() 238 { 239 WSDDTypeMapping[] t = new WSDDTypeMapping[typeMappings.size()]; 240 typeMappings.toArray(t); 241 return t; 242 } 243 244 } 245 | Popular Tags |