KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > pentaho > plugin > kettle > KettleSystemListener


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 Jan 9, 2006
14  * @author mbatchel
15  */

16 package org.pentaho.plugin.kettle;
17
18 import java.io.File JavaDoc;
19 import java.io.FileInputStream JavaDoc;
20 import java.io.InputStream JavaDoc;
21 import java.io.IOException JavaDoc;
22 import java.util.Map JavaDoc;
23 import java.util.Properties JavaDoc;
24
25 import org.pentaho.core.session.IPentahoSession;
26 import org.pentaho.core.system.IPentahoSystemListener;
27 import org.pentaho.core.system.PentahoSystem;
28 import org.pentaho.messages.Messages;
29 import org.pentaho.util.logging.Logger;
30
31 import be.ibridge.kettle.trans.StepLoader;
32 import be.ibridge.kettle.core.LocalVariables;
33 import be.ibridge.kettle.job.JobEntryLoader;
34
35
36 public class KettleSystemListener implements IPentahoSystemListener {
37
38     public boolean startup(IPentahoSession session) {
39
40         try {
41
42             /* Load the plugins etc. */
43             StepLoader stloader = StepLoader.getInstance();
44             environmentInit();
45             if (!stloader.read()) {
46                 Logger.error(KettleSystemListener.class.getName(), Messages.getErrorString("KettleSystemListener.ERROR_0001_STEP_LOAD_FAILED")); //$NON-NLS-1$
47
}
48
49             JobEntryLoader jeLoader = JobEntryLoader.getInstance();
50             if (!jeLoader.read()) {
51                 Logger.error(KettleSystemListener.class.getName(), Messages.getString("KettleSystemListener.ERROR_0002_JOB_ENTRY_LOAD_FAILED")); //$NON-NLS-1$
52
}
53             
54
55         } catch (Exception JavaDoc ex) {
56             Logger.error(KettleSystemListener.class.getName(), Messages.getErrorString("KettleSystemListener.ERROR_0001_STEP_LOAD_FAILED"), //$NON-NLS-1$
57
ex);
58         }
59
60         return true;
61     }
62
63
64
65     public static Map JavaDoc readProperties() {
66
67         Properties JavaDoc props = new Properties JavaDoc();
68         String JavaDoc kettlePropsFilename = PentahoSystem.getApplicationContext().getSolutionPath("system"+File.separator+"kettle"+File.separator+"kettle.properties"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
69

70         InputStream JavaDoc is = null;
71         try {
72             File JavaDoc propsFile = new File JavaDoc( kettlePropsFilename );
73             if( !propsFile.exists() ) {
74                 return props;
75             }
76             is = new FileInputStream JavaDoc(propsFile);
77             props.load(is);
78         } catch (IOException JavaDoc ioe) {
79             Logger.error(KettleSystemListener.class.getName(), Messages.getString("KettleSystemListener.ERROR_0003_PROPERTY_FILE_READ_FAILED") + ioe.getMessage(), ioe); //$NON-NLS-1$
80
}
81         finally {
82             if (is != null)
83                 try
84                 {
85                     is.close();
86                 }
87                 catch (IOException JavaDoc e)
88                 {
89                     // ignore
90
}
91         }
92
93         props.put( "pentaho.solutionpath", PentahoSystem.getApplicationContext().getFileOutputPath( "" ) ); //$NON-NLS-1$ //$NON-NLS-2$
94
return props;
95
96     }
97
98
99
100     public static void environmentInit()
101
102     {
103
104         Map JavaDoc kettleProperties = readProperties();
105
106         System.getProperties().putAll(kettleProperties);
107
108         LocalVariables local = LocalVariables.getInstance();
109
110         local.createKettleVariables(Thread.currentThread().getName(), null, false);
111
112
113
114     }
115
116     
117
118
119     public void shutdown() {
120         // Nothing required
121
}
122
123 }
124
Popular Tags