comparison geo-backend/src/main/java/de/intevation/gnv/geobackend/sde/datasources/Row.java @ 129:110e3ac1b7d2

Library Dependencies Added to pom.xml-File Import of SDE-Datasources geo-backend/trunk@5 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Tim Englich <tim.englich@intevation.de>
date Wed, 02 Sep 2009 09:07:03 +0000
parents
children 031ef9649cd1
comparison
equal deleted inserted replaced
128:9b3f5a067c29 129:110e3ac1b7d2
1 /**
2 * Title: Row, $Header: /share/gdi/SDI-Suite/Repository/projekte/BSH-GDI/genericViewer/src/main/java/de/conterra/bsh/gdi/gnviewer/datasources/Row.java,v 1.4 2008/01/30 12:38:34 blume Exp $
3 * Source: $Source: /share/gdi/SDI-Suite/Repository/projekte/BSH-GDI/genericViewer/src/main/java/de/conterra/bsh/gdi/gnviewer/datasources/Row.java,v $
4 * created by: Stefan Blume (blume)
5 * erstellt am: 21.11.2007
6 * Copyright: con terra GmbH, 2005
7 *
8 * modified by: $Author: blume $
9 * modified on: $Date: 2008/01/30 12:38:34 $
10 * Version: $Revision: 1.4 $
11 * TAG: $Name: $
12 * locked from: $Locker: $
13 * CVS State: $State: Exp $
14 * Project: $ProjectName$
15 */
16 package de.intevation.gnv.geobackend.sde.datasources;
17
18 import java.util.ArrayList;
19 import java.util.Calendar;
20 import java.util.Date;
21
22 import org.apache.log4j.Logger;
23
24 import com.esri.sde.sdk.client.SDEPoint;
25 import com.esri.sde.sdk.client.SeException;
26 import com.esri.sde.sdk.client.SeShape;
27
28 import de.intevation.gnv.geobackend.sde.datasources.exception.TechnicalException;
29 import de.intevation.gnv.geobackend.util.DateUtils;
30
31 /**
32 * A Row represents a set of values.
33 * In a technical manner (e.g. database manner) a row contains all attributes of a single "hit".
34 *
35 * @author blume
36 * @version 1.0
37 * @serial 1.0
38 * @see
39 * @since 21.11.2007 11:00:54
40 */
41 public class Row {
42
43 /**
44 * Default Logging instance
45 */
46 private static Logger sLogger = Logger.getLogger(Row.class);
47 private static boolean sDebug = sLogger.isDebugEnabled();
48
49 /**
50 * Data container.
51 */
52 private Object[] mObjects;
53
54 /**
55 * Constructor.
56 *
57 * @param pRowSize the number of attributes contained by this row.
58 */
59 public Row(int pRowSize) {
60 mObjects = new Object[pRowSize];
61 }
62
63 /**
64 * Constructor.
65 *
66 * @param ArrayStr a line from CSV-File.
67 */
68 public Row (String[] ArrayStr){
69 this (ArrayStr.length);
70 int nLength = ArrayStr.length;
71 for (int i=0; i < nLength; i++){
72 //if (sDebug)
73 // sLogger.debug(" ArrayStr["+i+" ]=" + ArrayStr[i]);
74 addObject(ArrayStr[i], i);
75
76 }
77
78 }
79
80
81 /**
82 * Adds an attribute value to a specific position of this row.
83 *
84 * @param pObject the object to be stored.
85 * @param pPos the postion the value to be saved
86 */
87 public void addObject(Object pObject, int pPos) {
88 mObjects[pPos] = pObject;
89 }
90
91 /**
92 * Returns a Value out of the Row.
93 *
94 * @param pPos the position of the value to be returned.
95 * @return an Object! (not strongly typed)
96 * @throws TechnicalException
97 */
98 public Object getValue(int pPos) throws TechnicalException {
99 if (pPos < mObjects.length) {
100 return mObjects[pPos];
101 } else {
102 throw new TechnicalException("Cannot access this field position. Size is: " + mObjects.length);
103 }
104 }
105
106
107 /**
108 * This is a covenient method for getting strongly typed objects out of the row.
109 * It has to be ensured, that the type of the requested row position has been resolved out of the ColumnDefinition ({@link ResultSet#getColumnDefinitions()}).
110 * In fact, this method executes a simple cast to the desired type.
111 *
112 * @param pPos the position of the object to be resolved.
113 * @return a strongly typed Date
114 * @throws TechnicalException
115 * @see #getValue(int)
116 */
117 public Date getDateValue(int pPos) throws TechnicalException {
118 Date date = null;
119 try {
120 Calendar lCalendar = (Calendar) getValue(pPos);
121 date = lCalendar.getTime();
122 }
123 catch (ClassCastException e) {
124 try{
125 //SimpleDateFormat formatter = new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss");
126 date = DateUtils.getDateFromString ((String)getValue(pPos)); //(Date)formatter.parse((String)getValue(pPos));
127
128
129 }
130 catch (Exception ex){
131 sLogger.error(getValue(pPos) + " " + ex.getMessage(), ex);
132 throw new TechnicalException("Could not cast this value to the Date Type. Object is of value type: " + getValue(pPos).getClass().getName());
133 }
134 }
135
136 return date;
137 }
138
139 /**
140 * This is a covenient method for getting strongly typed objects out of the row.
141 * It has to be ensured, that the type of the requested row position has been resolved out of the ColumnDefinition ({@link ResultSet#getColumnDefinitions()}).
142 * In fact, this method executes a simple cast to the desired type.
143 *
144 * @param pPos the position of the object to be resolved.
145 * @return a strongly typed String
146 * @throws TechnicalException
147 * @see #getValue(int)
148 */
149 public String getStringValue(int pPos) throws TechnicalException {
150 try {
151 return (String) getValue(pPos);
152 } catch (ClassCastException e) {
153 throw new TechnicalException("Could not cast this value to the String Type. Object is of value type: " + getValue(pPos).getClass().getName());
154 }
155 }
156
157 /**
158 * This is a covenient method for getting strongly typed objects out of the row.
159 * It has to be ensured, that the type of the requested row position has been resolved out of the ColumnDefinition ({@link ResultSet#getColumnDefinitions()}).
160 * In fact, this method executes a simple cast to the desired type.
161 *
162 * @param pPos the position of the object to be resolved.
163 * @throws TechnicalException
164 * @see #getValue(int)
165 * * @return a strongly typed int
166 */
167 public int getIntValue(int pPos) throws TechnicalException {
168 try {
169 return (Integer) getValue(pPos);
170 } catch (ClassCastException e) {
171 throw new TechnicalException("Could not cast this value to the Integer Type. Object is of value type: " + getValue(pPos).getClass().getName());
172 }
173 }
174
175 /**
176 * This is a covenient method for getting strongly typed objects out of the row.
177 * It has to be ensured, that the type of the requested row position has been resolved out of the ColumnDefinition ({@link ResultSet#getColumnDefinitions()}).
178 * In fact, this method executes a simple cast to the desired type.
179 *
180 * @param pPos the position of the object to be resolved.
181 * @throws TechnicalException
182 * @see #getValue(int)
183 * * @return a strongly typed Double
184 */
185 public Double getDoubleValue(int pPos) throws TechnicalException {
186 try {
187 return (Double) getValue(pPos);
188 } catch (ClassCastException e) {
189 try{
190 return new Double ((String)getValue(pPos));
191 }
192 catch(Exception ex){
193 sLogger.error(getValue(pPos) + " " + ex.getMessage(), ex);
194 throw new TechnicalException("Could not cast this value to the Double Type. Object is of value type: " + getValue(pPos).getClass().getName());
195 }
196 }
197 }
198
199 /**
200 * This is a covenient method for getting strongly typed objects out of the row.
201 * It has to be ensured, that the type of the requested row position has been resolved out of the ColumnDefinition ({@link ResultSet#getColumnDefinitions()}).
202 * In fact, this method executes a simple cast to the desired type.
203 *
204 * @param pPos the position of the object to be resolved.
205 * @return a strongly typed Float
206 * @throws TechnicalException
207 * @see #getValue(int)
208 */
209 public Float getFloatValue(int pPos) throws TechnicalException {
210 try {
211 return (Float) getValue(pPos);
212 } catch (ClassCastException e) {
213 throw new TechnicalException("Could not cast this value to the Float Type. Object is of value type: " + getValue(pPos).getClass().getName());
214 }
215 }
216 /**
217 * This is a covenient method for getting strongly typed objects out of the row.
218 * It has to be ensured, that the type of the requested row position has been resolved out of the ColumnDefinition ({@link ResultSet#getColumnDefinitions()}).
219 * In fact, this method executes a simple cast to the desired type.
220 *
221 * @param pPos the position of the object to be resolved.
222 * @return a strongly typed Float
223 * @throws TechnicalException
224 * @see #getValue(int)
225 */
226 public String getPosValue(int pPos)throws TechnicalException{
227 SeShape val;
228 ArrayList aList;
229 SDEPoint mPoint[];
230 double lat,lon;
231 try {
232 val = (SeShape) getValue(pPos);
233 aList = val.getAllPoints(0,false);
234 mPoint = (SDEPoint[])aList.get(0);
235 lat = mPoint[0].getY();
236 lon = mPoint[0].getX();
237 String nord="N";
238 String ost="E";
239 if (lat <0 ){nord="S"; lat=-lat;}
240 if (lon <0 ){ost="W"; lon=-lon;}
241 return String.format("%1$02d°%2$1S %3$05.2f' %4$03d°%5$1S %6$05.2f'",
242 (int)lat, nord,60.*(lat-((int)lat)),(int)lon,ost,60.*(lon-((int)lon)));
243
244
245 } catch (SeException e) {
246 throw new TechnicalException("Could not cast this value to the Float Type. Object is of value type: " + getValue(pPos).getClass().getName());
247 }
248 }
249 }

http://dive4elements.wald.intevation.org