KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > pentaho > core > system > PentahoSystem


1 /*
2  * Copyright 2006 Pentaho Corporation. All rights reserved.
3  * This software was developed by Pentaho Corporation and is provided under the terms
4  * of the Mozilla Public License, Version 1.1, or any later version. You may not use
5  * this file except in compliance with the license. If you need a copy of the license,
6  * please go to http://www.mozilla.org/MPL/MPL-1.1.txt. The Original Code is the Pentaho
7  * BI Platform. The Initial Developer is Pentaho Corporation.
8  *
9  * Software distributed under the Mozilla Public License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. Please refer to
11  * the license for the specific language governing your rights and limitations.
12  *
13  * @created May 6, 2005
14  * @author James Dixon
15  *
16  */

17
18 package org.pentaho.core.system;
19
20 import java.io.File JavaDoc;
21 import java.io.FileNotFoundException JavaDoc;
22 import java.util.ArrayList JavaDoc;
23 import java.util.Collections JavaDoc;
24 import java.util.HashMap JavaDoc;
25 import java.util.Iterator JavaDoc;
26 import java.util.List JavaDoc;
27 import java.util.Locale JavaDoc;
28 import java.util.Map JavaDoc;
29
30 import org.dom4j.Document;
31 import org.dom4j.DocumentHelper;
32 import org.dom4j.Element;
33 import org.dom4j.Node;
34 import org.pentaho.core.publisher.IPentahoPublisher;
35 import org.pentaho.core.repository.IContentRepository;
36 import org.pentaho.core.repository.IRuntimeRepository;
37 import org.pentaho.core.repository.ISolutionRepository;
38 import org.pentaho.core.runtime.IActionParameter;
39 import org.pentaho.core.runtime.IBackgroundExecution;
40 import org.pentaho.core.runtime.IRuntimeContext;
41 import org.pentaho.core.session.IPentahoSession;
42 import org.pentaho.core.session.StandaloneSession;
43 import org.pentaho.core.solution.HttpSessionParameterProvider;
44 import org.pentaho.core.solution.IParameterProvider;
45 import org.pentaho.core.solution.ISolutionEngine;
46 import org.pentaho.core.solution.SimpleOutputHandler;
47 import org.pentaho.core.solution.SimpleParameterProvider;
48 import org.pentaho.core.ui.IPentahoUrlFactory;
49 import org.pentaho.core.ui.IXMLComponent;
50 import org.pentaho.core.ui.SimpleUrlFactory;
51 import org.pentaho.core.util.IUITemplater;
52 import org.pentaho.messages.Messages;
53 import org.pentaho.messages.util.LocaleHelper;
54 import org.pentaho.util.VersionHelper;
55 import org.pentaho.util.logging.ILogger;
56 import org.pentaho.util.logging.Logger;
57
58 public class PentahoSystem {
59
60     public static final boolean debug = true;
61
62     public static final boolean ignored = false; // used to suppress compiler
63

64     // warnings about unused
65
// parameters.
66

67     public static int loggingLevel = ILogger.ERROR;
68
69     private static IApplicationContext applicationContext;
70
71     protected static final String JavaDoc CONTENT_REPOSITORY = "IContentRepository"; //$NON-NLS-1$
72

73     protected static final String JavaDoc RUNTIME_REPOSITORY = "IRuntimeRepository"; //$NON-NLS-1$
74

75     private static final String JavaDoc SOLUTION_REPOSITORY = "ISolutionRepository"; //$NON-NLS-1$
76

77     protected static final String JavaDoc SOLUTION_ENGINE = "ISolutionEngine"; //$NON-NLS-1$
78

79     public static final String JavaDoc BACKGROUND_EXECUTION = "IBackgroundExecution"; //$NON-NLS-1$
80

81     private static final String JavaDoc SCOPE_GLOBAL = "global"; //$NON-NLS-1$
82

83     protected static final String JavaDoc SCOPE_SESSION = "session"; //$NON-NLS-1$
84

85     protected static final String JavaDoc SCOPE_REQUEST = "request"; //$NON-NLS-1$
86

87     private static Map JavaDoc globalObjectsMap = Collections.synchronizedMap(new HashMap JavaDoc());
88
89     private static HashMap JavaDoc globalAttributes;
90
91     private static SimpleParameterProvider globalParameters;
92
93     private static ISystemSettings systemSettings;
94
95     private static List JavaDoc publishers;
96
97     private static List JavaDoc listeners;
98
99     private static Map JavaDoc scopeMap;
100
101     private static Map JavaDoc classNameMap;
102     
103     private static Map JavaDoc initializationFailureDetailsMap = new HashMap JavaDoc();
104
105     private static HashMap JavaDoc sessionCreateMap;
106
107     private static IRuntimeRepository runtimeRepository;
108     private static IContentRepository contentRepository;
109     
110     
111     public static final int SYSTEM_NOT_INITIALIZED = -1;
112     public static final int SYSTEM_INITIALIZED_OK = 0;
113     public static final int SYSTEM_LISTENERS_FAILED = (int) Math.pow(2, 0); // 1
114
public static final int SYSTEM_OBJECTS_FAILED = (int) Math.pow(2, 1); // 2
115
public static final int SYSTEM_PUBLISHERS_FAILED = (int) Math.pow(2, 2); // 4
116
public static final int SYSTEM_AUDIT_FAILED = (int) Math.pow(2, 3); // 8
117
public static final int SYSTEM_PENTAHOXML_FAILED = (int) Math.pow(2, 4); // 16
118
public static final int SYSTEM_SETTINGS_FAILED = (int) Math.pow(2, 5); // 32
119

120     private static int initializedStatus = SYSTEM_NOT_INITIALIZED;
121     
122     // private static ISolutionRepository solutionRepository;
123

124     // TODO even if logging is not configured messages need to make it out to
125
// the console
126

127     public static synchronized boolean retrySystemInit() {
128       IApplicationContext appContext = applicationContext;
129       publishers.clear();
130       listeners.clear();
131       scopeMap.clear();
132       sessionCreateMap.clear();
133       globalAttributes.clear();
134       globalParameters = null;
135       publishers = null;
136       scopeMap = null;
137       sessionCreateMap = null;
138       globalAttributes = null;
139       return init( appContext );
140     }
141     
142     public static boolean init(IApplicationContext pApplicationContext) {
143             return init( pApplicationContext, null );
144     }
145
146     public static boolean init(IApplicationContext pApplicationContext, Map JavaDoc listenerMap) {
147           initializedStatus = SYSTEM_INITIALIZED_OK;
148         VersionHelper.setVersion(Messages.getString("PentahoSystem.SYSTEM_PLATFORM_VERSION")); //$NON-NLS-1$
149
VersionHelper.setBuild(Messages.getString("PentahoSystem.SYSTEM_PLATFORM_BUILD_NUMBER")); //$NON-NLS-1$
150

151         publishers = new ArrayList JavaDoc();
152         listeners = new ArrayList JavaDoc();
153         scopeMap = new HashMap JavaDoc();
154         classNameMap = new HashMap JavaDoc();
155         sessionCreateMap = new HashMap JavaDoc();
156         globalAttributes = new HashMap JavaDoc();
157         globalParameters = new SimpleParameterProvider(globalAttributes);
158
159         applicationContext = pApplicationContext;
160
161         String JavaDoc propertyPath = applicationContext.getSolutionPath( "" ); //$NON-NLS-1$
162
propertyPath = propertyPath.replaceAll( "\\\\", "/" ); //$NON-NLS-1$ //$NON-NLS-2$
163
System.setProperty( "pentaho.solutionpath", propertyPath ); //$NON-NLS-1$
164

165         if (LocaleHelper.getLocale() == null) {
166             LocaleHelper.setLocale(Locale.getDefault());
167         }
168
169         String JavaDoc systemSettingsPath = applicationContext.getSolutionPath("system"); //$NON-NLS-1$
170
File JavaDoc systemSettingsDir = new File JavaDoc(systemSettingsPath);
171         if (!systemSettingsDir.exists() || !systemSettingsDir.isDirectory()) {
172             // the application context is not configure correctly
173
Logger.error(PentahoSystem.class.getName(), Messages.getString("PentahoSystem.ERROR_0001_SYSTEM_DIRECTORY_INVALID"), new FileNotFoundException JavaDoc(systemSettingsPath)); //$NON-NLS-1$
174
initializedStatus |= SYSTEM_SETTINGS_FAILED;
175             addInitializationFailureMessage(SYSTEM_SETTINGS_FAILED, Messages.getString("PentahoSystem.ERROR_0001_SYSTEM_DIRECTORY_INVALID")); //$NON-NLS-1$
176
}
177
178         // Get the SystemSettings Object
179
try {
180           systemSettings = new SystemSettings(pApplicationContext);
181         } catch (IllegalArgumentException JavaDoc ex) {
182           // If here, then the System Settings document (pentaho.xml)
183
// is not valid XML or cannot be found.
184
initializedStatus |= SYSTEM_PENTAHOXML_FAILED;
185           return false;
186         }
187
188         // Check the audit log class to make sure it's there.
189
String JavaDoc auditClass = systemSettings.getSystemSetting("objects/IAuditEntry", "org.pentaho.core.audit.AuditFileEntry"); //$NON-NLS-1$ //$NON-NLS-2$
190
if (!checkClassExists(auditClass)) {
191           initializedStatus |= SYSTEM_OBJECTS_FAILED | SYSTEM_AUDIT_FAILED;
192           String JavaDoc msg = Messages.getErrorString("PentahoSystem.ERROR_0020_SPECIFIED_CLASS_NOT_FOUND", auditClass); //$NON-NLS-1$
193
Logger.error(PentahoSystem.class.getName(), msg);
194           addInitializationFailureMessage(SYSTEM_OBJECTS_FAILED, msg);
195           return false;
196         }
197         
198         StandaloneSession session = new StandaloneSession("system session"); //$NON-NLS-1$
199
loggingLevel = Logger.getLogLevel(systemSettings.getSystemSetting("log-level", "ERROR")); //$NON-NLS-1$//$NON-NLS-2$
200
Logger.setLogLevel(loggingLevel);
201
202         boolean isOk = true;
203
204         // store a list of the publsihers
205
List JavaDoc publisherNodes = systemSettings.getSystemSettings("publishers/*"); //$NON-NLS-1$
206
if (publisherNodes != null) {
207             Iterator JavaDoc publisherIterator = publisherNodes.iterator();
208             while (publisherIterator.hasNext()) {
209                 String JavaDoc publisherClass = ((Node) publisherIterator.next()).getText();
210                 IPentahoPublisher publisher = (IPentahoPublisher) createObject(publisherClass);
211                 if (publisher != null) {
212                     publishers.add(publisher);
213                 } else {
214                   String JavaDoc msg = Messages.getErrorString("PentahoSystem.ERROR_0010_COULD_NOT_CREATE_PUBLISHER", publisherClass); //$NON-NLS-1$
215
Logger.error(PentahoSystem.class.getName(), msg);
216                     initializedStatus |= SYSTEM_PUBLISHERS_FAILED;
217                     addInitializationFailureMessage(SYSTEM_PUBLISHERS_FAILED, msg);
218                     return false;
219                 }
220             }
221         }
222
223         // store a list of the system listeners
224
List JavaDoc systemListenerNodes = systemSettings.getSystemSettings("system-listeners/*"); //$NON-NLS-1$
225
if (systemListenerNodes != null) {
226             Iterator JavaDoc systemListenerIterator = systemListenerNodes.iterator();
227             isOk = true;
228             while (systemListenerIterator.hasNext()) {
229                     Node listenerNode = (Node) systemListenerIterator.next();
230                 String JavaDoc systemListenerClass = listenerNode.getText();
231                 String JavaDoc listenerName = listenerNode.getName();
232                 if( listenerMap != null && listenerMap.get( listenerName ) == null ) {
233                     continue;
234                 }
235                 IPentahoSystemListener listener = (IPentahoSystemListener) createObject(systemListenerClass);
236                 if (listener != null) {
237                     listeners.add(listener);
238                     try {
239                         isOk = listener.startup(session);
240                         if (!isOk) {
241                           String JavaDoc msg = Messages.getString("PentahoSystem.ERROR_0014_STARTUP_FAILURE", systemListenerClass); //$NON-NLS-1$
242
Logger.error(PentahoSystem.class.getName(), msg);
243                             initializedStatus |= SYSTEM_LISTENERS_FAILED;
244                             addInitializationFailureMessage(SYSTEM_LISTENERS_FAILED, msg);
245                             return false;
246                         }
247                     } catch (Throwable JavaDoc e) {
248                       String JavaDoc msg = Messages.getString("PentahoSystem.ERROR_0014_STARTUP_FAILURE", systemListenerClass); //$NON-NLS-1$
249
Logger.error(PentahoSystem.class.getName(), msg, e);
250                         initializedStatus |= SYSTEM_LISTENERS_FAILED;
251                         addInitializationFailureMessage(SYSTEM_LISTENERS_FAILED, msg);
252                         return false;
253                     }
254                 } else {
255                   String JavaDoc msg = Messages.getErrorString("PentahoSystem.ERROR_0011_COULD_NOT_CREATE_LISTENER", systemListenerClass); //$NON-NLS-1$
256
Logger.error(PentahoSystem.class.getName(), msg);
257                     initializedStatus |= SYSTEM_LISTENERS_FAILED;
258                     addInitializationFailureMessage(SYSTEM_LISTENERS_FAILED, msg);
259                     return false;
260                 }
261             }
262         }
263
264         // get the list of session creation actions
265
// TODO need to specify if authentication is optional
266
List JavaDoc sessionCreateClasses = systemSettings.getSystemSettings("system-actions/*"); //$NON-NLS-1$
267
if (sessionCreateClasses != null) {
268             Iterator JavaDoc sessionCreateIterator = sessionCreateClasses.iterator();
269             while (sessionCreateIterator.hasNext()) {
270                 Node sessionActionNode = (Node) sessionCreateIterator.next();
271
272                 String JavaDoc sessionCreateClass = sessionActionNode.getName();
273                 String JavaDoc scope = sessionActionNode.selectSingleNode("@scope").getText(); //$NON-NLS-1$
274
String JavaDoc actionName = sessionActionNode.getText();
275                 List JavaDoc sessionActionList = (List JavaDoc) sessionCreateMap.get(sessionCreateClass);
276                 if (sessionActionList == null) {
277                     sessionActionList = new ArrayList JavaDoc();
278                     sessionCreateMap.put(sessionCreateClass, sessionActionList);
279                     // Force the actions to also be available from sub-action execution and from
280
// background execution.
281
sessionCreateMap.put("org.pentaho.core.session.UserSession", sessionActionList); //$NON-NLS-1$
282
}
283                 sessionActionList.add(new String JavaDoc[] { scope, actionName });
284             }
285         }
286
287         return true;
288     }
289     
290     public static boolean getInitializedOK() {
291       return initializedStatus == SYSTEM_INITIALIZED_OK;
292     }
293
294     public static int getInitializedStatus() {
295       return initializedStatus;
296     }
297
298     private static List JavaDoc getAdditionalInitializationFailureMessages(int failureBit) {
299       List JavaDoc l = (List JavaDoc)initializationFailureDetailsMap.get(new Integer JavaDoc(failureBit));
300       return l;
301     }
302     
303     public static List JavaDoc getInitializationFailureMessages() {
304       List JavaDoc rtn = new ArrayList JavaDoc();
305       if (hasFailed(SYSTEM_SETTINGS_FAILED)) {
306         rtn.add(Messages.getString("PentahoSystem.USER_INITIALIZATION_SYSTEM_SETTINGS_FAILED"));//$NON-NLS-1$
307
List JavaDoc l = getAdditionalInitializationFailureMessages(SYSTEM_SETTINGS_FAILED);
308         if (l!=null) {
309           rtn.addAll(l);
310         }
311       }
312       if (hasFailed(SYSTEM_PUBLISHERS_FAILED)) {
313         rtn.add(Messages.getString("PentahoSystem.USER_INITIALIZATION_SYSTEM_PUBLISHERS_FAILED"));//$NON-NLS-1$
314
List JavaDoc l = getAdditionalInitializationFailureMessages(SYSTEM_PUBLISHERS_FAILED);
315         if (l!=null) {
316           rtn.addAll(l);
317         }
318       }
319       if (hasFailed(SYSTEM_OBJECTS_FAILED)) {
320         rtn.add(Messages.getString("PentahoSystem.USER_INITIALIZATION_SYSTEM_OBJECTS_FAILED"));//$NON-NLS-1$
321
List JavaDoc l = getAdditionalInitializationFailureMessages(SYSTEM_OBJECTS_FAILED);
322         if (l!=null) {
323           rtn.addAll(l);
324         }
325       }
326       if (hasFailed(SYSTEM_AUDIT_FAILED)) {
327         rtn.add(Messages.getString("PentahoSystem.USER_INITIALIZATION_SYSTEM_AUDIT_FAILED"));//$NON-NLS-1$
328
List JavaDoc l = getAdditionalInitializationFailureMessages(SYSTEM_AUDIT_FAILED);
329         if (l!=null) {
330           rtn.addAll(l);
331         }
332       }
333       if (hasFailed(SYSTEM_LISTENERS_FAILED)) {
334         rtn.add(Messages.getString("PentahoSystem.USER_INITIALIZATION_SYSTEM_LISTENERS_FAILED"));//$NON-NLS-1$
335
List JavaDoc l = getAdditionalInitializationFailureMessages(SYSTEM_LISTENERS_FAILED);
336         if (l!=null) {
337           rtn.addAll(l);
338         }
339       }
340       if (hasFailed(SYSTEM_PENTAHOXML_FAILED)) {
341         rtn.add(Messages.getString("PentahoSystem.USER_INITIALIZATION_SYSTEM_PENTAHOXML_FAILED"));//$NON-NLS-1$
342
List JavaDoc l = getAdditionalInitializationFailureMessages(SYSTEM_PENTAHOXML_FAILED);
343         if (l!=null) {
344           rtn.addAll(l);
345         }
346       }
347       return rtn;
348     }
349     
350     public static synchronized void addInitializationFailureMessage(int failureBit, String JavaDoc message) {
351       Integer JavaDoc i = new Integer JavaDoc(failureBit);
352       List JavaDoc l = (List JavaDoc)initializationFailureDetailsMap.get(i);
353       if (l == null) {
354         l=new ArrayList JavaDoc();
355         initializationFailureDetailsMap.put(i, l);
356       }
357       l.add("   " + message);//$NON-NLS-1$
358
}
359     
360     private static final boolean hasFailed(int errorToCheck) {
361       return ( (initializedStatus & errorToCheck) == errorToCheck);
362     }
363     
364     protected static boolean checkClassExists(String JavaDoc className) {
365       try {
366         Class.forName(className);
367         return true;
368       } catch (Throwable JavaDoc t) { }
369       return false;
370     }
371     
372     public static boolean loadStartupObject(IPentahoSession session, String JavaDoc objectName, boolean required ) {
373             String JavaDoc scope;
374             String JavaDoc objectClass = PentahoSystem.getSystemSetting( "objects/"+objectName, null ); //$NON-NLS-1$
375
scope = PentahoSystem.getSystemSetting( "objects/"+objectName+"/@scope", null ); //$NON-NLS-1$ //$NON-NLS-2$
376
if( debug ) Logger.debug( PentahoSystem.class.getName(), Messages.getString("PentahoSystem.DEBUG_CLASS_INFO",objectName,objectClass,scope )); //$NON-NLS-1$
377
if( objectClass == null ) {
378               if (required) {
379                 Logger.error( PentahoSystem.class.getName(), Messages.getErrorString("PentahoSystem.ERROR_0021_OBJECT_NOT_SPECIFIED", objectName) ); //$NON-NLS-1$
380
return false;
381               } else {
382                 Logger.warn( PentahoSystem.class.getName(), Messages.getString("PentahoSystem.ERROR_0021_OBJECT_NOT_SPECIFIED", objectName) ); //$NON-NLS-1$
383
return true;
384               }
385             }
386             if( scope == null ) {
387               Logger.warn( PentahoSystem.class.getName(), Messages.getString("PentahoSystem.WARNING_OBJECT_SCOPE_MISSING", objectName) ); //$NON-NLS-1$
388
scope = SCOPE_SESSION;
389             }
390             classNameMap.put( objectName, objectClass );
391             scopeMap.put( objectName, scope );
392             if( SCOPE_GLOBAL.equals( scope ) ) {
393               try {
394                 Object JavaDoc obj = PentahoSystem.createObject( objectClass );
395                 if( obj == null ) {
396                   Logger.error( PentahoSystem.class.getName(), Messages.getErrorString("PentahoSystem.ERROR_0022_COULD_NOT_CREATE_OBJECT", objectName) ); //$NON-NLS-1$
397
return false;
398                 } else {
399                   globalObjectsMap.put(objectName, obj);
400                 }
401                 if (obj instanceof IPentahoInitializer) {
402                   ((IPentahoInitializer)obj).init( session );
403                 }
404                 
405               } catch ( ClassCastException JavaDoc e ) {
406                 // TODO surface this error
407
e.printStackTrace();
408               } catch ( Throwable JavaDoc t ) {
409                 // TODO surface this error
410
t.printStackTrace();
411                 
412               }
413             }
414
415             return true;
416           }
417     
418     public static IUITemplater getUITemplater( IPentahoSession session ) {
419             Object JavaDoc obj = getObject( session, "IUITemplater" ); //$NON-NLS-1$
420
return (IUITemplater) obj;
421     }
422
423     public static IBackgroundExecution getBackgroundExecutionHandler( IPentahoSession session ) {
424       Object JavaDoc obj = getObject( session, BACKGROUND_EXECUTION );
425       return (IBackgroundExecution)obj;
426     }
427     
428     public static IXMLComponent getUserFilesComponent( IPentahoSession session ) {
429           Object JavaDoc obj = getObject( session, "IUserFilesComponent" ); //$NON-NLS-1$
430
return (IXMLComponent) obj;
431     }
432     
433     public static Object JavaDoc getObject( IPentahoSession session, String JavaDoc objectName ) {
434 /* if( scopeMap == null ) {
435           // we were not initialized
436           Logger.error( PentahoSystem.class.getName(), ProMessages.getErrorString("ProPentahoSystem.ERROR_0003_PRO_PENTAHO_SYSTEM_NOT_INITIALIZED") ); //$NON-NLS-1$
437           return null;
438         }
439 */
String JavaDoc scope = (String JavaDoc) scopeMap.get( objectName );
440
441         if( SCOPE_GLOBAL.equalsIgnoreCase( scope ) ) {
442           Object JavaDoc rtn = globalObjectsMap.get(objectName);
443           if (rtn instanceof IPentahoInitializer) {
444             ((IPentahoInitializer)rtn).init(session);
445           }
446           return rtn;
447         } else if( SCOPE_SESSION.equalsIgnoreCase( scope ) ) {
448           Object JavaDoc attribute = session.getAttribute( objectName );
449           
450           if( (attribute != null) ) {
451             // Set the session which is a threadlocal...
452
if (attribute instanceof IPentahoInitializer) {
453               ((IPentahoInitializer)attribute).init( session );
454             }
455             return attribute;
456           }
457           String JavaDoc clazz = (String JavaDoc) classNameMap.get( objectName );
458           attribute = PentahoSystem.createObject( clazz );
459           if (attribute instanceof IPentahoInitializer) {
460             ((IPentahoInitializer)attribute).init( session );
461           }
462           session.setAttribute( objectName, attribute );
463           return attribute;
464         }
465         Logger.error( PentahoSystem.class.getName(), Messages.getErrorString("PentahoSystem.ERROR_0023_COULD_NOT_RETURN_OBJECT", objectName, scope) ); //$NON-NLS-1$
466
return null;
467         
468       }
469     
470     protected static boolean initGlobalObjects(IPentahoSession session) {
471         String JavaDoc solutionEngineClass = systemSettings.getSystemSetting("objects/ISolutionEngine", null); //$NON-NLS-1$
472
String JavaDoc scope = systemSettings.getSystemSetting("objects/ISolutionEngine/@scope", null); //$NON-NLS-1$
473
if (debug)
474             Logger.debug(PentahoSystem.class.getName(), Messages.getString("PentahoSystem.DEBUG_SOLUTION_ENGINE_CLASS", solutionEngineClass, scope)); //$NON-NLS-1$
475
if (solutionEngineClass == null) {
476           String JavaDoc msg = Messages.getErrorString("PentahoSystem.ERROR_0002_SOLUTION_ENGINE_NOT_SPECIFIED"); //$NON-NLS-1$
477
Logger.error(PentahoSystem.class.getName(), msg);
478             initializedStatus |= SYSTEM_OBJECTS_FAILED;
479             addInitializationFailureMessage(SYSTEM_OBJECTS_FAILED, msg);
480             return false;
481         }
482         if (scope == null) {
483             Logger.warn(PentahoSystem.class.getName(), Messages.getString("PentahoSystem.WARNING_SOLUTION_ENGINE_SCOPE_MISSING")); //$NON-NLS-1$
484
scope = SCOPE_REQUEST;
485         }
486         classNameMap.put(SOLUTION_ENGINE, solutionEngineClass);
487         scopeMap.put(SOLUTION_ENGINE, scope);
488         if (SCOPE_GLOBAL.equals(scope)) {
489           ISolutionEngine obj = (ISolutionEngine) createObject(solutionEngineClass);
490             if (obj == null) {
491               String JavaDoc msg = Messages.getErrorString("PentahoSystem.ERROR_0003_COULD_NOT_CREATE_SOLUTION_ENGINE"); //$NON-NLS-1$
492
Logger.error(PentahoSystem.class.getName(), msg);
493                 initializedStatus |= SYSTEM_OBJECTS_FAILED;
494                 addInitializationFailureMessage(SYSTEM_OBJECTS_FAILED, msg);
495                 return false;
496             } else {
497                 globalObjectsMap.put(SOLUTION_ENGINE, obj);
498             }
499         } else {
500           if (!checkClassExists(solutionEngineClass)) {
501             String JavaDoc msg = Messages.getErrorString("PentahoSystem.ERROR_0020_SPECIFIED_CLASS_NOT_FOUND", solutionEngineClass); //$NON-NLS-1$
502
Logger.error(PentahoSystem.class.getName(), msg);
503             initializedStatus |= SYSTEM_OBJECTS_FAILED;
504             addInitializationFailureMessage(SYSTEM_OBJECTS_FAILED, msg);
505             return false;
506           }
507         }
508
509         String JavaDoc solutionRepositoryClass = systemSettings.getSystemSetting("objects/ISolutionRepository", null); //$NON-NLS-1$
510
scope = systemSettings.getSystemSetting("objects/ISolutionRepository/@scope", null); //$NON-NLS-1$
511
if (debug)
512             Logger.debug(PentahoSystem.class.getName(), Messages.getString("PentahoSystem.DEBUG_SOLUTION_REPOSITORY_CLASS", solutionRepositoryClass, scope)); //$NON-NLS-1$
513
if (solutionRepositoryClass == null) {
514           String JavaDoc msg = Messages.getErrorString("PentahoSystem.ERROR_0004_SOLUTION_REPOSITORY_NOT_SPECIFIED"); //$NON-NLS-1$
515
Logger.error(PentahoSystem.class.getName(), msg);
516             initializedStatus |= SYSTEM_OBJECTS_FAILED;
517             addInitializationFailureMessage(SYSTEM_OBJECTS_FAILED, msg);
518             return false;
519         }
520         if (scope == null) {
521             Logger.warn(PentahoSystem.class.getName(), Messages.getString("PentahoSystem.WARNING_SOLUTION_REPOSITORY_SCOPE_MISSING")); //$NON-NLS-1$
522
scope = SCOPE_SESSION;
523         }
524         classNameMap.put(SOLUTION_REPOSITORY, solutionRepositoryClass);
525         scopeMap.put(SOLUTION_REPOSITORY, scope);
526         if (SCOPE_GLOBAL.equals(scope)) {
527           ISolutionRepository obj = (ISolutionRepository) createObject(solutionRepositoryClass);
528             if (obj == null) {
529               String JavaDoc msg = Messages.getErrorString("PentahoSystem.ERROR_0005_COULD_NOT_CREATE_SOLUTION_REPOSITORY"); //$NON-NLS-1$
530
Logger.error(PentahoSystem.class.getName(), msg);
531                 initializedStatus |= SYSTEM_OBJECTS_FAILED;
532                 addInitializationFailureMessage(SYSTEM_OBJECTS_FAILED, msg);
533                 return false;
534             } else {
535                 globalObjectsMap.put(SOLUTION_REPOSITORY, obj);
536             }
537             obj.init(session);
538             obj.setLoggingLevel(loggingLevel);
539         } else {
540           if (!checkClassExists(solutionRepositoryClass)) {
541             String JavaDoc msg = Messages.getErrorString("PentahoSystem.ERROR_0020_SPECIFIED_CLASS_NOT_FOUND", solutionRepositoryClass); //$NON-NLS-1$
542
Logger.error(PentahoSystem.class.getName(), msg);
543             initializedStatus |= SYSTEM_OBJECTS_FAILED;
544             addInitializationFailureMessage(SYSTEM_OBJECTS_FAILED, msg);
545             return false;
546           }
547         }
548
549
550         String JavaDoc runtimeRepositoryClass = systemSettings.getSystemSetting("objects/IRuntimeRepository", null); //$NON-NLS-1$
551
scope = systemSettings.getSystemSetting("objects/IRuntimeRepository/@scope", null); //$NON-NLS-1$
552
if (debug)
553             Logger.debug(PentahoSystem.class.getName(), Messages.getString("PentahoSystem.DEBUG_RUNTIME_REPOSITORY_CLASS", runtimeRepositoryClass, scope)); //$NON-NLS-1$
554
if (runtimeRepositoryClass == null) {
555           String JavaDoc msg = Messages.getErrorString("PentahoSystem.ERROR_0006_RUNTIME_REPOSITORY_NOT_SPECIFIED"); //$NON-NLS-1$
556
Logger.error(PentahoSystem.class.getName(), msg);
557             initializedStatus |= SYSTEM_OBJECTS_FAILED;
558             addInitializationFailureMessage(SYSTEM_OBJECTS_FAILED, msg);
559             return false;
560         }
561
562         if (scope == null) {
563             Logger.warn(PentahoSystem.class.getName(), Messages.getString("PentahoSystem.WARNING_RUNTIME_REPOSITORY_SCOPE_MISSING")); //$NON-NLS-1$
564
scope = SCOPE_SESSION;
565         }
566
567         classNameMap.put(RUNTIME_REPOSITORY, runtimeRepositoryClass);
568         scopeMap.put(RUNTIME_REPOSITORY, scope);
569         if (SCOPE_GLOBAL.equals(scope)) {
570           IRuntimeRepository obj = (IRuntimeRepository) createObject(runtimeRepositoryClass);
571             if (obj == null) {
572               String JavaDoc msg = Messages.getErrorString("PentahoSystem.ERROR_0007_COULD_NOT_CREATE_RUNTIME_REPOSITORY"); //$NON-NLS-1$
573
Logger.error(PentahoSystem.class.getName(), msg);
574                 initializedStatus |= SYSTEM_OBJECTS_FAILED;
575                 addInitializationFailureMessage(SYSTEM_OBJECTS_FAILED, msg);
576                 return false;
577             } else {
578                 globalObjectsMap.put(RUNTIME_REPOSITORY, obj);
579                 obj.setSession(session);
580                 runtimeRepository = obj;
581             }
582         } else {
583           if (!checkClassExists(runtimeRepositoryClass)) {
584             String JavaDoc msg = Messages.getErrorString("PentahoSystem.ERROR_0020_SPECIFIED_CLASS_NOT_FOUND", runtimeRepositoryClass); //$NON-NLS-1$
585
initializedStatus |= SYSTEM_OBJECTS_FAILED;
586             Logger.error(PentahoSystem.class.getName(), msg);
587             addInitializationFailureMessage(SYSTEM_OBJECTS_FAILED, msg);
588             return false;
589           }
590         }
591
592         String JavaDoc contentRepositoryClass = systemSettings.getSystemSetting("objects/IContentRepository", null); //$NON-NLS-1$
593
scope = systemSettings.getSystemSetting("objects/IContentRepository/@scope", null); //$NON-NLS-1$
594
if (debug)
595             Logger.debug(PentahoSystem.class.getName(), Messages.getString("PentahoSystem.DEBUG_CONTENT_REPOSITORY_CLASS", contentRepositoryClass, scope)); //$NON-NLS-1$
596
if (contentRepositoryClass == null) {
597             Logger.warn(PentahoSystem.class.getName(), Messages.getErrorString("PentahoSystem.ERROR_0008_CONTENT_REPOSITORY_NOT_SPECIFIED")); //$NON-NLS-1$
598
} else {
599             if (scope == null) {
600                 Logger.warn(PentahoSystem.class.getName(), Messages.getString("PentahoSystem.WARNING_CONTENT_REPOSITORY_SCOPE_MISSING")); //$NON-NLS-1$
601
scope = SCOPE_SESSION;
602             }
603             classNameMap.put(CONTENT_REPOSITORY, contentRepositoryClass);
604             scopeMap.put(CONTENT_REPOSITORY, scope);
605             if (SCOPE_GLOBAL.equals(scope)) {
606               IContentRepository obj = (IContentRepository) createObject(contentRepositoryClass);
607                 if (obj == null) {
608                   String JavaDoc msg = Messages.getErrorString("PentahoSystem.ERROR_0009_COULD_NOT_CREATE_CONTENT_REPOSITORY"); //$NON-NLS-1$
609
Logger.error(PentahoSystem.class.getName(), msg);
610                     initializedStatus |= SYSTEM_OBJECTS_FAILED;
611                     addInitializationFailureMessage(SYSTEM_OBJECTS_FAILED, msg);
612                     return false;
613                 }
614                 globalObjectsMap.put(CONTENT_REPOSITORY, obj);
615                 obj.setSession(session);
616                 if( contentRepository == null ) {
617                     contentRepository = obj;
618                 }
619                 
620             } else {
621               if (!checkClassExists(contentRepositoryClass)) {
622                 String JavaDoc msg = Messages.getErrorString("PentahoSystem.ERROR_0020_SPECIFIED_CLASS_NOT_FOUND", contentRepositoryClass); //$NON-NLS-1$
623
initializedStatus |= SYSTEM_OBJECTS_FAILED;
624                 Logger.error(PentahoSystem.class.getName(), msg);
625                 addInitializationFailureMessage(SYSTEM_OBJECTS_FAILED, msg);
626                 return false;
627               }
628             }
629         }
630         loadStartupObject( session, "IUITemplater", false ); //$NON-NLS-1$
631
loadStartupObject( session, "IUserFilesComponent", false ); //$NON-NLS-1$
632
loadStartupObject( session, BACKGROUND_EXECUTION, false);
633         sessionStartup(session, false);
634         return true;
635     }
636
637     public static String JavaDoc getSystemName() {
638         return Messages.getString("PentahoSystem.USER_SYSTEM_TITLE"); //$NON-NLS-1$;
639
}
640
641     public static List JavaDoc getSessionCreateActions(String JavaDoc className) {
642         List JavaDoc sessionCreateActions = (List JavaDoc) sessionCreateMap.get(className);
643         return sessionCreateActions;
644     }
645
646     public static IParameterProvider getGlobalParameters() {
647         return globalParameters;
648     }
649
650     public static void sessionStartup(IPentahoSession session) {
651         sessionStartup(session, true);
652     }
653
654     public static void clearGlobals() {
655         globalAttributes.clear();
656     }
657
658     public static void sessionStartup(IPentahoSession session, boolean doSession) {
659         List JavaDoc actions = getSessionCreateActions(session.getClass().getName());
660         if (actions == null) {
661             // nothing to do...
662
return;
663         }
664
665         if (!session.isAuthenticated() && doSession) {
666             return;
667         }
668         boolean doGlobals = globalAttributes.size() == 0;
669         // TODO this needs more validation
670
Iterator JavaDoc actionsIterator = actions.iterator();
671         while (actionsIterator.hasNext()) {
672             String JavaDoc tmp[] = (String JavaDoc[]) actionsIterator.next();
673             String JavaDoc scope = tmp[0];
674             if ("global".equals(scope) && !doGlobals) { //$NON-NLS-1$
675
// see if this has been done already
676
continue;
677             } else if ("session".equals(scope) && !doSession) { //$NON-NLS-1$
678
continue;
679             }
680             String JavaDoc actionStr = tmp[1];
681             // parse the actionStr out to identify an action
682
String JavaDoc actionInfo[] = parseActionString(actionStr);
683             if (actionInfo != null && actionInfo.length == 3) {
684                 String JavaDoc solutionId = actionInfo[0];
685                 String JavaDoc path = actionInfo[1];
686                 String JavaDoc actionName = actionInfo[2];
687                 // now execute the action...
688

689                 SimpleOutputHandler outputHandler = null;
690
691                 String JavaDoc instanceId = null;
692
693                 ISolutionEngine solutionEngine = PentahoSystem.getSolutionEngineInstance(session);
694                 solutionEngine.setLoggingLevel(loggingLevel);
695                 solutionEngine.init(session);
696
697                 String JavaDoc baseUrl = ""; //$NON-NLS-1$
698
HashMap JavaDoc parameterProviderMap = new HashMap JavaDoc();
699                 HttpSessionParameterProvider sessionParameters = new HttpSessionParameterProvider(session);
700                 parameterProviderMap.put("session", sessionParameters); //$NON-NLS-1$
701

702                 IPentahoUrlFactory urlFactory = new SimpleUrlFactory(baseUrl);
703
704                 ArrayList JavaDoc messages = new ArrayList JavaDoc();
705
706                 IRuntimeContext context = null;
707                 try {
708                     context = solutionEngine.execute(solutionId, path, actionName, "Session startup actions", false, true, instanceId, false, parameterProviderMap, outputHandler, null, urlFactory, messages); //$NON-NLS-1$
709

710                     if (context.getStatus() == IRuntimeContext.RUNTIME_STATUS_SUCCESS) {
711                         // now grab any outputs
712
Iterator JavaDoc outputIterator = context.getOutputNames().iterator();
713                         while (outputIterator.hasNext()) {
714                             IActionParameter output = context.getOutputParameter((String JavaDoc) outputIterator.next());
715                             String JavaDoc attributeName = output.getName();
716                             Object JavaDoc data = output.getValue();
717                             if (data != null) {
718                                 if ("session".equals(scope)) { //$NON-NLS-1$
719
session.removeAttribute(attributeName);
720                                     session.setAttribute(attributeName, data);
721                                 } else if ("global".equals(scope)) { //$NON-NLS-1$
722
globalAttributes.remove(attributeName);
723                                     globalAttributes.put(attributeName, data);
724                                 }
725
726                             }
727                         }
728                     }
729                 } finally {
730                     if (context != null) {
731                         context.dispose();
732                     }
733                 }
734
735             } else {
736                 Logger.error(PentahoSystem.class.getName(), Messages.getString("PentahoSystem.ERROR_0016_COULD_NOT_PARSE_ACTION", actionStr)); //$NON-NLS-1$
737
}
738
739         }
740     }
741
742     public static String JavaDoc[] parseActionString(String JavaDoc actionString) {
743         // parse a string in this format samples/reporting/JFR/report.xml into
744
// the solution, path, and document name
745
if (actionString == null) {
746             return null;
747         }
748
749         // first normalize the path separators
750
actionString = actionString.replace('\\', '/');
751
752         // remove a leading '/'
753
if (actionString.charAt(0) == '/') {
754             actionString = actionString.substring(1);
755         }
756
757         String JavaDoc solution;
758         String JavaDoc path = ""; //$NON-NLS-1$
759
String JavaDoc name;
760         int idx1 = actionString.indexOf('/');
761         int idx2 = actionString.lastIndexOf('/');
762         if (idx1 == -1) {
763             // this is not a valid action String
764
return null;
765         }
766         solution = actionString.substring(0, idx1);
767         name = actionString.substring(idx2 + 1);
768         if (idx2 > idx1) {
769             path = actionString.substring(idx1 + 1, idx2);
770         }
771         return new String JavaDoc[] { solution, path, name };
772     }
773
774     public static void shutdown() {
775         if (LocaleHelper.getLocale() == null) {
776             LocaleHelper.setLocale(Locale.getDefault());
777         }
778         Iterator JavaDoc systemListenerIterator = listeners.iterator();
779         while (systemListenerIterator.hasNext()) {
780             IPentahoSystemListener listener = (IPentahoSystemListener) systemListenerIterator.next();
781             if (listener != null) {
782                 try {
783                     listener.shutdown();
784                 } catch (Throwable JavaDoc e) {
785                     Logger.error(PentahoSystem.class.getName(), Messages.getString("PentahoSystem.ERROR_0015_SHUTDOWN_FAILURE") + listener.getClass().getName(), e); //$NON-NLS-1$
786
}
787             }
788         }
789     }
790
791     public static IApplicationContext getApplicationContext() {
792         return applicationContext;
793     }
794
795     public static ISolutionEngine getSolutionEngineInstance(IPentahoSession session) {
796         // TODO support session and solution and request based scopes
797
String JavaDoc scope = (String JavaDoc) scopeMap.get(SOLUTION_ENGINE);
798         if (SCOPE_GLOBAL.equalsIgnoreCase(scope)) {
799             return (ISolutionEngine) globalObjectsMap.get(SOLUTION_ENGINE);
800         }
801         else if (SCOPE_SESSION.equalsIgnoreCase(scope)) {
802             if( session == null ) {
803                 Logger.error(PentahoSystem.class.getName(), Messages.getErrorString("PentahoSystem.ERROR_0003_COULD_NOT_CREATE_SOLUTION_ENGINE")); //$NON-NLS-1$
804
return null;
805             }
806             Object JavaDoc attribute = session.getAttribute(SOLUTION_ENGINE);
807             if ((attribute != null) && (attribute instanceof ISolutionEngine)) {
808                 // Set the session which is a threadlocal...
809
ISolutionEngine solutionEngine = (ISolutionEngine) attribute;
810                 return solutionEngine;
811             }
812             String JavaDoc solutionEngineClass = (String JavaDoc) classNameMap.get(SOLUTION_ENGINE);
813             Object JavaDoc obj = createObject(solutionEngineClass);
814             if ( obj == null || !(obj instanceof ISolutionEngine ) ) {
815                 Logger.error(PentahoSystem.class.getName(), Messages.getErrorString("PentahoSystem.ERROR_0003_COULD_NOT_CREATE_SOLUTION_ENGINE")); //$NON-NLS-1$
816
return null;
817             }
818             ISolutionEngine solutionEngine = (ISolutionEngine) obj;
819             session.setAttribute(SOLUTION_ENGINE, solutionEngine);
820             return solutionEngine;
821         }
822         else if (SCOPE_REQUEST.equalsIgnoreCase(scope)) {
823             if( session == null ) {
824                 Logger.error(PentahoSystem.class.getName(), Messages.getErrorString("PentahoSystem.ERROR_0003_COULD_NOT_CREATE_SOLUTION_ENGINE")); //$NON-NLS-1$
825
return null;
826             }
827             String JavaDoc solutionEngineClass = (String JavaDoc) classNameMap.get(SOLUTION_ENGINE);
828             Object JavaDoc obj = createObject(solutionEngineClass);
829             if ( obj == null || !(obj instanceof ISolutionEngine ) ) {
830                 Logger.error(PentahoSystem.class.getName(), Messages.getErrorString("PentahoSystem.ERROR_0003_COULD_NOT_CREATE_SOLUTION_ENGINE")); //$NON-NLS-1$
831
return null;
832             }
833             ISolutionEngine solutionEngine = (ISolutionEngine) obj;
834             return solutionEngine;
835         }
836
837         return null;
838     }
839
840     public static IContentRepository getContentRepository(IPentahoSession session) {
841         String JavaDoc scope = (String JavaDoc) scopeMap.get(CONTENT_REPOSITORY);
842         if (SCOPE_GLOBAL.equalsIgnoreCase(scope)) {
843             return (IContentRepository) globalObjectsMap.get(CONTENT_REPOSITORY);
844         } else if (SCOPE_SESSION.equalsIgnoreCase(scope)) {
845             if( session == null ) {
846                 Logger.error(PentahoSystem.class.getName(), Messages.getErrorString("PentahoSystem.ERROR_0009_COULD_NOT_CREATE_CONTENT_REPOSITORY")); //$NON-NLS-1$
847
return null;
848             }
849             Object JavaDoc attribute = null;
850             try {
851                 attribute = session.getAttribute(CONTENT_REPOSITORY);
852             } catch (Throwable JavaDoc t) {
853                 session.error(Messages.getErrorString("PentahoSystem.ERROR_0012_COULD_NOT_GET_CONTENT_REPOSITORY")); //$NON-NLS-1$
854
}
855             if ((attribute != null) && (attribute instanceof IContentRepository)) {
856                 // Set the session which is a threadlocal...
857
IContentRepository repository = (IContentRepository) attribute;
858                 repository.setSession(session);
859                 if( contentRepository == null ) {
860                     contentRepository = repository;
861                 }
862                 return repository;
863             }
864             String JavaDoc contentRepositoryClass = (String JavaDoc) classNameMap.get(CONTENT_REPOSITORY);
865             Object JavaDoc obj = createObject(contentRepositoryClass);
866             if ( obj == null || !(obj instanceof IContentRepository ) ) {
867                 Logger.error(PentahoSystem.class.getName(), Messages.getErrorString("PentahoSystem.ERROR_0009_COULD_NOT_CREATE_CONTENT_REPOSITORY")); //$NON-NLS-1$
868
return null;
869             }
870             IContentRepository repository = (IContentRepository) obj;
871             repository.setSession(session);
872             session.setAttribute(CONTENT_REPOSITORY, repository);
873             if( contentRepository == null ) {
874                 contentRepository = repository;
875             }
876             return repository;
877         }
878         return null;
879     }
880
881     public static ISolutionRepository getSolutionRepository(IPentahoSession session) {
882         String JavaDoc scope = (String JavaDoc) scopeMap.get(SOLUTION_REPOSITORY);
883
884         // TODO support local-scoped solution repository
885

886         if (SCOPE_GLOBAL.equalsIgnoreCase(scope)) {
887             return (ISolutionRepository) globalObjectsMap.get(SOLUTION_REPOSITORY);
888         } else if (SCOPE_SESSION.equalsIgnoreCase(scope)) {
889             if( session == null ) {
890                 Logger.error(PentahoSystem.class.getName(), Messages.getErrorString("PentahoSystem.ERROR_0005_COULD_NOT_CREATE_SOLUTION_REPOSITORY")); //$NON-NLS-1$
891
return null;
892             }
893             Object JavaDoc attribute = session.getAttribute(SOLUTION_REPOSITORY);
894             if ((attribute != null) && (attribute instanceof ISolutionRepository)) {
895                 // Set the session which is a threadlocal...
896
ISolutionRepository aSolutionRepository = (ISolutionRepository) attribute;
897                 aSolutionRepository.setLocale(LocaleHelper.getLocale());
898                 aSolutionRepository.init(session);
899                 aSolutionRepository.setLoggingLevel(loggingLevel);
900                 return aSolutionRepository;
901             }
902             String JavaDoc solutionRepositoryClass = (String JavaDoc) classNameMap.get(SOLUTION_REPOSITORY);
903             Object JavaDoc obj = createObject(solutionRepositoryClass);
904             if ( obj == null || !(obj instanceof ISolutionRepository ) ) {
905                 Logger.error(PentahoSystem.class.getName(), Messages.getErrorString("PentahoSystem.ERROR_0005_COULD_NOT_CREATE_SOLUTION_REPOSITORY")); //$NON-NLS-1$
906
return null;
907             }
908             ISolutionRepository aSolutionRepository = (ISolutionRepository) obj;
909             aSolutionRepository.init(session);
910             aSolutionRepository.setLoggingLevel(loggingLevel);
911             session.setAttribute(SOLUTION_REPOSITORY, aSolutionRepository);
912             return aSolutionRepository;
913         }
914         return null;
915     }
916
917     public static IRuntimeRepository getRuntimeRepository(IPentahoSession session) {
918         String JavaDoc scope = (String JavaDoc) scopeMap.get(RUNTIME_REPOSITORY);
919         if (SCOPE_GLOBAL.equalsIgnoreCase(scope)) {
920             return (IRuntimeRepository) globalObjectsMap.get(RUNTIME_REPOSITORY);
921         }
922         else if (SCOPE_SESSION.equalsIgnoreCase(scope)) {
923             if( session == null ) {
924                 Logger.error(PentahoSystem.class.getName(), Messages.getErrorString("PentahoSystem.ERROR_0007_COULD_NOT_CREATE_RUNTIME_REPOSITORY")); //$NON-NLS-1$
925
return null;
926             }
927             Object JavaDoc attribute = session.getAttribute(RUNTIME_REPOSITORY);
928             if ((attribute != null) && (attribute instanceof IRuntimeRepository)) {
929                 // Set the session which is a threadlocal...
930
IRuntimeRepository repository = (IRuntimeRepository) attribute;
931                 repository.setSession(session);
932                 if( runtimeRepository == null ) {
933                     runtimeRepository = repository;
934                 }
935                 return repository;
936             }
937             String JavaDoc runtimeRepositoryClass = (String JavaDoc) classNameMap.get(RUNTIME_REPOSITORY);
938             Object JavaDoc obj = createObject(runtimeRepositoryClass);
939             if ( obj == null || !(obj instanceof IRuntimeRepository ) ) {
940                 Logger.error(PentahoSystem.class.getName(), Messages.getErrorString("PentahoSystem.ERROR_0007_COULD_NOT_CREATE_RUNTIME_REPOSITORY")); //$NON-NLS-1$
941
return null;
942             }
943             IRuntimeRepository repository = (IRuntimeRepository) obj;
944             repository.setSession(session);
945             session.setAttribute(RUNTIME_REPOSITORY, repository);
946             if( runtimeRepository == null ) {
947                 runtimeRepository = repository;
948             }
949             return repository;
950         }
951         return null;
952     }
953
954     public static Object JavaDoc createObject(String JavaDoc className, ILogger logger) {
955
956         Object JavaDoc object = null;
957         try {
958
959             Class JavaDoc componentClass = Class.forName(className);
960             object = componentClass.newInstance();
961
962         } catch (Throwable JavaDoc t) {
963             logger.fatal(Messages.getErrorString("PentahoSystem.ERROR_0013_COULD_NOT_CREATE_OBEJCT", className), t); //$NON-NLS-1$
964
}
965         return object;
966     }
967
968     public static Object JavaDoc createObject(String JavaDoc className) {
969
970         Object JavaDoc object = null;
971         try {
972
973             Class JavaDoc componentClass = Class.forName(className);
974             object = componentClass.newInstance();
975
976         } catch (Throwable JavaDoc t) {
977             Logger.fatal(PentahoSystem.class.getName(), Messages.getErrorString("PentahoSystem.ERROR_0013_COULD_NOT_CREATE_OBEJCT", className), t); //$NON-NLS-1$
978
}
979         return object;
980     }
981
982     public static String JavaDoc getSystemSetting(String JavaDoc path, String JavaDoc settingName, String JavaDoc defaultValue) {
983         return systemSettings.getSystemSetting(path, settingName, defaultValue);
984     }
985
986     public static String JavaDoc getSystemSetting(String JavaDoc settingName, String JavaDoc defaultValue) {
987         // TODO make this more efficient using caching
988
return systemSettings.getSystemSetting(settingName, defaultValue);
989     }
990
991     public static ISystemSettings getSystemSettings() {
992         return systemSettings;
993     }
994
995     public static void refreshSettings() {
996         systemSettings.resetSettingsCache();
997     }
998
999     public static String JavaDoc publish(IPentahoSession session, String JavaDoc className) {
1000        Iterator JavaDoc publisherIterator = publishers.iterator();
1001        // TODO: audit this
1002
while (publisherIterator.hasNext()) {
1003            IPentahoPublisher publisher = (IPentahoPublisher) publisherIterator.next();
1004            if (publisher != null && (className == null || className.equals(publisher.getClass().getName()))) {
1005                try {
1006                    return publisher.publish(session, loggingLevel);
1007                } catch (Throwable JavaDoc e) {
1008
1009                }
1010            }
1011        }
1012        return Messages.getString("PentahoSystem.ERROR_0017_PUBLISHER_NOT_FOUND"); //$NON-NLS-1$
1013
}
1014
1015    public static List JavaDoc getPublisherList() {
1016        return publishers;
1017    }
1018
1019    public static Document getPublishersDocument() {
1020
1021        Document document = DocumentHelper.createDocument();
1022        Element root = document.addElement("publishers"); //$NON-NLS-1$
1023

1024        Iterator JavaDoc publisherIterator = publishers.iterator();
1025        // TODO: audit this
1026
// refresh the system settings
1027
while (publisherIterator.hasNext()) {
1028            IPentahoPublisher publisher = (IPentahoPublisher) publisherIterator.next();
1029            if (publisher != null) {
1030                try {
1031                    Element publisherNode = root.addElement("publisher"); //$NON-NLS-1$
1032
publisherNode.addElement("name").setText(publisher.getName()); //$NON-NLS-1$
1033
publisherNode.addElement("description").setText(publisher.getDescription()); //$NON-NLS-1$
1034
publisherNode.addElement("class").setText(publisher.getClass().getName()); //$NON-NLS-1$
1035

1036                } catch (Throwable JavaDoc e) {
1037
1038                }
1039            }
1040        }
1041
1042        return document;
1043
1044    }
1045
1046    public static void systemEntryPoint() {
1047      applicationContext.invokeEntryPoints();
1048    }
1049
1050    public static void systemExitPoint() {
1051      applicationContext.invokeExitPoints();
1052    }
1053
1054}
Free Books   Free Magazines  
Popular Tags