01: /*
02: * Copyright 2006 Pentaho Corporation. All rights reserved.
03: * This software was developed by Pentaho Corporation and is provided under the terms
04: * of the Mozilla Public License, Version 1.1, or any later version. You may not use
05: * this file except in compliance with the license. If you need a copy of the license,
06: * please go to http://www.mozilla.org/MPL/MPL-1.1.txt. The Original Code is the Pentaho
07: * BI Platform. The Initial Developer is Pentaho Corporation.
08: *
09: * 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.mql;
17:
18: import java.io.File;
19: import java.io.FileInputStream;
20: import java.io.InputStream;
21: import java.util.Properties;
22:
23: import org.pentaho.core.session.IPentahoSession;
24: import org.pentaho.core.system.IPentahoSystemListener;
25: import org.pentaho.core.system.PentahoSystem;
26: import org.pentaho.messages.Messages;
27: import org.pentaho.pms.core.CWM;
28: import org.pentaho.util.logging.Logger;
29:
30: public class PMDSystemListener implements IPentahoSystemListener {
31:
32: public boolean startup(IPentahoSession session) {
33:
34: Properties props = new Properties();
35: String kettlePropsFilename = PentahoSystem
36: .getApplicationContext()
37: .getSolutionPath(
38: "system" + File.separator + "metadata" + File.separator + "repository.properties"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
39:
40: InputStream is = null;
41: try {
42: File propsFile = new File(kettlePropsFilename);
43: if (propsFile.exists()) {
44: is = new FileInputStream(propsFile);
45: props.load(is);
46:
47: InputStream xmiInputStream = null;
48: try {
49: xmiInputStream = PentahoSystem
50: .getSolutionRepository(session)
51: .getResourceInputStream(
52: "system/metadata/PentahoCWM.xml", false); //$NON-NLS-1$
53: CWM.getRepositoryInstance(props, xmiInputStream);
54: } catch (Throwable t) {
55: t.printStackTrace();
56: } finally {
57: if (xmiInputStream != null) {
58: xmiInputStream.close();
59: }
60: }
61: } else {
62: Logger
63: .error(
64: PMDSystemListener.class.getName(),
65: Messages
66: .getErrorString("PMDSystemListener.ERROR_0001_PROPERTIES_NOT_FOUND")); //$NON-NLS-1$
67: return true;
68: }
69: } catch (Throwable t) {
70: Logger
71: .error(
72: PMDSystemListener.class.getName(),
73: Messages
74: .getErrorString("PMDSystemListener.ERROR_0002_COULD_NOT_INITIALIZE"), t); //$NON-NLS-1$
75: return true; // Service is not required
76: }
77: return true;
78: }
79:
80: public void shutdown() {
81: // Nothing required
82: }
83:
84: }
|