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.fukurou.model;
017
018
019 /**
020 * [PN],[OYA] ãªã©ã® [] ã§æŒ?®šã•れãŸã‚«ãƒ©ãƒ?§è¡¨ã•れãŸãƒ•ォーマットデータã«å¯¾ã—ã¦ã€?
021 * DBTableModelオブジェクトをé©ç”¨ã—㦠å?‚«ãƒ©ãƒ?«å®Ÿãƒ‡ãƒ¼ã‚¿ã‚’割り当ã¦ã‚‹ã‚ªãƒ–ジェクトã§ã™ã?
022 *
023 * @og.group ç”»é¢è¡¨ç¤º
024 *
025 * @version 4.0
026 * @author Kazuhiko Hasegawa
027 * @since JDK5.0,
028 */
029 public class ArrayDataModel implements DataModel<String> {
030 private final String[] names ;
031 private String[] values = null;
032
033 /**
034 * 引数ã«åå‰é…å?を指定ã—ãŸã‚³ãƒ³ã‚¹ãƒˆãƒ©ã‚¯ã‚¿ãƒ¼
035 *
036 * @param nms åå‰é…å?
037 * @throws IllegalArgumentException 引数ã®åå‰é…å?ã?null ã®å ´å?
038 */
039 public ArrayDataModel( final String[] nms ) {
040 if( nms == null ) {
041 String errMsg = "引数ã®åå‰é…å?ã«ã€null ã¯è¨å®šã§ãã¾ã›ã‚“ã€?;
042 throw new IllegalArgumentException( errMsg );
043 }
044
045 int size = nms.length ;
046 names = new String[size] ;
047 System.arraycopy( nms,0,names,0,size );
048 }
049
050 /**
051 * row ã«ã‚るセルã®è¨å®šå?ã‚’ç½®ãæ›ãˆã¾ã™ã?
052 *
053 * @param vals æ–°ã—ã„é…å?値ã€?
054 * @param row 値ãŒå¤‰æ›´ã•れるè¡?無視ã•れã¾ã?
055 */
056 public void setValues( final String[] vals, final int row ) {
057 int size = vals.length;
058 values = new String[size];
059 System.arraycopy( vals,0,values,0,size );
060 }
061
062 /**
063 * カラãƒ?ã«å¯¾å¿œã™ã‚?カラãƒ?•ªå·ã‚’è¿”ã—ã¾ã™ã?
064 *
065 * 特殊ãªã‚«ãƒ©ãƒ?ŒæŒ?®šã•れãŸå ´åˆã?ã€è²??値を返ã—ã¾ã™ã?
066 * 例ãˆã°ã€[KEY.カラãƒ?]ã€[I]ã€[ROW.ID] ãªã©ã€ç‰¹å®šã?è²??値を返ã—ã¾ã™ã?
067 * ã¾ãŸã?カラãƒ?ãŒå?ã®ãƒ??タモãƒ?ƒ«ã«å˜åœ¨ã—ãªã??åˆã‚‚ã€è²??値ã‹ã?
068 * Exception ã‚’è¿”ã—ã¾ã™ã?è²??値ãªã®ã‹ã?Exception ãªã®ã‹ã?ã€?
069 * 実è£?«ä¾å˜ã—ã¾ã™ã?
070 *
071 * @param columnName 値ãŒå‚ç…§ã•れるカラãƒ?
072 *
073 * @return æŒ?®šã•れãŸã‚»ãƒ«ã®ã‚«ãƒ©ãƒ?•ªå·ã€‚å˜åœ¨ã—ãªã‘れã°ã€?1
074 * @throws IllegalArgumentException 引数ã®ã‚«ãƒ©ãƒ?ã?null ã®å ´å?
075 */
076 public int getColumnNo( final String columnName ) {
077 if( columnName == null ) {
078 String errMsg = "引数ã®ã‚«ãƒ©ãƒ?ã«ã€null ã¯è¨å®šã§ãã¾ã›ã‚“ã€?;
079 throw new IllegalArgumentException( errMsg );
080 }
081
082 int address = -1;
083 for( int i=0; i<names.length; i++ ) {
084 if( columnName.equalsIgnoreCase( names[i] ) ) {
085 address = i;
086 break;
087 }
088 }
089
090 return address;
091 }
092
093 /**
094 * カラãƒ?é…å?ã«å¯¾å¿œã™ã‚?カラãƒ?•ªå·é…å?ã‚’è¿”ã—ã¾ã™ã?
095 *
096 * ã“れã¯ã€?getColumnNo( String ) ã«å¯¾ã™ã‚‹ è¤?•°ã®ã‚«ãƒ©ãƒ?を検索ã—ãŸ
097 * å ´åˆã¨åŒã˜ã§ã™ã?
098 *
099 * @param clmNms 値ãŒå‚ç…§ã•れるカラãƒ?é…å?
100 *
101 * @return æŒ?®šã•れãŸã‚»ãƒ«ã®ã‚«ãƒ©ãƒ?•ªå·é…å?ã€?
102 */
103 public int[] getColumnNos( final String[] clmNms ) {
104 if( clmNms == null ) {
105 return new int[0];
106 }
107
108 int[] clmNos = new int[clmNms.length];
109 for( int j=0; j<clmNms.length; j++ ) {
110 int address = -1;
111 for( int i=0; i<names.length; i++ ) {
112 if( clmNms[j].equalsIgnoreCase( names[i] ) ) {
113 address = i;
114 break;
115 }
116 }
117 clmNos[j] = address;
118 }
119
120 return clmNos;
121 }
122
123 /**
124 * カラãƒ?é…å?ã‚’è¿”ã—ã¾ã™ã?
125 *
126 * @return カラãƒ?é…å?
127 */
128 public String[] getNames() {
129 return names.clone();
130 }
131
132 /**
133 * row ã«ã‚るセルã®å±žæ?値をé?列ã§è¿”ã—ã¾ã™ã?
134 *
135 * @param row 値ãŒå‚ç…§ã•れるè¡?無視ã•れã¾ã?
136 *
137 * @return æŒ?®šã•れãŸã‚»ãƒ«ã®å±žæ?値
138 */
139 public String[] getValues( final int row ) {
140 return values.clone();
141 }
142
143 /**
144 * row ãŠã‚ˆã³ clm ã«ã‚るセルã®å±žæ?値をStringã«å¤‰æ›ã—ã¦è¿”ã—ã¾ã™ã?
145 *
146 * @param row 値ãŒå‚ç…§ã•れるè¡?無視ã•れã¾ã?
147 * @param clm 値ãŒå‚ç…§ã•れるå?
148 *
149 * @return æŒ?®šã•れãŸã‚»ãƒ«ã®å€¤
150 *
151 */
152 public String getValue( final int row, final int clm) {
153 return values[clm];
154 }
155
156 /**
157 * clm ã®Nativeタイプを返ã—ã¾ã™ã?
158 * Nativeタイプã?org.opengion.fukurou.model.NativeTypeã§å®šç¾©ã•れã¦ã?¾ã™ã?
159 *
160 * @og.rev 4.1.1.2 (2008/02/28) æ–°è¦è¿½åŠ?
161 * @og.rev 5.1.8.0 (2010/07/01) NativeType#getType(String) ã®ãƒ¡ã‚½ãƒ?ƒ‰ã‚’使用ã™ã‚‹ã‚ˆã†ã«å¤‰æ›´ã€?
162 *
163 * @param clm 値ãŒå‚ç…§ã•れるå?
164 *
165 * @return Nativeタイ�
166 * @see org.opengion.fukurou.model.NativeType
167 */
168 public NativeType getNativeType( final int clm ) {
169 // return StringUtil.getNativeType( values[clm] );
170 return NativeType.getType( values[clm] );
171 }
172 }