001/*
002 * Copyright (c) 2009 The openGion Project.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
013 * either express or implied. See the License for the specific language
014 * governing permissions and limitations under the License.
015 */
016package org.opengion.plugin.io;
017
018import java.io.PrintWriter;
019
020import org.opengion.hayabusa.db.DBTableModel;
021
022/**
023 * 固定長文字ファイルの書き出しクラスです。
024 * DefaultTableWriter を継承していますので,ラベル,名前,サイズ,データの
025 * 出力部のみオーバーライドして,固定長文字ファイルの出力機能を実現しています。
026 *
027 * なお,固定長出力されるのは,データ部のみで,ラベル,名前,サイズは,
028 * separator で指定された区切り記号で連結されて出力されます。
029 *
030 * @og.group ファイル出力
031 *
032 * @version  4.0
033 * @author   Kazuhiko Hasegawa
034 * @since    JDK5.0,
035 */
036public class TableWriter_Fixed extends TableWriter_Default {
037        //* このプログラムのVERSION文字列を設定します。   {@value} */
038        private static final String VERSION = "4.0.0.0 (2005/08/31)" ;
039
040//      /**
041//       * デフォルトコンストラクター
042//       *
043//       */
044//      public TableWriter_Fixed() {
045//              super();
046//      }
047
048        /**
049         * PrintWriter に DBTableModelのテーブル情報を書き込みます。
050         *
051         * @og.rev 2.3.1.2 (2003/01/28) データ出力時に、改行が余分に出される箇所を修正。
052         * @og.rev 3.1.1.0 (2003/03/28) 同期メソッド(synchronized付き)を非同期に変更する。
053         * @og.rev 3.5.4.5 (2004/01/23) 文字列のエンコード指定(桁数判定)
054         *
055         * @param       table  DBTableModelオブジェクト
056         * @param       writer PrintWriterオブジェクト
057         */
058        @Override
059        protected void writeData( final DBTableModel table,final PrintWriter writer ) {
060                int numberOfRows    =  table.getRowCount();
061                String encode = getEncode();
062
063                for( int row=0; row<numberOfRows; row++ ) {
064                        for( int i=0; i<numberOfColumns; i++ ) {
065                                int clm = clmNo[i];
066                                writer.print( dbColumn[clm].getWriterValue( table.getValue(row,clm),encode ) );
067                        }
068                        writer.println();
069                }
070        }
071}