KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > pentaho > core > connection > AbstractPentahoMetaData


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 Nov 15, 2005
14  * @author wseyler
15  */

16
17 package org.pentaho.core.connection;
18
19 public abstract class AbstractPentahoMetaData implements IPentahoMetaData {
20     /*
21      * (non-Javadoc)
22      *
23      * @see org.pentaho.connection.IPentahoMetaData#getColumnIndex(java.lang.String)
24      */

25     public int getColumnIndex(String JavaDoc value) {
26       Object JavaDoc[][] columnHeaders = getColumnHeaders();
27         if (columnHeaders == null || columnHeaders.length != 1) {
28             return -1;
29         }
30         for (int idx = 0; idx < columnHeaders[0].length; idx++) {
31             if (columnHeaders[0][idx].toString().equalsIgnoreCase(value)) {
32                 return idx;
33             }
34         }
35         return -1;
36     }
37
38     /*
39      * (non-Javadoc)
40      *
41      * @see org.pentaho.connection.IPentahoMetaData#getColumnIndex(java.lang.String[])
42      */

43     public int getColumnIndex(String JavaDoc[] values) {
44       Object JavaDoc[][] columnHeaders = getColumnHeaders();
45         if (columnHeaders == null || columnHeaders.length != values.length) {
46             return -1;
47         }
48         for (int columnIdx = 0; columnIdx < columnHeaders[0].length; columnIdx++) {
49             boolean match = true;
50             for (int rowIdx = 0; rowIdx < columnHeaders.length && match; rowIdx++) {
51                 match = columnHeaders[rowIdx][columnIdx].toString().equalsIgnoreCase(values[rowIdx]);
52             }
53             if (match) {
54                 return columnIdx;
55             }
56         }
57         return -1;
58     }
59
60     /*
61      * (non-Javadoc)
62      *
63      * @see org.pentaho.connection.IPentahoMetaData#getRowIndex(java.lang.String)
64      */

65     public int getRowIndex(String JavaDoc value) {
66       Object JavaDoc[][] rowHeaders = getRowHeaders();
67         if (rowHeaders == null || rowHeaders[0].length != 1) {
68             return -1;
69         }
70         for (int rowIdx = 0; rowIdx < rowHeaders.length; rowIdx++) {
71             if (rowHeaders[rowIdx][0].toString().equalsIgnoreCase(value)) {
72                 return rowIdx;
73             }
74         }
75         return -1;
76     }
77
78     /*
79      * (non-Javadoc)
80      *
81      * @see org.pentaho.connection.IPentahoMetaData#getRowIndex(java.lang.String[])
82      */

83     public int getRowIndex(String JavaDoc[] values) {
84       Object JavaDoc[][] rowHeaders = getRowHeaders();
85         if (rowHeaders == null || rowHeaders[0].length != values.length) {
86             return -1;
87         }
88         for (int rowIdx = 0; rowIdx < rowHeaders.length; rowIdx++) {
89             boolean match = true;
90             for (int columnIdx = 0; columnIdx < rowHeaders[rowIdx].length && match; columnIdx++) {
91                 match = rowHeaders[rowIdx][columnIdx].toString().equalsIgnoreCase(values[columnIdx]);
92             }
93             if (match) {
94                 return rowIdx;
95             }
96         }
97         return -1;
98     }
99
100     /*
101      * (non-Javadoc)
102      *
103      * @see org.pentaho.connection.IPentahoMetaData#getColumnHeaders()
104      */

105     public abstract Object JavaDoc[][] getColumnHeaders();
106
107     /*
108      * (non-Javadoc)
109      *
110      * @see org.pentaho.connection.IPentahoMetaData#getRowHeaders()
111      */

112     public abstract Object JavaDoc[][] getRowHeaders();
113
114     /*
115      * (non-Javadoc)
116      *
117      * @see org.pentaho.connection.IPentahoMetaData#getColumnCount()
118      */

119     public int getColumnCount() {
120       Object JavaDoc[][] columnHeaders = getColumnHeaders();
121         if (columnHeaders == null || columnHeaders.length <= 0) {
122             return 0;
123         }
124         return columnHeaders[0].length;
125     }
126 }
127
Popular Tags