View Javadoc

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.local;
17  
18  import java.io.File;
19  import java.io.FileInputStream;
20  import java.io.IOException;
21  import java.io.InputStream;
22  import java.util.Properties;
23  
24  import org.apache.commons.logging.Log;
25  import org.apache.commons.logging.LogFactory;
26  import org.apache.juddi.registry.RegistryEngine;
27  import org.apache.juddi.util.Loader;
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 Kurt Stam (kurt.stam@redhat.com)
34   */
35  public abstract class Registry
36  { 
37    private static final String CONFIG_FILE_PROPERTY_NAME = "juddi.propertiesFile";
38    // default config file name. 
39    private static final String DEFAULT_PROPERTY_FILE = "juddi.properties";
40     
41    // private reference to the webapp's logger.
42    private static Log log = LogFactory.getLog(Registry.class);
43  
44    // registry singleton instance
45    private static RegistryEngine registry;
46  
47    static
48    {
49        init() ;
50    }
51    
52  /***
53     * Create the shared instance of jUDDI's Registry class
54     * and call it's "init()" method to initialize all core 
55     * components.
56     */
57    private static void init() 
58    {   
59  
60      Properties props = new Properties();
61  
62      try
63      {      
64        log.debug("Loading jUDDI configuration.");
65          
66  //    determine the name of the juddi property file to use from web.xml
67        String propFile = System.getProperty(CONFIG_FILE_PROPERTY_NAME);
68        if ((propFile == null) || (propFile.trim().length() == 0)) {
69          propFile = "/" + DEFAULT_PROPERTY_FILE;
70        }
71     
72        InputStream is = Loader.getResourceAsStream(propFile);
73        if (is==null) {
74      	  log.debug("Loading " + propFile + " using the context classloader failed, trying regular classloader..");
75      	  is = Class.class.getResourceAsStream(propFile);
76        }
77        if (is==null) {
78      	  log.debug("Loading " + propFile + " using the Class classloader failed.");
79      	  if (("/" + DEFAULT_PROPERTY_FILE).equals(propFile)) {
80      		  propFile=DEFAULT_PROPERTY_FILE;
81      	  }
82      	  File configFile = new File(propFile);
83      	  if (!configFile.exists()) {
84      		  log.debug("Could not find " + configFile.getAbsolutePath());
85      	  } else {
86      		  log.debug("Reading juddi properties from " + configFile.getAbsolutePath());
87                is = new FileInputStream(configFile);
88      	  } 
89        }
90        //Adding this to make maven happy, what maven wants, maven gets.
91        if (is==null) {
92            log.debug("Trying the classloader of the class itself. (workaround for maven2)");
93            Loader loader = new Loader();
94            is = loader.getResourceAsStreamFromClass(propFile);
95        }
96        
97        if (is != null)
98        {
99          log.debug("Resources loaded from: "+propFile);
100         props.load(is);
101         is.close();
102       }
103       else
104       {
105         log.warn("Could not locate jUDDI properties '" + propFile + 
106                 "'. Using defaults.");
107 
108         // A juddi.properties file doesn't exist
109         // yet so create create a new Properties 
110         // instance using default property values.
111         
112         props.put(RegistryEngine.PROPNAME_OPERATOR_NAME,
113                   RegistryEngine.DEFAULT_OPERATOR_NAME);
114         
115         props.put(RegistryEngine.PROPNAME_I18N_LANGUAGE_CODE,
116             			RegistryEngine.DEFAULT_I18N_LANGUAGE_CODE);
117   
118         props.put(RegistryEngine.PROPNAME_I18N_COUNTRY_CODE,
119             			RegistryEngine.DEFAULT_I18N_COUNTRY_CODE);
120   
121         props.put(RegistryEngine.PROPNAME_DISCOVERY_URL,
122                   RegistryEngine.DEFAULT_DISCOVERY_URL);
123         
124         props.put(RegistryEngine.PROPNAME_ADMIN_EMAIL_ADDRESS,
125                   RegistryEngine.DEFAULT_ADMIN_EMAIL_ADDRESS);
126         
127         props.put(RegistryEngine.PROPNAME_DATASOURCE_NAME,
128                   RegistryEngine.DEFAULT_DATASOURCE_NAME);
129         
130         props.put(RegistryEngine.PROPNAME_IS_USE_DATASOURCE,
131                   RegistryEngine.DEFAULT_IS_USE_DATASOURCE);
132         
133         props.put(RegistryEngine.PROPNAME_JDBC_DRIVER,
134                 RegistryEngine.DEFAULT_JDBC_DRIVER);
135       
136         props.put(RegistryEngine.PROPNAME_JDBC_URL,
137                 RegistryEngine.DEFAULT_JDBC_URL);
138       
139         props.put(RegistryEngine.PROPNAME_JDBC_USERNAME,
140                 RegistryEngine.DEFAULT_JDBC_USERNAME);
141       
142         props.put(RegistryEngine.PROPNAME_JDBC_PASSWORD,
143                 RegistryEngine.DEFAULT_JDBC_PASSWORD);
144               
145         props.put(RegistryEngine.PROPNAME_AUTH_CLASS_NAME,
146                   RegistryEngine.DEFAULT_AUTH_CLASS_NAME);
147         
148         props.put(RegistryEngine.PROPNAME_CRYPTOR_CLASS_NAME,
149                   RegistryEngine.DEFAULT_CRYPTOR_CLASS_NAME);
150         
151         props.put(RegistryEngine.PROPNAME_DATASTORE_CLASS_NAME,
152                   RegistryEngine.DEFAULT_DATASTORE_CLASS_NAME);
153         
154         props.put(RegistryEngine.PROPNAME_UUIDGEN_CLASS_NAME,
155                   RegistryEngine.DEFAULT_UUIDGEN_CLASS_NAME);
156         
157         props.put(RegistryEngine.PROPNAME_VALIDATOR_CLASS_NAME,
158                   RegistryEngine.DEFAULT_VALIDATOR_CLASS_NAME);  
159 
160         props.put(RegistryEngine.PROPNAME_MAX_NAME_ELEMENTS,
161                   Integer.toString(RegistryEngine.DEFAULT_MAX_NAME_ELEMENTS));
162         
163         props.put(RegistryEngine.PROPNAME_MAX_NAME_LENGTH,
164                   Integer.toString(RegistryEngine.DEFAULT_MAX_NAME_LENGTH));
165 
166         props.put(RegistryEngine.PROPNAME_MAX_MESSAGE_SIZE,
167                   Integer.toString(RegistryEngine.DEFAULT_MAX_MESSAGE_SIZE));        
168 
169         props.put(RegistryEngine.PROPNAME_MAX_BUSINESSES_PER_PUBLISHER,
170                   Integer.toString(RegistryEngine.DEFAULT_MAX_BUSINESSES_PER_PUBLISHER));
171         
172         props.put(RegistryEngine.PROPNAME_MAX_SERVICES_PER_BUSINESS,
173                   Integer.toString(RegistryEngine.DEFAULT_MAX_SERVICES_PER_BUSINESS));
174         
175         props.put(RegistryEngine.PROPNAME_MAX_BINDINGS_PER_SERVICE,
176                   Integer.toString(RegistryEngine.DEFAULT_MAX_BINDINGS_PER_SERVICE));
177         
178         props.put(RegistryEngine.PROPNAME_MAX_TMODELS_PER_PUBLISHER,
179                   Integer.toString(RegistryEngine.DEFAULT_MAX_TMODELS_PER_PUBLISHER));
180         
181         props.put(RegistryEngine.PROPNAME_MAX_ROWS_LIMIT,           
182                   Integer.toString(RegistryEngine.DEFAULT_MAX_ROWS_LIMIT));
183         
184         props.put(RegistryEngine.PROPNAME_JAVA_NAMING_FACTORY_INITIAL,           
185                 RegistryEngine.DEFAULT_JAVA_NAMING_FACTORY_INITIAL);
186       
187         props.put(RegistryEngine.PROPNAME_JAVA_NAMING_PROVIDER_URL,           
188                 RegistryEngine.DEFAULT_JAVA_NAMING_PROVIDER_URL);
189       
190         props.put(RegistryEngine.PROPNAME_JAVA_NAMING_FACTORY_URL_PKGS,           
191                 RegistryEngine.DEFAULT_JAVA_NAMING_FACTORY_URL_PKGS);
192         
193       }
194     }
195     catch(IOException ioex) {
196       log.error(ioex.getMessage(),ioex);
197     }
198 
199     log.debug("Initializing jUDDI components.");
200     
201     registry = new RegistryEngine(props);
202     registry.init();
203   }
204   
205   /***
206    * Grab the shared instance of jUDDI's Registry class and
207    * call it's "dispose()" method to notify all sub-components
208    * to stop any background threads and release any external
209    * resources they may have aquired.
210    */
211   public void destroy()
212   {
213     log.info("jUDDI Stopping: Cleaning up existing resources.");
214 
215     RegistryEngine registry = Registry.getRegistry();
216     if (registry != null)
217       registry.dispose();
218   }
219 
220   /***
221    *
222    */
223   public static RegistryEngine getRegistry()
224   {
225       return registry;
226   }
227 
228   private Registry() {
229 	super();
230   }
231   
232   
233 }