KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.apache.commons.logging.Log;
23 import org.apache.commons.logging.LogFactory;
24 import org.apache.juddi.AbstractRegistry;
25 import org.apache.juddi.datatype.RegistryObject;
26 import org.apache.juddi.datatype.request.AuthInfo;
27 import org.apache.juddi.datatype.response.AuthToken;
28 import org.apache.juddi.error.RegistryException;
29 import org.apache.juddi.error.UnsupportedException;
30 import org.apache.juddi.function.FunctionMaker;
31 import org.apache.juddi.function.IFunction;
32 import org.apache.juddi.util.Config;
33 import org.apache.juddi.util.Loader;
34
35 /**
36  * @author Steve Viens (sviens@apache.org)
37  */

38 public class RegistryEngine extends AbstractRegistry
39 {
40   // Registry Property File Name
41
private static final String JavaDoc PROPFILE_NAME = "juddi.properties";
42   
43   // Registry Property Names
44
//
45
public static final String JavaDoc PROPNAME_OPERATOR_NAME = "juddi.operatorName";
46   
47   public static final String JavaDoc PROPNAME_I18N_LANGUAGE_CODE = "juddi.i18n.languageCode";
48   public static final String JavaDoc PROPNAME_I18N_COUNTRY_CODE = "juddi.i18n.countryCode";
49   
50   public static final String JavaDoc PROPNAME_DISCOVERY_URL = "juddi.discoveryURL";
51   public static final String JavaDoc PROPNAME_ADMIN_EMAIL_ADDRESS = "juddi.adminEmailAddress"; // unused
52
public static final String JavaDoc PROPNAME_DATASOURCE_NAME = "juddi.dataSource";
53   
54   public static final String JavaDoc PROPNAME_AUTH_CLASS_NAME = "juddi.auth";
55   public static final String JavaDoc PROPNAME_DATASTORE_CLASS_NAME = "juddi.dataStore";
56   public static final String JavaDoc PROPNAME_CRYPTOR_CLASS_NAME = "juddi.cryptor";
57   public static final String JavaDoc PROPNAME_UUIDGEN_CLASS_NAME = "juddi.uuidgen";
58   public static final String JavaDoc PROPNAME_VALIDATOR_CLASS_NAME = "juddi.validator";
59   
60   public static final String JavaDoc PROPNAME_MAX_NAME_ELEMENTS = "juddi.maxNameElementsAllowed";
61   public static final String JavaDoc PROPNAME_MAX_NAME_LENGTH = "juddi.maxNameLengthAllowed";
62   public static final String JavaDoc PROPNAME_MAX_MESSAGE_SIZE = "juddi.maxMessageSize"; // unused
63
public static final String JavaDoc PROPNAME_MAX_BUSINESS_ENTITIES_PER_USER = "juddi.maxBusinessEntitiesPerUser"; // unused
64
public static final String JavaDoc PROPNAME_MAX_BUSINESS_SERVICES_PER_BUSINESS = "juddi.maxBusinessServicesPerBusiness"; // unused
65
public static final String JavaDoc PROPNAME_MAX_BINDING_TEMPLATES_PER_SERVICE = "juddi.maxBindingTemplatesPerService"; // unused
66
public static final String JavaDoc PROPNAME_MAX_TMODELS_PER_USER = "juddi.maxTModelsPerUser"; // unused
67
public static final String JavaDoc PROPNAME_MAX_ROWS_LIMIT = "juddi.maxRowsLimit"; // unused
68

69   // Registry Default Property Values
70
//
71
public static final String JavaDoc DEFAULT_OPERATOR_NAME = "Apache.org";
72   
73   public static final String JavaDoc DEFAULT_I18N_LANGUAGE_CODE = "en";
74   public static final String JavaDoc DEFAULT_I18N_COUNTRY_CODE = "US";
75   
76   public static final String JavaDoc DEFAULT_DISCOVERY_URL = "http://localhost:8080/juddi/uddiget.jsp?";
77   public static final String JavaDoc DEFAULT_ADMIN_EMAIL_ADDRESS = "nobody@apache.org"; // unused
78
public static final String JavaDoc DEFAULT_DATASOURCE_NAME = "java:comp/env/jdbc/juddiDB";
79   
80   public static final String JavaDoc DEFAULT_AUTH_CLASS_NAME = "org.apache.juddi.auth.DefaultAuthenticator";
81   public static final String JavaDoc DEFAULT_DATASTORE_CLASS_NAME = "org.apache.juddi.datastore.JDBCDataStore";
82   public static final String JavaDoc DEFAULT_CRYPTOR_CLASS_NAME = "org.apache.juddi.cryptor.DefaultCryptor";
83   public static final String JavaDoc DEFAULT_UUIDGEN_CLASS_NAME = "org.apache.juddi.uuidgen.DefaultUUIDGen";
84   public static final String JavaDoc DEFAULT_VALIDATOR_CLASS_NAME = "org.apache.juddi.validator.DefaultValidator";
85   
86   public static final int DEFAULT_MAX_NAME_ELEMENTS = 5;
87   public static final int DEFAULT_MAX_NAME_LENGTH = 255;
88   public static final int DEFAULT_MAX_MESSAGE_SIZE = 2097152; // unused
89
public static final int DEFAULT_MAX_BUSINESS_ENTITIES_PER_USER = 25; // unused
90
public static final int DEFAULT_MAX_BUSINESS_SERVICES_PER_BUSINESS = 20; // unused
91
public static final int DEFAULT_MAX_BINDING_TEMPLATES_PER_SERVICE = 10; // unused
92
public static final int DEFAULT_MAX_TMODELS_PER_USER = 100; // unused
93
public static final int DEFAULT_MAX_ROWS_LIMIT = 10; // unused
94

95   // private reference to the jUDDI logger
96
private static Log log = LogFactory.getLog(RegistryEngine.class);
97
98   // Function maker
99
private FunctionMaker maker = null;
100
101   // registry status
102
private boolean isAvailable = false;
103
104   /**
105    * Create a new instance of RegistryEngine. This constructor
106    * looks in the classpath for a file named 'juddi.properties'
107    * and uses property values in this file to initialize the
108    * new instance. Default values are used if the file does not
109    * exist or if a particular property value is not present.
110    */

111   public RegistryEngine()
112   {
113     super();
114
115     // Add jUDDI properties from the juddi.properties
116
// file found in the classpath. Duplicate property
117
// values added in init() will be overwritten.
118
try {
119       InputStream JavaDoc stream = Loader.getResourceAsStream(PROPFILE_NAME);
120       if (stream != null)
121       {
122         Properties JavaDoc props = new Properties JavaDoc();
123         props.load(stream);
124         Config.addProperties(props);
125       }
126     }
127     catch (IOException JavaDoc ioex) {
128       log.error("An error occured while loading properties from: "+PROPFILE_NAME,ioex);
129     }
130   }
131
132   /**
133    * Creates a new instance of RegistryEngine. This constructor
134    * uses the property values passed in the Properties parameter
135    * to initialize the new RegistryProxy instance. Default values
136    * are used if the file does not exist or if a particular
137    * property value is not present.
138    */

139   public RegistryEngine(Properties JavaDoc props)
140   {
141     super();
142
143     if (props != null)
144       Config.addProperties(props);
145   }
146
147   /**
148    * Initialize required resources.
149    */

150   public void init()
151   {
152     // Turn off registry access
153
isAvailable = false;
154
155     // Grab a reference to the function
156
// registry (hmm bad name choice).
157
this.maker = new FunctionMaker(this);
158
159     // Turn on registry access
160
isAvailable = true;
161   }
162
163   /**
164    * Releases any acquired resources. Will stop these
165    * if they are currently running.
166    */

167   public void dispose()
168   {
169     // Turn off registry access
170
isAvailable = false;
171   }
172
173   /**
174    * Returns 'true' if the registry is available
175    * to handle requests, otherwise returns 'false'.
176    */

177   public boolean isAvailable()
178   {
179     return this.isAvailable;
180   }
181
182   /**
183    *
184    */

185   public RegistryObject execute(RegistryObject request)
186     throws RegistryException
187   {
188     String JavaDoc className = request.getClass().getName();
189
190     IFunction function = (IFunction)maker.lookup(className);
191     if (function == null)
192       throw new UnsupportedException(className);
193
194     RegistryObject response = function.execute(request);
195
196     return response;
197   }
198
199
200   /***************************************************************************/
201   /***************************** TEST DRIVER *********************************/
202   /***************************************************************************/
203
204
205   public static void main(String JavaDoc[] args)
206     throws Exception JavaDoc
207   {
208     // Option #1 (grabs properties from juddi.properties file)
209
//RegistryEngine registry = new RegistryEngine();
210

211     // Option #2 (provides properties in Properties instance)
212
Properties JavaDoc props = new Properties JavaDoc();
213     props.setProperty(RegistryEngine.PROPNAME_OPERATOR_NAME,"jUDDI.org");
214     props.setProperty(RegistryEngine.PROPNAME_MAX_NAME_ELEMENTS,"5");
215     props.setProperty(RegistryEngine.PROPNAME_MAX_NAME_LENGTH,"255");
216     props.setProperty(RegistryEngine.PROPNAME_DISCOVERY_URL,"http://localhost/juddi");
217     props.setProperty(RegistryEngine.PROPNAME_ADMIN_EMAIL_ADDRESS,"admin@juddi.org");
218     props.setProperty(RegistryEngine.PROPNAME_MAX_MESSAGE_SIZE,"2097152");
219     props.setProperty(RegistryEngine.PROPNAME_AUTH_CLASS_NAME,"org.apache.juddi.auth.DefaultAuthenticator");
220     props.setProperty(RegistryEngine.PROPNAME_CRYPTOR_CLASS_NAME,"org.apache.juddi.cryptor.DefaultCryptor");
221     props.setProperty(RegistryEngine.PROPNAME_UUIDGEN_CLASS_NAME,"org.apache.juddi.uuidgen.DefaultUUIDGen");
222     
223     props.setProperty("juddi.useConnectionPool","true");
224     props.setProperty("juddi.jdbcDriver","com.mysql.jdbc.Driver");
225     props.setProperty("juddi.jdbcURL","jdbc:mysql://localhost/juddi");
226     props.setProperty("juddi.jdbcUser","juddi");
227     props.setProperty("juddi.jdbcPassword","juddi");
228     props.setProperty("juddi.jdbcMaxActive","10");
229     props.setProperty("juddi.jdbcMaxIdle","10");
230     
231     RegistryEngine registry = new RegistryEngine(props);
232
233     // initialize the registry
234
registry.init();
235
236     // write all properties to the console
237
System.out.println(Config.getProperties());
238
239     AuthToken authToken = registry.getAuthToken("sviens","password");
240     AuthInfo authInfo = authToken.getAuthInfo();
241
242     System.out.println("AuthToken: "+authInfo.getValue());
243
244     // tear down the registry
245
registry.dispose();
246   }
247 }
Popular Tags