001: ///////////////////////////////
002: // Makumba, Makumba tag library
003: // Copyright (C) 2000-2003 http://www.makumba.org
004: //
005: // This library is free software; you can redistribute it and/or
006: // modify it under the terms of the GNU Lesser General Public
007: // License as published by the Free Software Foundation; either
008: // version 2.1 of the License, or (at your option) any later version.
009: //
010: // This library is distributed in the hope that it will be useful,
011: // but WITHOUT ANY WARRANTY; without even the implied warranty of
012: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: // Lesser General Public License for more details.
014: //
015: // You should have received a copy of the GNU Lesser General Public
016: // License along with this library; if not, write to the Free Software
017: // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
018: //
019: // -------------
020: // $Id: MakumbaSystem.java 2119 2007-11-22 01:12:14Z cristian_bogdan $
021: // $Name$
022: /////////////////////////////////////
023:
024: package org.makumba;
025:
026: import org.makumba.commons.JspWikiFormatter;
027: import org.makumba.commons.WikiFormatter;
028: import org.makumba.forms.html.CalendarEditorProvider;
029: import org.makumba.forms.html.KruseCalendarEditor;
030: import org.makumba.forms.validation.ClientsideValidationProvider;
031: import org.makumba.forms.validation.LiveValidationProvider;
032: import org.makumba.providers.DataDefinitionProvider;
033: import org.makumba.providers.TransactionProvider;
034:
035: /** The makumba runtime system. Provides starter methods to obtain {@link Transaction} and {@link DataDefinition} objects */
036: public class MakumbaSystem {
037: /** DataDefinition provider - FIXME should read which one it is from config */
038: private static DataDefinitionProvider MDDFactory = new DataDefinitionProvider();
039:
040: /** TransactionProvider - FIXME should read which one it is from config */
041: private static TransactionProvider tp = new TransactionProvider();
042:
043: /** The date at which makumba is loaded */
044: static public final java.util.Date loadingTime = new java.util.Date();
045:
046: /**
047: * Get information about the makumba cache sizes.
048: *
049: * @return a {@link java.util.Map} with cache categories as keys and cache sizes as values
050: * @since makumba-0.5.5.13
051: */
052: public static java.util.Map getCacheInfo() {
053: return org.makumba.commons.NamedResources.getCacheInfo();
054: }
055:
056: /**
057: * The name of the default database according to the lookup file "MakumbaDatabase.properties"
058: *
059: * @since makumba-0.5.4
060: * @deprecated Use {@link #getDefaultDataSourceName()} instead
061: */
062: public static String getDefaultDatabaseName() {
063: return tp.getDefaultDataSourceName();
064: }
065:
066: /**
067: * The name of the default database according to the database lookup file indicated
068: *
069: * @param dbLookupFile
070: * the name of the database lookup file, including ".properties", or any other extension. The file should
071: * be in CLASSPATH.
072: * @since makumba-0.5.4
073: * @deprecated use {@link TransactionProvider#getDataSourceName(String)} instead
074: */
075: @Deprecated
076: public static String getDefaultDatabaseName(String dbLookupFile) {
077: return tp.getDataSourceName(dbLookupFile);
078: }
079:
080: /**
081: * Get a connection to the database described in the .properties file with the given name.
082: *
083: * @param name
084: * the database name, the same as the db description file but without ".properties". for example
085: * "localhost_mysql_databasename". The file should be in CLASSPATH. The operations carried out during
086: * database initialization are logged (see {@link java.util.logging.Logger},
087: * {@link org.makumba.MakumbaSystem#setLoggingRoot(java.lang.String)}) in the <b><code>"db.init"</code></b>
088: * and <b><code>"db.init.tablechecking"</code></b> loggers, with {@link java.util.logging.Level#INFO}
089: * (connections, checkings), {@link java.util.logging.Level#SEVERE} (fatal errors) and with
090: * {@link java.util.logging.Level#WARNING} logging levels.
091: * @since makumba-0.5.4
092: * @deprecated use {@link TransactionProvider#getConnectionTo(String)} instead
093: */
094: @Deprecated
095: public static Transaction getConnectionTo(String name) {
096: return tp.getConnectionTo(name);
097: }
098:
099: /**
100: * Get a connection to the default database found according to MakumbaDatabase.properties
101: *
102: * @since makumba-0.5
103: * @deprecated This method name is misleading since it returns a connection, not a database. Use
104: * getConnectionTo(getDefaultDatabaseName()) instead
105: */
106: public static Transaction findDatabase() {
107: return getConnectionTo(tp.getDefaultDataSourceName());
108: }
109:
110: /**
111: * Find the Database according to the given lookup file from the CLASSPATH. The file name will include the
112: * .properties extension
113: *
114: * @since makumba-0.5
115: * @deprecated This method name is misleading since it returns a connection, not a database. Use
116: * getConnectionTo(getDefaultDatabaseName(dbLookupFile)) instead
117: */
118: public static Transaction findDatabase(String dbLookupFile) {
119: return getConnectionTo(getDefaultDatabaseName(dbLookupFile));
120: }
121:
122: /**
123: * Get the Database defined by the given connection file from the CLASSPATH. The file name should not include the
124: * .properties extension
125: *
126: * @since makumba-0.5
127: * @deprecated This method name is misleading since it returns a connection, not a database. Use
128: * getConnectionTo(connectionFile) instead
129: */
130: public static Transaction getDatabase(String connectionFile) {
131: return getConnectionTo(connectionFile);
132: }
133:
134: /**
135: * Access the properties of a database. Besides the properties defined in the database connection file, the
136: * following are available <table border =1>
137: * <tr>
138: * <td><code>sql_engine.name</code>
139: * <td>name of the SQL engine used
140: * <tr>
141: * <td><code>sql_engine.version</code>
142: * <td>version of the SQL engine used
143: * <tr>
144: * <td><code>sql.jdbc_driver.name</code>
145: * <td>name of the JDBC driver used
146: * <tr>
147: * <td><code>jdbc_driver.name</code>
148: * <td>name of the JDBC driver used
149: * <tr>
150: * <td><code>jdbc_driver.version</code>
151: * <td>version of the JDBC driver used
152: * <tr>
153: * <td><code>jdbc_url</code>
154: * <td>JDBC url connected to
155: * <tr>
156: * <td><code>jdbc_connections</code>
157: * <td>number of jdbc connections open </table>
158: *
159: * @since makumba-0.5.5.7
160: */
161: public static String getDatabaseProperty(String name,
162: String propName) {
163: return tp.getDatabaseProperty(name, propName);
164: }
165:
166: /**
167: * Get the DataDefinition defined by the given type. The type a.b.C will generate a lookup for the file
168: * CLASSPATH/a/b/C.mdd and then for CLASSPATH/dataDefinitions/a/b/C.mdd
169: * @deprecated Use {@link DataDefinitionProvider#getDataDefinition(String)} instead
170: */
171: @Deprecated
172: public static DataDefinition getDataDefinition(String typeName) {
173: return MDDFactory.getDataDefinition(typeName);
174: }
175:
176: @Deprecated
177: public static DataDefinition getTemporaryDataDefinition(String name) {
178: return MDDFactory.getVirtualDataDefinition(name);
179: }
180:
181: /** Make a field definition from the indicated string */
182: @Deprecated
183: public static FieldDefinition makeFieldDefinition(String name,
184: String definition) {
185: return MDDFactory.makeFieldDefinition(name, definition);
186: }
187:
188: /** Make a field definition with the elementary type */
189: @Deprecated
190: public static FieldDefinition makeFieldOfType(String name,
191: String type) {
192: return MDDFactory.makeFieldOfType(name, type);
193: }
194:
195: /** Make a field definition identical with the given one, except for the name */
196: @Deprecated
197: public static FieldDefinition makeFieldWithName(String name,
198: FieldDefinition type) {
199: return MDDFactory.makeFieldWithName(name, type);
200: }
201:
202: /** Make a field definition with the elementary type */
203: @Deprecated
204: public static FieldDefinition makeFieldOfType(String name,
205: String type, String description) {
206: return MDDFactory.makeFieldOfType(name, type, description);
207: }
208:
209: /** Make a field definition identical with the given one, except for the name */
210: @Deprecated
211: public static FieldDefinition makeFieldWithName(String name,
212: FieldDefinition type, String description) {
213: return MDDFactory.makeFieldWithName(name, type, description);
214: }
215:
216: /**
217: * Get the DataDefinition of the records returned by the given OQL query
218: *
219: * @deprecated use {@link OQLQueryProvider#getOQLAnalyzer} for better OQL functionality
220:
221: public static DataDefinition getResultDataDefinition(String OQL) {
222: return OQLQueryProvider.getOQLAnalyzer(OQL).getProjectionType();
223: }
224: */
225:
226: /** Returns a Makumba version (derived from a CVS tag) */
227: public static String getVersion() {
228: return org.makumba.version.getVersion();
229: }
230:
231: /** Returns build date (as recorded during building) */
232: public static java.util.Date getBuildDate() {
233: return org.makumba.version.getBuildDate();
234: }
235:
236: static String loggingRoot = "org.makumba";
237:
238: /**
239: * Get a logger for logging during makumba operations. See {@link java.util.logging.Logger},
240: * {@link #setLoggingRoot(java.lang.String)}. This method is mostly used by makumba code. From application code,
241: * use {@link #getLogger(java.lang.String)} or {@link #getLogger() }.
242: * <p>
243: * The table below describes when makumba logging occurs and at what logging {@link java.util.logging.Level} (note
244: * also that {@link java.util.logging.Level#SEVERE} and {@link java.util.logging.Level#WARNING} logging is done in
245: * makumba when fatal errors or warnings occur).
246: * <p>
247: * The logging levels below tell the programmer how to configure logging so that some parts of the makumba logging
248: * become visible. For example, details on database update performance are not normally visible on the log, since
249: * they are at {@link java.util.logging.Level#FINE} logging level, and {@link java.util.logging.Level#INFO} is
250: * default. To view them, one needs to add the following line in <code>logging.properties</code>(see
251: * {@link java.util.logging.LogManager} for explanations of logger configuration)<br>
252: * <blockquote> <code>org.makumba.update.performance.level=FINE</code><br>
253: * </blockquote> The programmer could just as well decide that all makumba logging at or over the level FINE should
254: * be visible, except for the one on taglib performance:<br>
255: * <blockquote> <code>org.makumba.level=FINE</code><br>
256: * <code>org.makumba.taglib.performance.level=INFO</code> </blockquote>
257: * <p>
258: * <table border=1>
259: * <tr>
260: * <td>Operation
261: * <td>Log name
262: * <td>Logging details
263: * <td>Logging level
264: * <tr>
265: * <td>application operations
266: * <td>loggingRoot + <code>apps</code>+ the parameter to {@link #getLogger(java.lang.String)}
267: * <td>logging level used by applications that call {@link #getLogger(java.lang.String)} and {@link #getLogger()}
268: * <td> any, as required by the application
269: * <tr>
270: * <td>database opening
271: * <td>loggingRoot + <code>db.init</code>, <code>db.init.tablechecking</code>
272: * <td>see {@link #getConnectionTo(java.lang.String)}
273: * <td>{@link java.util.logging.Level#INFO}
274: * <tr>
275: * <td>connection pooling
276: * <td>loggingRoot + <code>util.pool
277: <td>infomrmation on the size of the database connection pool
278: <td>{@link java.util.logging.Level#FINE}
279:
280: <tr><td>database administration
281: <td>loggingRoot + <code>db.admin.copy</code>, <code>db.admin.delete
282: <td>see {@link copy#_copy}, {@link HtmlTableImporter#_delete}
283: <td>{@link java.util.logging.Level#INFO}
284:
285: <tr><td>database querying
286: <td>loggingRoot + <code>db.query.compilation</code>,
287: <code>db.query.execution</code>, <code>db.query.performance
288: <td>see {@link org.makumba.Transaction#executeQuery(java.lang.String, java.lang.Object)},
289: {@link org.makumba.Transaction#read(org.makumba.Pointer, java.lang.Object)}
290: <td>{@link java.util.logging.Level#FINE}
291:
292: <tr><td>database query grouping
293: <td>loggingRoot + <code>db.query.grouping
294: <td>grouping used during simulated left joins, e.g. in executing embedded <mak:list> JSP tags
295: <td>{@link java.util.logging.Level#FINE}
296:
297: <tr><td>taglib performace
298: <td>loggingRoot + <code>taglib.performance
299: <td>performance info needed to fine-tune <mak:list> and other makumba JSP tags
300: <td>{@link java.util.logging.Level#FINE}
301:
302: <tr><td>database updating
303: <td>loggingRoot + <code>db.update.execution</code>, <code>db.update.performance
304: <td>see {@link org.makumba.Transaction}, all insert, delete, and update operations
305: <td>{@link java.util.logging.Level#FINE}
306:
307: <tr><td>business logic discovery
308: <td>loggingRoot + <code>controller
309: <td>The steps taken when finding business logic classes
310: <td>{@link java.util.logging.Level#INFO}
311:
312: <tr><td>errors during business logic calls
313: <td>loggingRoot + <code>controller.logicError
314: <td>Runtime (probably involuntary) errors produced by the business logic programmer
315: <td>{@link java.util.logging.Level#INFO}
316:
317: <tr><td>swaping of large content to disk
318: <td>loggingRoot + <code>util.longContent
319: <td>tells when large content in {@link org.makumba.Text} or large content produced by a mak:list tag are swapped to disk
320: <td>{@link java.util.logging.Level#FINE}
321:
322: </table>
323: * @since makumba-0.5.5.3
324: */
325: public static java.util.logging.Logger getMakumbaLogger(
326: String suffix) {
327: return java.util.logging.Logger.getLogger("org.makumba."
328: + suffix);
329: }
330:
331: /**
332: * Return a logger for use by an application.
333: *
334: * @return the logging root + "apps" + the indicated suffix
335: * @see org.makumba.MakumbaSystem#setLoggingRoot(java.lang.String)
336: * @since makumba-0.5.5.3
337: */
338: public static java.util.logging.Logger getLogger(String suffix) {
339: return java.util.logging.Logger.getLogger("org.makumba."
340: + "apps." + suffix);
341: }
342:
343: /**
344: * Return a logger for use by an application.
345: *
346: * @return the logging root plus "apps"
347: * @see org.makumba.MakumbaSystem#setLoggingRoot(java.lang.String)
348: * @since makumba-0.5.5.3
349: */
350: public static java.util.logging.Logger getLogger() {
351: return java.util.logging.Logger.getLogger("org.makumba."
352: + "apps");
353: }
354:
355: /**
356: * Change the makumba logging root in this classloader. The default logging root is <b><code>"org.makumba"</code></b>
357: * so loggers would look like <b><code>org.makumba.db.init.tableckecking</code></b>
358: *
359: * @since makumba-0.5.5.3
360: */
361: public static void setLoggingRoot(String root) {
362: loggingRoot = root;
363: }
364:
365: /**
366: * Returns the timezone in which makumba should read/display dates from/to users, configurable by the system
367: * variable makumba.displayTimeZone
368: */
369: public static java.util.TimeZone getTimeZone() {
370: String s = null;
371: try {
372: s = System.getProperty("makumba.displayTimeZone");
373: } catch (SecurityException e) {
374: } // for applets
375: if (s != null)
376: return java.util.TimeZone.getTimeZone(s);
377: return java.util.TimeZone.getDefault();
378:
379: }
380:
381: /**
382: * @return the system's default wiki formatter.
383: */
384: public static WikiFormatter getWikiFormatter() {
385: return JspWikiFormatter.getInstance();
386: }
387:
388: /** Returns the makumba system locale */
389: // later: should be configurable by config files
390: public static java.util.Locale getLocale() {
391: return java.util.Locale.UK;
392: }
393:
394: /**
395: * Discover mdds in a directory in classpath.
396: *
397: * @return filenames as Vector of Strings.
398: */
399: public static java.util.Vector<String> mddsInDirectory(
400: String dirInClasspath) {
401: return MDDFactory.getDataDefinitionsInLocation(dirInClasspath);
402: }
403:
404: /** Get the default calendar editor. FIXME: read this from some config, or so. */
405: public static CalendarEditorProvider getCalendarProvider() {
406: return KruseCalendarEditor.getInstance();
407: }
408:
409: /** Get the default client-side validation provider. FIXME: read this from some config, or so. */
410: public static ClientsideValidationProvider getClientsideValidationProvider() {
411: return new LiveValidationProvider();
412: }
413: }
|