1 16 package org.apache.axis.deployment.wsdd; 17 18 import org.apache.axis.ConfigurationException; 19 import org.apache.axis.components.logger.LogFactory; 20 import org.apache.axis.encoding.SerializationContext; 21 import org.apache.axis.utils.Messages; 22 import org.apache.axis.utils.XMLUtils; 23 import org.apache.commons.logging.Log; 24 import org.w3c.dom.Document ; 25 import org.w3c.dom.Element ; 26 import org.xml.sax.InputSource ; 27 28 import java.io.IOException ; 29 import java.io.StringReader ; 30 import java.io.StringWriter ; 31 32 33 37 public class WSDDDocument extends WSDDConstants 38 { 39 protected static Log log = 40 LogFactory.getLog(WSDDDocument.class.getName()); 41 42 43 private Document doc; 44 45 48 private WSDDDeployment deployment; 49 50 private WSDDUndeployment undeployment; 51 52 55 public WSDDDocument() 56 { 57 } 58 59 63 public WSDDDocument(Document document) throws WSDDException 64 { 65 setDocument(document); 66 } 67 68 72 public WSDDDocument(Element e) throws WSDDException 73 { 74 doc = e.getOwnerDocument(); 75 if (ELEM_WSDD_UNDEPLOY.equals(e.getLocalName())) { 76 undeployment = new WSDDUndeployment(e); 77 } else { 78 deployment = new WSDDDeployment(e); 79 } 80 } 81 82 86 public WSDDDeployment getDeployment() 87 { 88 if (deployment == null) { 89 deployment = new WSDDDeployment(); 90 } 91 return deployment; 92 } 93 94 100 public Document getDOMDocument() throws ConfigurationException { 101 StringWriter writer = new StringWriter (); 102 SerializationContext context = new SerializationContext(writer, null); 103 context.setPretty(true); 104 try { 105 deployment.writeToContext(context); 106 } catch (Exception e) { 107 log.error(Messages.getMessage("exception00"), e); 108 } 109 try { 110 writer.close(); 111 return XMLUtils.newDocument(new InputSource (new StringReader (writer.getBuffer().toString()))); 112 } catch (Exception e) { 113 return null; 114 } 115 } 116 117 122 public void writeToContext(SerializationContext context) 123 throws IOException 124 { 125 getDeployment().writeToContext(context); 126 } 127 128 133 public void setDocument(Document document) throws WSDDException { 134 this.doc = document; 135 Element docEl = doc.getDocumentElement(); 136 if (ELEM_WSDD_UNDEPLOY.equals(docEl.getLocalName())) { 137 undeployment = new WSDDUndeployment(docEl); 138 } else { 139 deployment = new WSDDDeployment(docEl); 140 } 141 } 142 143 149 public void deploy(WSDDDeployment registry) throws ConfigurationException { 150 if (deployment != null) { 151 deployment.deployToRegistry(registry); 152 } 153 if (undeployment != null) { 154 undeployment.undeployFromRegistry(registry); 155 } 156 } 157 } 158 | Popular Tags |