KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > juddi > registry > RegistryServlet


1 /*
2  * Copyright 2001-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.juddi.registry;
17
18 import java.io.IOException JavaDoc;
19 import java.io.InputStream JavaDoc;
20 import java.util.Properties JavaDoc;
21
22 import javax.servlet.ServletConfig JavaDoc;
23 import javax.servlet.ServletException JavaDoc;
24 import javax.servlet.http.HttpServlet JavaDoc;
25
26 import org.apache.commons.logging.Log;
27 import org.apache.commons.logging.LogFactory;
28
29 /**
30  * This servlet is ONLY used to initialize the jUDDI webapp on
31  * startup and cleanup the jUDDI webapp on shutdown.
32  *
33  * @author Steve Viens (sviens@apache.org)
34  */

35 public class RegistryServlet extends HttpServlet JavaDoc
36 {
37   // config file property name (used to look up the juddi property file name).
38
private static final String JavaDoc CONFIG_FILE_PROPERTY_NAME = "juddi.propertiesFile";
39   
40   // default config file name.
41
private static final String JavaDoc DEFAULT_PROPERTY_FILE = "/WEB-INF/juddi.properties";
42    
43   // private reference to the webapp's logger.
44
private static Log log = LogFactory.getLog(RegistryServlet.class);
45
46   // registry singleton instance
47
private static RegistryEngine registry = null;
48
49   /**
50    * Create the shared instance of jUDDI's Registry class
51    * and call it's "init()" method to initialize all core
52    * components.
53    */

54   public void init(ServletConfig JavaDoc config)
55     throws ServletException JavaDoc
56   {
57     super.init(config);
58
59     Properties JavaDoc props = new Properties JavaDoc();
60
61     try
62     {
63       log.info("Loading jUDDI configuration.");
64         
65       // determine the name of the juddi property file to use from web.xml
66
String JavaDoc propFile = config.getInitParameter(CONFIG_FILE_PROPERTY_NAME);
67       if ((propFile == null) || (propFile.trim().length() == 0))
68         propFile = DEFAULT_PROPERTY_FILE;
69       
70       InputStream JavaDoc is =
71         getServletContext().getResourceAsStream(propFile);
72         
73       if (is != null)
74       {
75         log.info("Resources loaded from: "+propFile);
76
77         // Load jUDDI configuration from the
78
// juddi.properties file found in the
79
// WEB-INF directory.
80

81         props.load(is);
82       }
83       else
84       {
85         log.warn("Could not locate jUDDI properties '" + propFile +
86                 "'. Using defaults.");
87
88         // A juddi.properties file doesn't exist
89
// yet so create create a new Properties
90
// instance using default property values.
91

92         props.put(RegistryEngine.PROPNAME_OPERATOR_NAME,
93                   RegistryEngine.DEFAULT_OPERATOR_NAME);
94         
95         props.put(RegistryEngine.PROPNAME_I18N_LANGUAGE_CODE,
96                         RegistryEngine.DEFAULT_I18N_LANGUAGE_CODE);
97   
98         props.put(RegistryEngine.PROPNAME_I18N_COUNTRY_CODE,
99                         RegistryEngine.DEFAULT_I18N_COUNTRY_CODE);
100   
101         props.put(RegistryEngine.PROPNAME_DISCOVERY_URL,
102                   RegistryEngine.DEFAULT_DISCOVERY_URL);
103         
104         props.put(RegistryEngine.PROPNAME_ADMIN_EMAIL_ADDRESS,
105                   RegistryEngine.DEFAULT_ADMIN_EMAIL_ADDRESS);
106         
107         props.put(RegistryEngine.PROPNAME_DATASOURCE_NAME,
108                   RegistryEngine.DEFAULT_DATASOURCE_NAME);
109               
110         props.put(RegistryEngine.PROPNAME_AUTH_CLASS_NAME,
111                   RegistryEngine.DEFAULT_AUTH_CLASS_NAME);
112         
113         props.put(RegistryEngine.PROPNAME_CRYPTOR_CLASS_NAME,
114                   RegistryEngine.DEFAULT_CRYPTOR_CLASS_NAME);
115         
116         props.put(RegistryEngine.PROPNAME_DATASTORE_CLASS_NAME,
117                   RegistryEngine.DEFAULT_DATASTORE_CLASS_NAME);
118         
119         props.put(RegistryEngine.PROPNAME_UUIDGEN_CLASS_NAME,
120                   RegistryEngine.DEFAULT_UUIDGEN_CLASS_NAME);
121         
122         props.put(RegistryEngine.PROPNAME_VALIDATOR_CLASS_NAME,
123                   RegistryEngine.DEFAULT_VALIDATOR_CLASS_NAME);
124
125         props.put(RegistryEngine.PROPNAME_MAX_NAME_ELEMENTS,
126                   Integer.toString(RegistryEngine.DEFAULT_MAX_NAME_ELEMENTS));
127         
128         props.put(RegistryEngine.PROPNAME_MAX_NAME_LENGTH,
129                   Integer.toString(RegistryEngine.DEFAULT_MAX_NAME_LENGTH));
130
131         props.put(RegistryEngine.PROPNAME_MAX_MESSAGE_SIZE,
132                   Integer.toString(RegistryEngine.DEFAULT_MAX_MESSAGE_SIZE));
133
134         props.put(RegistryEngine.PROPNAME_MAX_BUSINESS_ENTITIES_PER_USER,
135                   Integer.toString(RegistryEngine.DEFAULT_MAX_BUSINESS_ENTITIES_PER_USER));
136         
137         props.put(RegistryEngine.PROPNAME_MAX_BUSINESS_SERVICES_PER_BUSINESS,
138                   Integer.toString(RegistryEngine.DEFAULT_MAX_BUSINESS_SERVICES_PER_BUSINESS));
139         
140         props.put(RegistryEngine.PROPNAME_MAX_BINDING_TEMPLATES_PER_SERVICE,
141                   Integer.toString(RegistryEngine.DEFAULT_MAX_BINDING_TEMPLATES_PER_SERVICE));
142         
143         props.put(RegistryEngine.PROPNAME_MAX_TMODELS_PER_USER,
144                   Integer.toString(RegistryEngine.DEFAULT_MAX_TMODELS_PER_USER));
145         
146         props.put(RegistryEngine.PROPNAME_MAX_ROWS_LIMIT,
147                   Integer.toString(RegistryEngine.DEFAULT_MAX_ROWS_LIMIT));
148       }
149     }
150     catch(IOException JavaDoc ioex) {
151       log.error(ioex.getMessage(),ioex);
152     }
153
154     log.info("Initializing jUDDI components.");
155     
156     registry = new RegistryEngine(props);
157     registry.init();
158   }
159   
160   /**
161    * Grab the shared instance of jUDDI's Registry class and
162    * call it's "dispose()" method to notify all sub-components
163    * to stop any background threads and release any external
164    * resources they may have aquired.
165    */

166   public void destroy()
167   {
168     super.destroy();
169     
170     log.info("jUDDI Stopping: Cleaning up existing resources.");
171
172     RegistryEngine registry = RegistryServlet.getRegistry();
173     if (registry != null)
174       registry.dispose();
175   }
176
177   /**
178    *
179    */

180   public static RegistryEngine getRegistry()
181   {
182     return registry;
183   }
184 }
Popular Tags