1 55 package org.jboss.axis.deployment.wsdd; 56 57 import org.jboss.axis.ConfigurationException; 58 import org.jboss.axis.encoding.SerializationContext; 59 import org.jboss.axis.encoding.SerializationContextImpl; 60 import org.jboss.axis.utils.Messages; 61 import org.jboss.axis.utils.XMLUtils; 62 import org.jboss.logging.Logger; 63 import org.w3c.dom.Document ; 64 import org.w3c.dom.Element ; 65 import org.xml.sax.InputSource ; 66 67 import java.io.IOException ; 68 import java.io.StringReader ; 69 import java.io.StringWriter ; 70 71 72 75 public class WSDDDocument extends WSDDConstants 76 { 77 private static Logger log = Logger.getLogger(WSDDDocument.class.getName()); 78 79 private Document doc; 80 81 private WSDDDeployment deployment; 82 private WSDDUndeployment undeployment; 83 84 87 public WSDDDocument() 88 { 89 } 90 91 94 public WSDDDocument(Document doc) throws WSDDException 95 { 96 this.doc = doc; 97 Element docEl = doc.getDocumentElement(); 98 if (ELEM_WSDD_UNDEPLOY.equals(docEl.getLocalName())) 99 { 100 undeployment = new WSDDUndeployment(docEl); 101 } 102 else 103 { 104 deployment = new WSDDDeployment(docEl); 105 } 106 } 107 108 111 public WSDDDocument(Element e) throws WSDDException 112 { 113 doc = e.getOwnerDocument(); 114 if (ELEM_WSDD_UNDEPLOY.equals(e.getLocalName())) 115 { 116 undeployment = new WSDDUndeployment(e); 117 } 118 else 119 { 120 deployment = new WSDDDeployment(e); 121 } 122 } 123 124 127 public WSDDDeployment getDeployment() 128 { 129 if (deployment == null) 130 deployment = new WSDDDeployment(); 131 return deployment; 132 } 133 134 public Document getDOMDocument() throws ConfigurationException 135 { 136 StringWriter writer = new StringWriter (); 137 SerializationContext context = new SerializationContextImpl(writer, null); 138 context.setPretty(true); 139 try 140 { 141 deployment.writeToContext(context); 142 } 143 catch (Exception e) 144 { 145 log.error(Messages.getMessage("exception00"), e); 146 } 147 try 148 { 149 writer.close(); 150 return XMLUtils.newDocument(new InputSource (new StringReader (writer.getBuffer().toString()))); 151 } 152 catch (Exception e) 153 { 154 return null; 155 } 156 } 157 158 public void writeToContext(SerializationContext context) 159 throws IOException 160 { 161 getDeployment().writeToContext(context); 162 } 163 164 167 public void setDocument(Document document) 168 { 169 doc = document; 170 171 deployment = null; 172 } 173 174 public void deploy(WSDDDeployment registry) throws ConfigurationException 175 { 176 if (deployment != null) 177 { 178 deployment.deployToRegistry(registry); 179 } 180 if (undeployment != null) 181 { 182 undeployment.undeployFromRegistry(registry); 183 } 184 } 185 } 186 | Popular Tags |