001: /*
002: * BEGIN_HEADER - DO NOT EDIT
003: *
004: * The contents of this file are subject to the terms
005: * of the Common Development and Distribution License
006: * (the "License"). You may not use this file except
007: * in compliance with the License.
008: *
009: * You can obtain a copy of the license at
010: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
011: * See the License for the specific language governing
012: * permissions and limitations under the License.
013: *
014: * When distributing Covered Code, include this CDDL
015: * HEADER in each file and include the License file at
016: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
017: * If applicable add the following below this CDDL HEADER,
018: * with the fields enclosed by brackets "[]" replaced with
019: * your own identifying information: Portions Copyright
020: * [year] [name of copyright owner]
021: */
022:
023: /*
024: * @(#)ValueDataSetCreator.java
025: * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
026: *
027: * END_HEADER - DO NOT EDIT
028: */
029: package org.openesb.tools.extchart.jfchart.data;
030:
031: import org.openesb.tools.extchart.exception.ChartException;
032: import java.sql.ResultSet;
033: import java.sql.ResultSetMetaData;
034: import java.sql.SQLException;
035: import java.sql.Types;
036: import java.util.logging.Logger;
037: import org.jfree.data.general.Dataset;
038: import org.jfree.data.general.DefaultValueDataset;
039:
040: /**
041: *
042: * @author rdwivedi
043: */
044: public class ValueDataSetCreator extends DataSetCreator {
045:
046: /** Creates a new instance of ValueDataSetCreator */
047: private static Logger mLogger = Logger
048: .getLogger(ValueDataSetCreator.class.getName());
049: private DefaultValueDataset dataset = null;
050:
051: public ValueDataSetCreator() {
052:
053: }
054:
055: public Dataset getDefaultDataSet() {
056: return dataset;
057: }
058:
059: public void processResultSet(ResultSet resultSet)
060: throws ChartException {
061: dataset = new DefaultValueDataset();
062:
063: try {
064: if (resultSet.next()) {
065: ResultSetMetaData metaData = resultSet.getMetaData();
066: int columnCount = metaData.getColumnCount();
067: if (columnCount > 1) {
068: throw new ChartException(
069: "Invalid sql generated. Vlaue data set requires 1 column only.");
070: }
071:
072: int columnType = metaData.getColumnType(1);
073: switch (columnType) {
074: case Types.NUMERIC:
075: case Types.REAL:
076: case Types.INTEGER:
077: case Types.DOUBLE:
078: case Types.FLOAT:
079: case Types.DECIMAL:
080: case Types.BIGINT:
081: Number value = (Number) resultSet.getObject(1);
082: dataset.setValue(value);
083: break;
084: default:
085: throw new ChartException(
086: "Data Type "
087: + columnType
088: + "Not Allowed ,please select a number column.");
089: }
090: }
091: } catch (SQLException e) {
092: throw new ChartException(e);
093: }
094: }
095:
096: public String getQuery() throws ChartException {
097:
098: return null;
099: }
100:
101: }
|