1 57 58 package org.apache.soap.server ; 59 60 import java.util.* ; 62 import java.io.* ; 63 64 import javax.servlet.* ; 66 import javax.servlet.http.* ; 67 68 import javax.xml.parsers.* ; 70 import org.w3c.dom.* ; 71 import org.xml.sax.* ; 72 73 import org.apache.soap.* ; 75 import org.apache.soap.rpc.* ; 76 import org.apache.soap.server.* ; 77 import org.apache.soap.server.http.* ; 78 import org.apache.soap.util.* ; 79 import org.apache.soap.util.xml.* ; 80 81 98 public class XMLConfigManager extends BaseConfigManager 99 implements ConfigManager { 100 protected DocumentBuilder xdb = XMLParserUtils.getXMLDocBuilder(); 101 102 103 protected String filename = "DeployedServices.xml"; 104 105 109 public void setOptions( Hashtable options ) { 110 if ( options == null ) return ; 111 112 String value = (String ) options.get( "filename" ); 113 if ( value != null && !"".equals(value) ) { 114 filename = value ; 115 } 116 } 117 118 122 public void loadRegistry() throws SOAPException { 123 dds = null ; 124 try { 125 File file = ServerHTTPUtils.getFileFromNameAndContext(filename, 126 context); 127 FileReader rd = new FileReader (file); 128 Document doc = null; 129 Element root = null; 130 131 try { 132 doc = xdb.parse(new InputSource(rd)); 133 root = doc.getDocumentElement(); 134 } catch (Exception e) { 135 e.printStackTrace(); 136 throw new SOAPException(Constants.FAULT_CODE_SERVER,e.getMessage()); 137 } 138 139 NodeList deploymentElements = root.getElementsByTagNameNS( 140 Constants.NS_URI_XML_SOAP_DEPLOYMENT, "service"); 141 142 int count = deploymentElements.getLength(); 143 dds = new Hashtable(); 144 for( int i=0; i<count; i++ ) { 145 Element deploymentElement = (Element)deploymentElements.item(i); 146 DeploymentDescriptor dd = DeploymentDescriptor.fromXML( 147 deploymentElement); 148 String id = dd.getID(); 149 dds.put( id, dd ); 150 } 151 } catch(Exception e) { 152 dds = new Hashtable (); 153 System.err.println ("SOAP Service Manager: Unable to read '" + 154 filename + "': assuming fresh start"); 155 } 156 } 157 158 162 public void saveRegistry() throws SOAPException { 163 try { 164 File file = ServerHTTPUtils.getFileFromNameAndContext(filename, 165 context); 166 PrintWriter pw = new PrintWriter(new FileWriter (file)); 167 Enumeration e = dds.elements(); 168 169 pw.println("<deployedServices>"); 170 pw.println(); 171 while ( e.hasMoreElements() ) { 172 DeploymentDescriptor dd = (DeploymentDescriptor)e.nextElement(); 173 dd.toXML(pw); 174 pw.println(); 175 } 176 pw.println("</deployedServices>"); 177 178 pw.close (); 179 } catch (Exception e) { 180 throw new SOAPException (Constants.FAULT_CODE_SERVER, 181 "Error saving services registry: " + 182 e.getMessage ()); 183 } 184 } 185 } 186 187 | Popular Tags |