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.hayabusa.resource; 017 018import static org.opengion.fukurou.util.StringUtil.nval2; 019 020/** 021 * systemId に対応したカラムデータを作成します。 022 * 023 * カラムデータは、項目(CLM)に対して、各種カラム情報を持っています。 024 * エンジン内部で使用している DBColumn オブジェクトは、RENDERER や EDITOR など 025 * 実際にはオブジェクトで管理していますが、この ColumnData では、それらのキーとなる 026 * 文字列を持っています。実際に DBColumn オブジェクトの構築時に、各属性オブジェクトを 027 * 生成(または、キャッシュから取り出し)ます。 028 * 029 * カラムデータを作成する場合は、同一カラムで、作成区分(KBSAKU)違いの場合は、 030 * 最も大きな作成区分を持つコードを使用します。 031 * 作成区分(KBSAKU)は、0:システム予約、1:アプリ設定、2:ユーザー設定 という具合に 032 * カスタマイズの度合いに応じて大きな数字を割り当てることで、キー情報を上書き修正 033 * することが可能になります。(削除することは出来ません。) 034 * 035 * @og.rev 4.0.0.0 (2004/12/31) 新規作成 036 * @og.group リソース管理 037 * 038 * @version 4.0 039 * @author Kazuhiko Hasegawa 040 * @since JDK5.0, 041 */ 042public final class ColumnData { 043 044 /** 内部データのカラム番号 {@value} */ 045 public static final int CLM = 0 ; 046 /** 内部データのカラム番号 {@value} */ 047 public static final int CLS_NAME = 1 ; 048 /** 内部データのカラム番号 {@value} */ 049 public static final int USE_LENGTH = 2 ; 050 /** 内部データのカラム番号 {@value} */ 051 public static final int VIEW_LENGTH = 3 ; 052 /** 内部データのカラム番号 {@value} */ 053 public static final int RENDERER = 4 ; 054 /** 内部データのカラム番号 {@value} */ 055 public static final int EDITOR = 5 ; 056 /** 内部データのカラム番号 {@value} */ 057 public static final int DBTYPE = 6 ; 058 /** 内部データのカラム番号 {@value} */ 059 public static final int DATA_DEFAULT = 7 ; 060 /** 内部データのカラム番号 {@value} */ 061 public static final int LABEL_CLM = 8 ; 062 /** 内部データのカラム番号 {@value} */ 063 public static final int CODE_CLM = 9 ; 064 /** 内部データのカラム番号 {@value} */ 065 public static final int CLM_PARAM = 10 ; 066 /** 内部データのカラム番号 {@value} */ 067 public static final int RENDERER_PARAM = 11 ; 068 /** 内部データのカラム番号 {@value} */ 069 public static final int EDITOR_PARAM = 12 ; 070 /** 内部データのカラム番号 {@value} */ 071 public static final int TYPE_PARAM = 13 ; 072 /** 内部データのカラム番号 {@value} */ 073 public static final int ROLES = 14 ; 074 /** 内部データのカラム数 {@value} */ 075 public static final int DATA_SIZE = 15 ; 076 /** リソース読み込みのために一時利用 4.3.5.7 (2009/03/22) */ 077 public static final int FG_LOAD = 15 ; 078 079 private final String name ; // カラム名 080 private final String className ; // データの属性 081 private final String maxlength ; // 使用桁数 082 private final String viewLength ; // 表示桁数 083 private final String renderer ; // 表示種別 084 private final String editor ; // 編集種別 085 private final String dbType ; // 文字種別 086 private final String dataDef ; // データのデフォルト値 087 private final String labelClm ; // ラベルカラム 088 private final String codeClm ; // コードカラム 089 private final String columnPrm ; // カラムパラメータ 090 private final String rendererPrm ; // 表示パラメータ 091 private final String editorPrm ; // 編集パラメータ 092 private final String dbTypePrm ; // 文字パラメータ 093 private final String roles ; // カラムロール 094 private final RoleMode roleMode ; // 4.3.0.0 (2008/07/04) ロールズとモードを管理するオブジェクト 095 096 private final int totalSize ; // 総桁数(小数点も含む) 097 private final int sizeX ; // カラムの文字桁数(整数部) 098 private final int sizeY ; // カラムの文字桁数(少数部) 099 private final boolean official ; // リソースDBから作成されたかどうか 100 101 /** 102 * 配列文字列のデータを元に、ColumnDataオブジェクトを構築します。 103 * このコンストラクタは、他のパッケージから呼び出せないように、 104 * パッケージプライベートにしておきます。 105 * このコンストラクタは、DBリソースファイルを想定しています。 106 * 107 * @og.rev 4.3.0.0 (2008/07/04) ロールモードマルチ対応 108 * @og.rev 5.1.6.0 (2010/05/01) DBTypeの初期値を "XK" とします。 109 * @og.rev 5.2.2.0 (2010/11/01) パラメーターもVer3互換のためNVAL2で処理します。 110 * @og.rev 5.5.8.5 (2012/11/27) 編集パラメータで、"=" と記述されている場合は、表示パラメータを利用する。 111 * 112 * @param data CLM,CLS_NAME,USE_LENGTH,VIEW_LENGTH, 113 * RENDERER,EDITOR,DBTYPE,DATA_DEFAULT,LABEL_CLM,CODE_CLM, 114 * CLM_PARAM,RENDERER_PARAM,EDITOR_PARAM,TYPE_PARAM,ROLES 115 * 116 */ 117 public ColumnData( final String[] data ) { 118 name = data[CLM].intern() ; // カラム名 119 className = data[CLS_NAME].intern() ; // データの属性 120 maxlength = data[USE_LENGTH].replace( '.',',' ).intern(); // 使用桁数 121 viewLength = nval2( data[VIEW_LENGTH], null ) ; // 表示桁数 122 renderer = nval2( data[RENDERER], null ) ; // 表示種別 123 editor = nval2( data[EDITOR], null ) ; // 編集種別 124 dbType = nval2( data[DBTYPE], "XK" ) ; // 文字種別 5.1.6.0 (2010/05/01) 125 dataDef = nval2( data[DATA_DEFAULT] , "" ) ; // データのデフォルト値 126 labelClm = nval2( data[LABEL_CLM] , name ) ; // ラベルカラム 127 codeClm = nval2( data[CODE_CLM] , name ) ; // コードカラム 128 columnPrm = nval2( data[CLM_PARAM], null ); // カラムパラメータ 129 rendererPrm = nval2( data[RENDERER_PARAM], null ) ; // 表示パラメータ 130 dbTypePrm = nval2( data[TYPE_PARAM], null ) ; // 文字パラメータ 131 roles = nval2( data[ROLES] , null ) ; // カラムロール 132 official = true; // リソースDBから作成されたかどうか 133 134 // 5.5.8.5 (2012/11/27) 編集パラメータで、"=" と記述されている場合は、表示パラメータを利用する。 135 String tempEditPrm = nval2( data[EDITOR_PARAM], null ) ; 136 if( "=".equals( tempEditPrm ) ) { 137 editorPrm = rendererPrm ; 138 } 139 else { 140 editorPrm = tempEditPrm ; 141 } 142 143 roleMode = RoleMode.newInstance( roles ); // ロールモード 144 145 // x,y 形式の場合、x + 2 桁で表されます。(マイナス記号と小数点記号) 146 // 7,3 は、 xxxx,yyy のフォーマットで、データ長は、9 になります。 147 int ch = maxlength.indexOf( ',' ) ; 148 if( ch > 0 ) { 149 sizeY = Integer.parseInt( maxlength.substring( ch+1 ) ); 150 sizeX = Integer.parseInt( maxlength.substring( 0,ch ) ) - sizeY; 151 totalSize = sizeX + sizeY+ 2; 152 } 153 else { 154 sizeY = 0; 155 sizeX = Integer.parseInt( maxlength ); 156 if( "S9".equals( dbType ) ) { 157 totalSize = sizeX + 1; // 数字型の場合は、マイナス記号分を加える。 158 } 159 else { 160 totalSize = sizeX ; 161 } 162 } 163 } 164 165 /** 166 * カラム名を返します。 167 * 168 * @return カラム名 169 */ 170 public String getName() { return name; } 171 172 /** 173 * カラムのデータの属性を返します。 174 * 175 * @return カラムのデータの属性 176 */ 177 public String getClassName() { return className; } 178 179 /** 180 * フィールドの使用桁数を返します。 181 * 少数指定の場合は、"7,3" のようなカンマで整数部、小数部を区切った書式になります。 182 * 7,3 は、 xxxx,yyy のフォーマットで、整数部4桁、小数部3桁を意味します。 183 * 184 * @return 使用桁数 185 */ 186 public String getMaxlength() { return maxlength; } 187 188 /** 189 * フィールドのデータ長を返します。 190 * 通常は、整数型の文字列とデータ長は同じですが,小数点を表すデータ長は 191 * x.y 形式の場合、x + 1 桁で表されます。 192 * 6.2 は、 xxxx.yy のフォーマットです。 193 * 194 * @return データ長定義文字列 195 */ 196 public int getTotalSize() { return totalSize; } 197 198 /** 199 * フィールドの整数部のデータ長を返します。 200 * 201 * @return データ長定義文字列 202 */ 203 public int getSizeX() { return sizeX ; } 204 205 /** 206 * フィールドの小数部のデータ長を返します。 207 * 208 * @return データ長定義文字列 209 */ 210 public int getSizeY() { return sizeY ; } 211 212 /** 213 * フィールドの表示桁数を返します。 214 * 215 * @return 表示桁数 216 */ 217 public String getViewLength() { return viewLength; } 218 219 /** 220 * 表示種別を返します。 221 * 222 * @return 表示種別の文字列 223 */ 224 public String getRenderer() { return renderer; } 225 226 /** 227 * 編集種別を返します。 228 * 229 * @return 編集種別 230 */ 231 public String getEditor() { return editor; } 232 233 /** 234 * 文字種別を返します。 235 * 236 * @return 文字種別 237 */ 238 public String getDbType() { return dbType; } 239 240 /** 241 * ラベルカラムを返します。 242 * 243 * @return ラベルカラム 244 */ 245 public String getLabelColumn() { return labelClm; } 246 247 /** 248 * コードカラムを返します。 249 * 250 * @return コードカラム 251 */ 252 public String getCodeColumn() { return codeClm; } 253 254 /** 255 * データのデフォルト値を返します。 256 * 257 * @return データのデフォルト値 258 */ 259 public String getDefault() { return dataDef; } 260 261 /** 262 * カラムのパラメータを取得します。 263 * 264 * @return カラムパラメータ 265 */ 266 public String getColumnParam() { return columnPrm; } 267 268 /** 269 * 表示用レンデラーのパラメータを取得します。 270 * 271 * @return 表示パラメータ 272 */ 273 public String getRendererParam() { return rendererPrm; } 274 275 /** 276 * 編集用エディターのパラメータを取得します。 277 * 278 * @return 編集パラメータ 279 */ 280 public String getEditorParam() { return editorPrm; } 281 282 /** 283 * データタイプのパラメータを取得します。 284 * 285 * @return データタイプのパラメータ 286 */ 287 public String getDbTypeParam() { return dbTypePrm; } 288 289 /** 290 * カラムロールを取得します。 291 * 292 * @return カラムロール 293 */ 294 public String getRoles() { return roles; } 295 296 /** 297 * カラムオブジェクトのロールモードを返します。 298 * 299 * @og.rev 4.3.0.0 (2008/07/04) ロールモードマルチ対応 300 * 301 * @return カラムオブジェクトのロールモード 302 */ 303 public RoleMode getRoleMode() { return roleMode; } 304 305 /** 306 * リソースDBから作成されたかどうかを返します。 307 * 正式な場合は、true / リソースになく、独自に作成された場合は、false になります。 308 * 309 * @return リソースDBから作成されたかどうか 310 * 311 */ 312 public boolean isOfficial() { return official; } 313 314 /** 315 * 内部データの文字列配列を返します。 316 * 317 * @return 内部データの文字列配列 318 */ 319 public String[] getColumnData() { 320 String[] data = new String[DATA_SIZE]; 321 322 data[CLM ] = name ; 323 data[CLS_NAME ] = className ; 324 data[USE_LENGTH ] = maxlength ; 325 data[VIEW_LENGTH ] = viewLength ; 326 data[RENDERER ] = renderer ; 327 data[EDITOR ] = editor ; 328 data[DBTYPE ] = dbType ; 329 data[DATA_DEFAULT ] = dataDef ; 330 data[LABEL_CLM ] = labelClm ; 331 data[CODE_CLM ] = codeClm ; 332 data[CLM_PARAM ] = columnPrm ; 333 data[RENDERER_PARAM ] = rendererPrm ; 334 data[EDITOR_PARAM ] = editorPrm ; 335 data[TYPE_PARAM ] = dbTypePrm ; 336 data[ROLES ] = roles ; 337 338 return data ; 339 } 340}