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     */
016    package org.opengion.hayabusa.resource;
017    
018    import 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)は?:シス?予??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     */
042    public 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                ;               // リソース??から作?されたかど?
100    
101            /**
102             * 配???の??タを?に、ColumnDataオブジェクトを構築します?
103             * こ?コンストラクタは、他?パッケージから呼び出せな???
104             * パッケージプライベ?トにしておきます?
105             * こ?コンストラクタは??リソースファイルを想定して?す?
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       = StringUtil.toNumber( data[USE_LENGTH] ).intern() ;    // 使用桁数
121                    maxlength       = data[USE_LENGTH].replace( '.',',' ).intern();                 // 使用桁数
122                    viewLength      = nval2( data[VIEW_LENGTH], null ) ;    // 表示桁数
123                    renderer        = nval2( data[RENDERER], null ) ;               // 表示種別
124                    editor          = nval2( data[EDITOR], null ) ;                 // 編?別
125    //              dbType          = nval2( data[DBTYPE], null ) ;                 // ?種別
126                    dbType          = nval2( data[DBTYPE], "XK" ) ;                 // ?種別  5.1.6.0 (2010/05/01)
127                    dataDef         = nval2( data[DATA_DEFAULT] , ""   ) ;  // ??タの?ォルト?
128                    labelClm        = nval2( data[LABEL_CLM]    , name ) ;  // ラベルカラ?
129                    codeClm         = nval2( data[CODE_CLM]     , name ) ;  // コードカラ?
130    //              columnPrm       = data[CLM_PARAM] ;                                             // カラ?ラメータ
131    //              rendererPrm     = data[RENDERER_PARAM] ;                                // 表示パラメータ
132    //              editorPrm       = data[EDITOR_PARAM] ;                                  // 編?ラメータ
133    //              dbTypePrm       = data[TYPE_PARAM] ;                                    // ?パラメータ
134                    columnPrm       = nval2( data[CLM_PARAM], null );               // カラ?ラメータ
135                    rendererPrm     = nval2( data[RENDERER_PARAM], null ) ; // 表示パラメータ
136    //              editorPrm       = nval2( data[EDITOR_PARAM], null ) ;   // 編?ラメータ                        5.5.8.5 (2012/11/27)
137                    dbTypePrm       = nval2( data[TYPE_PARAM], null ) ;             // ?パラメータ
138                    roles           = nval2( data[ROLES] , null ) ;                 // カラ?ール
139                    official        = true;                                                                 // リソース??から作?されたかど?
140    
141                    // 5.5.8.5 (2012/11/27) 編?ラメータで?=" と記述されて?場合?、表示パラメータを利用する?
142                    String tempEditPrm = nval2( data[EDITOR_PARAM], null ) ;
143                    if( "=".equals( tempEditPrm ) ) {
144                            editorPrm = rendererPrm ;
145                    }
146                    else {
147                            editorPrm = tempEditPrm ;
148                    }
149    
150                    roleMode        = RoleMode.newInstance( roles );        // ロールモー?
151    
152                    // x,y 形式?場合?x + 2 桁で表されます?(マイナス記号と小数点記号)
153                    // 7,3 は?xxxx,yyy のフォーマットで、データ長は? になります?
154                    int ch = maxlength.indexOf( ',' ) ;
155                    if( ch > 0 ) {
156                            sizeY = Integer.parseInt( maxlength.substring( ch+1 ) );
157                            sizeX = Integer.parseInt( maxlength.substring( 0,ch ) ) - sizeY;
158                            totalSize = sizeX + sizeY+ 2;
159                    }
160                    else {
161                            sizeY = 0;
162                            sizeX = Integer.parseInt( maxlength );
163                            if( "S9".equals( dbType ) ) {
164                                    totalSize = sizeX + 1;  // 数字型の場合?、?イナス記号??る?
165                            }
166                            else {
167                                    totalSize = sizeX ;
168                            }
169                    }
170            }
171    
172            /**
173             * カラ?を返します?
174             *
175             * @return  カラ?
176             */
177            public String getName() { return name; }
178    
179            /**
180             * カラ????タの属?を返します?
181             *
182             * @return  カラ????タの属?
183             */
184            public String getClassName() { return className; }
185    
186            /**
187             * フィールド?使用桁数を返します?
188             * 少数??場合??7,3" のようなカンマで整数部、小数部を区?た書式になります?
189             * 7,3 は?xxxx,yyy のフォーマットで、整数部?桁?小数部?桁を意味します?
190             *
191             * @return  使用桁数
192             */
193            public String getMaxlength() { return maxlength; }
194    
195            /**
196             * フィールド???タ長を返します?
197             * 通常は、整数型???と??タ長は同じですが,小数点を表すデータ長は
198             * x.y 形式?場合?x + 1 桁で表されます?
199             * 6.2 は?xxxx.yy のフォーマットです?
200             *
201             * @return  ??タ長定義??
202             */
203            public int getTotalSize() { return totalSize; }
204    
205            /**
206             * フィールド?整数部の??タ長を返します?
207             *
208             * @return  ??タ長定義??
209             */
210            public int getSizeX() { return sizeX ; }
211    
212            /**
213             * フィールド?小数部の??タ長を返します?
214             *
215             * @return  ??タ長定義??
216             */
217            public int getSizeY() { return sizeY ; }
218    
219            /**
220             * フィールド?表示桁数を返します?
221             *
222             * @return  表示桁数
223             */
224            public String getViewLength() { return viewLength; }
225    
226            /**
227             * 表示種別を返します?
228             *
229             * @return  表示種別の??
230             */
231            public String getRenderer() { return renderer; }
232    
233            /**
234             * 編?別を返します?
235             *
236             * @return  編?別
237             */
238            public String getEditor() { return editor; }
239    
240            /**
241             * ?種別を返します?
242             *
243             * @return  ?種別
244             */
245            public String getDbType() { return dbType; }
246    
247            /**
248             * ラベルカラ?返します?
249             *
250             * @return  ラベルカラ?
251             */
252            public String getLabelColumn() { return labelClm; }
253    
254            /**
255             * コードカラ?返します?
256             *
257             * @return  コードカラ?
258             */
259            public String getCodeColumn() { return codeClm; }
260    
261            /**
262             * ??タの?ォルト?を返します?
263             *
264             * @return  ??タの?ォルト?
265             */
266            public String getDefault() { return dataDef; }
267    
268            /**
269             * カラ??パラメータを取得します?
270             *
271             * @return      カラ?ラメータ
272             */
273            public String getColumnParam() { return columnPrm; }
274    
275            /**
276             * 表示用レン?ーのパラメータを取得します?
277             *
278             * @return      表示パラメータ
279             */
280            public String getRendererParam() { return rendererPrm; }
281    
282            /**
283             * 編?エ?ターのパラメータを取得します?
284             *
285             * @return      編?ラメータ
286             */
287            public String getEditorParam() { return editorPrm; }
288    
289            /**
290             * ??タタイプ?パラメータを取得します?
291             *
292             * @return      ??タタイプ?パラメータ
293             */
294            public String getDbTypeParam() { return dbTypePrm; }
295    
296            /**
297             * カラ?ールを取得します?
298             *
299             * @return      カラ?ール
300             */
301            public String getRoles() { return roles; }
302    
303            /**
304             * カラ?ブジェクト?ロールモードを返します?
305             *
306             * @og.rev 4.3.0.0 (2008/07/04) ロールモード?ルチ対?
307             *
308             * @return カラ?ブジェクト?ロールモー?
309             */
310            public RoleMode getRoleMode() { return roleMode; }
311    
312            /**
313             * リソース??から作?されたかど?を返します?
314             * 正式な場合?、true / リソースになく?独自に作?された?合?、false になります?
315             *
316             * @return      リソース??から作?されたかど?
317             *
318             */
319            public boolean isOfficial() { return official; }
320    
321            /**
322             * ???タの??配?を返します?
323             *
324             * @return      ???タの??配?
325             */
326            public String[] getColumnData() {
327                    String[] data = new String[DATA_SIZE];
328    
329                    data[CLM                        ] = name                ;
330                    data[CLS_NAME           ] = className   ;
331                    data[USE_LENGTH         ] = maxlength   ;
332                    data[VIEW_LENGTH        ] = viewLength  ;
333                    data[RENDERER           ] = renderer    ;
334                    data[EDITOR             ] = editor              ;
335                    data[DBTYPE             ] = dbType              ;
336                    data[DATA_DEFAULT       ] = dataDef             ;
337                    data[LABEL_CLM          ] = labelClm    ;
338                    data[CODE_CLM           ] = codeClm             ;
339                    data[CLM_PARAM          ] = columnPrm   ;
340                    data[RENDERER_PARAM     ] = rendererPrm ;
341                    data[EDITOR_PARAM       ] = editorPrm   ;
342                    data[TYPE_PARAM         ] = dbTypePrm   ;
343                    data[ROLES                      ] = roles               ;
344    
345                    return data ;
346            }
347    }