KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > soap > server > BaseConfigManager


1 /*
2  * The Apache Software License, Version 1.1
3  *
4  *
5  * Copyright (c) 2000 The Apache Software Foundation. All rights
6  * reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in
17  * the documentation and/or other materials provided with the
18  * distribution.
19  *
20  * 3. The end-user documentation included with the redistribution,
21  * if any, must include the following acknowledgment:
22  * "This product includes software developed by the
23  * Apache Software Foundation (http://www.apache.org/)."
24  * Alternately, this acknowledgment may appear in the software itself,
25  * if and wherever such third-party acknowledgments normally appear.
26  *
27  * 4. The names "SOAP" and "Apache Software Foundation" must
28  * not be used to endorse or promote products derived from this
29  * software without prior written permission. For written
30  * permission, please contact apache@apache.org.
31  *
32  * 5. Products derived from this software may not be called "Apache",
33  * nor may "Apache" appear in their name, without prior written
34  * permission of the Apache Software Foundation.
35  *
36  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
37  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
38  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
39  * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
40  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
42  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
43  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
44  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
45  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
46  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
47  * SUCH DAMAGE.
48  * ====================================================================
49  *
50  * This software consists of voluntary contributions made by many
51  * individuals on behalf of the Apache Software Foundation and was
52  * originally based on software copyright (c) 2000, International
53  * Business Machines, Inc., http://www.apache.org. For more
54  * information on the Apache Software Foundation, please see
55  * <http://www.apache.org/>.
56  */

57
58 package org.apache.soap.server ;
59
60 import java.util.* ;
61 import java.io.* ;
62 import javax.servlet.* ;
63 import javax.servlet.http.* ;
64 import org.apache.soap.* ;
65 import org.apache.soap.rpc.* ;
66 import org.apache.soap.server.* ;
67 import org.apache.soap.server.http.* ;
68 import org.apache.soap.util.* ;
69
70 /**
71  * An <code>XMLConfigManager</code> ...
72  *
73  * @author Dug (dug@us.ibm.com)
74  * @author <a HREF="mailto:magnus@handpoint.com">Magnus Thor Torfason</a>
75  *
76  * This class should be almost identical in function to the
77  * DefaultConfigManager.
78  *
79  * <p>
80  *
81  * The only notable difference is that while
82  * the DefaultConfigManager uses java readObject() and writeObject()
83  * methods, this class uses the XML routines of DeploymentDescriptor
84  * to save and load the DeploymentDescriptors from the underlying
85  * registry file (typically <tt>DeployedServices.xml</tt>).
86  *
87  */

88 public abstract class BaseConfigManager implements ConfigManager {
89   protected Hashtable dds = new Hashtable();
90   protected String JavaDoc[] serviceNamesCache ;
91   protected ServletContext context = null;
92
93   /**
94    * Sets the Servlet Context.
95    */

96   public void setContext(ServletContext context) {
97     this.context = context;
98   }
99
100   /**
101    * The init method loads any services that are defined in
102    * the underlying registry file.
103    */

104   public void init() throws SOAPException {
105     loadRegistry();
106   }
107
108   /**
109    * Used to deploy a service using a specified DeploymentDescriptor.
110    *
111    * <p>
112    *
113    * Note that this method will save the currently deployed services
114    * to the underlying registry file, overriding the old configuration.
115    */

116   public void deploy( DeploymentDescriptor dd ) throws SOAPException {
117     String JavaDoc id = dd.getID();
118     dds.put( id, dd );
119     saveRegistry();
120     serviceNamesCache = null ;
121   }
122
123   /**
124    * Undeploy previously deployed services.
125    *
126    * <p>
127    *
128    * Note that this method will save the currently deployed services
129    * to the underlying registry file, overriding the old configuration.
130    */

131   public DeploymentDescriptor undeploy( String JavaDoc id ) throws SOAPException {
132     DeploymentDescriptor dd = (DeploymentDescriptor) dds.remove( id );
133     if ( dd != null ) {
134       saveRegistry();
135       serviceNamesCache = null ;
136     } else {
137       throw new SOAPException( Constants.FAULT_CODE_SERVER,
138         "Service '" + id + "' unknown" );
139     }
140     return( dd );
141   }
142
143   /**
144    * Returns a list of all currently deployed services.
145    */

146   public String JavaDoc[] list() throws SOAPException {
147     if (serviceNamesCache != null) {
148       return serviceNamesCache;
149     }
150     Enumeration e = dds.keys ();
151     int count = dds.size ();
152     serviceNamesCache = new String JavaDoc[count];
153     for (int i = 0; i < count; i++) {
154       serviceNamesCache[i] = (String JavaDoc) e.nextElement ();
155     }
156     return serviceNamesCache;
157   }
158
159   /**
160    * Returns a DeploymentDescriptor from the ConfigManager.
161    *
162    * <p>
163    *
164    * This method will simply return null if there is no descriptor
165    * corresponding to the id (should it throw a SOAPException ?).
166    */

167   public DeploymentDescriptor query(String JavaDoc id) throws SOAPException {
168     DeploymentDescriptor dd = (DeploymentDescriptor) dds.get (id);
169     return( dd );
170   }
171
172   /**
173    * The loadRegistry() method must be implemented in non-abstract
174    * subclasses of BaseConfigManager.
175    */

176   public abstract void loadRegistry() throws SOAPException;
177
178   /**
179    * The saveRegistry() method must be implemented in non-abstract
180    * subclasses of BaseConfigManager.
181    */

182   public abstract void saveRegistry() throws SOAPException;
183 }
184
Popular Tags