KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > pentaho > plugin > core > ResultSetExportComponent


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 January 3rd, 2006
14  * @author Michael D'Amour
15  **/

16 package org.pentaho.plugin.core;
17
18 import java.util.Set JavaDoc;
19 import org.apache.commons.logging.Log;
20 import org.apache.commons.logging.LogFactory;
21 import org.pentaho.core.connection.DataUtilities;
22 import org.pentaho.core.connection.IPentahoResultSet;
23 import org.pentaho.messages.Messages;
24 import org.pentaho.plugin.ComponentBase;
25
26 /**
27  *
28  * Implements a PrintComponent class that will send a attached print file to a
29  * specified printer.
30  */

31 public class ResultSetExportComponent extends ComponentBase {
32     /**
33      *
34      */

35     private static final long serialVersionUID = 3289900246113442203L;
36
37     public Log getLogger() {
38         return LogFactory.getLog(ResultSetExportComponent.class);
39     }
40
41     public boolean init() {
42         // TODO Auto-generated method stub
43
return true;
44     }
45
46     protected boolean validateSystemSettings() {
47         // This component does not have any system settings to validate
48
return true;
49     }
50
51     protected boolean validateAction() {
52         boolean hasResultSetParameter = isDefinedInput("result-set"); //$NON-NLS-1$
53
if (!hasResultSetParameter) {
54             error(Messages.getString("JFreeReport.ERROR_0022_DATA_INPUT_INVALID_OBJECT")); //$NON-NLS-1$
55
return false;
56         }
57         if (getResultOutputName() == null) {
58             error(Messages.getString("JFreeReport.ERROR_0022_DATA_INPUT_INVALID_OBJECT")); //$NON-NLS-1$
59
return false;
60         }
61         return true;
62     }
63
64     protected boolean executeAction() {
65         Object JavaDoc resultSetObject = getInputValue("result-set"); //$NON-NLS-1$
66
if (resultSetObject instanceof IPentahoResultSet) {
67             IPentahoResultSet resultset = (IPentahoResultSet) resultSetObject;
68             if (getResultOutputName() != null) {
69                 setOutputValue(getResultOutputName(), DataUtilities.getXMLString(resultset));
70             }
71             return true;
72         } else {
73                 return false;
74         }
75     }
76
77     public void done() {
78         // TODO Auto-generated method stub
79
}
80
81     public String JavaDoc getResultOutputName() {
82         Set JavaDoc outputs = getOutputNames();
83         if ((outputs == null) || (outputs.size() == 0)) {
84             error(Messages.getString("Template.ERROR_0002_OUTPUT_COUNT_WRONG")); //$NON-NLS-1$
85
return null;
86         }
87         String JavaDoc outputName = null;
88         try {
89             outputName = getInputStringValue(StandardSettings.OUTPUT_NAME);
90         } catch (Exception JavaDoc e) {
91         }
92         if (outputName == null) { // Drop back to the old behavior
93
outputName = (String JavaDoc) outputs.iterator().next();
94         }
95         return outputName;
96     }
97 }
98
Popular Tags