KickJava   Java API By Example, From Geeks To Geeks.

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


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.IPentahoResultSet;
22 import org.pentaho.core.connection.PentahoDataTransmuter;
23 import org.pentaho.messages.Messages;
24 import org.pentaho.plugin.ComponentBase;
25
26 /**
27  *
28  * This class flattens an IPentahoResultSet by looking at a particular column.
29  *
30  *
31  * The flattening is based on a particular column, as we build our consolidated
32  * row, we look at the this columns value to create a new consolidated row when
33  * it changes.
34  *
35  * eg)
36  *
37  * Dec 20, 2005 3432 Dec 20, 2005 235 Dec 20, 2005 8568 Dec 20, 2005 5685 Dec
38  * 20, 2005 9873 Dec 29, 2005 24685 Dec 29, 2005 12345 Dec 29, 2005 13151 Dec
39  * 29, 2005 12302 Dec 29, 2005 34772
40  *
41  * Dec 20, 2005 3432 235 8568 5685 9873 Dec 29, 2005 24685 12345 13151 12302
42  * 34772
43  */

44 public class ResultSetFlattenerComponent extends ComponentBase {
45     /**
46      *
47      */

48     private static final String JavaDoc RESULT_SET = "result-set"; //$NON-NLS-1$
49

50     private static final String JavaDoc FLATTEN_COLUMN = "flatten-column"; //$NON-NLS-1$
51

52     private static final long serialVersionUID = 5969716585776621813L;
53
54     public Log getLogger() {
55         return LogFactory.getLog(ResultSetFlattenerComponent.class);
56     }
57
58     public boolean init() {
59         // TODO Auto-generated method stub
60
return true;
61     }
62
63     protected boolean validateSystemSettings() {
64         // This component does not have any system settings to validate
65
return true;
66     }
67
68     protected boolean validateAction() {
69         if (!isDefinedInput(RESULT_SET)) {
70             error(Messages.getString("ResultSetFlattenerComponent.ERROR_0001_DATA_INPUT_INVALID_OBJECT")); //$NON-NLS-1$
71
return false;
72         }
73         if (getResultOutputName() == null) {
74             error(Messages.getString("ResultSetFlattenerComponent.ERROR_0002_INVALID_OUTPUT")); //$NON-NLS-1$
75
return false;
76         }
77         if (!isDefinedInput(FLATTEN_COLUMN)) {
78             error(Messages.getString("ResultSetFlattenerComponent.ERROR_0003_INVALID_FLATTEN_COLUMN")); //$NON-NLS-1$
79
return false;
80         }
81         return true;
82     }
83
84     protected boolean executeAction() {
85         Object JavaDoc resultSetObject = getInputValue(RESULT_SET);
86         if (resultSetObject instanceof IPentahoResultSet) {
87             IPentahoResultSet resultset = (IPentahoResultSet) resultSetObject;
88             int column = (int) getInputLongValue(FLATTEN_COLUMN, 0);
89             column--;
90             if (getResultOutputName() != null) {
91                 setOutputValue(getResultOutputName(), PentahoDataTransmuter.flattenResultSet(resultset, column));
92             }
93         }
94         return true;
95     }
96
97     public void done() {
98     }
99
100     public String JavaDoc getResultOutputName() {
101         Set JavaDoc outputs = getOutputNames();
102         if ((outputs == null) || (outputs.size() == 0)) {
103             error(Messages.getString("Template.ERROR_0002_OUTPUT_COUNT_WRONG")); //$NON-NLS-1$
104
return null;
105         }
106         String JavaDoc outputName = null;
107         try {
108             outputName = getInputStringValue(StandardSettings.OUTPUT_NAME);
109         } catch (Exception JavaDoc e) {
110         }
111         if (outputName == null) { // Drop back to the old behavior
112
outputName = (String JavaDoc) outputs.iterator().next();
113         }
114         return outputName;
115     }
116 }
117
Popular Tags