diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/geo-backend/src/main/java/de/intevation/gnv/geobackend/sde/datasources/Row.java	Wed Sep 02 09:07:03 2009 +0000
@@ -0,0 +1,249 @@
+/**
+ * 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 $
+ * Source:          $Source: /share/gdi/SDI-Suite/Repository/projekte/BSH-GDI/genericViewer/src/main/java/de/conterra/bsh/gdi/gnviewer/datasources/Row.java,v $
+ * created by:      Stefan Blume (blume)
+ * erstellt am:     21.11.2007
+ * Copyright:       con terra GmbH, 2005
+ *
+ * modified by:     $Author: blume $
+ * modified on:     $Date: 2008/01/30 12:38:34 $
+ * Version:         $Revision: 1.4 $
+ * TAG:             $Name:  $
+ * locked from:     $Locker:  $
+ * CVS State:       $State: Exp $
+ * Project:         $ProjectName$
+ */
+package de.intevation.gnv.geobackend.sde.datasources;
+
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Date;
+
+import org.apache.log4j.Logger;
+
+import com.esri.sde.sdk.client.SDEPoint;
+import com.esri.sde.sdk.client.SeException;
+import com.esri.sde.sdk.client.SeShape;
+
+import de.intevation.gnv.geobackend.sde.datasources.exception.TechnicalException;
+import de.intevation.gnv.geobackend.util.DateUtils;
+
+/**
+ * A Row represents a set of values.
+ * In a technical manner (e.g. database manner) a row contains all attributes of a single "hit".
+ *
+ * @author blume
+ * @version 1.0
+ * @serial 1.0
+ * @see
+ * @since 21.11.2007 11:00:54
+ */
+public class Row {
+
+    /**
+     * Default Logging instance
+     */
+    private static Logger sLogger = Logger.getLogger(Row.class);
+    private static boolean sDebug = sLogger.isDebugEnabled();
+
+    /**
+     * Data container.
+     */
+    private Object[] mObjects;
+
+    /**
+     * Constructor.
+     *
+     * @param pRowSize the number of attributes contained by this row.
+     */
+    public Row(int pRowSize) {
+        mObjects = new Object[pRowSize];
+    }
+    
+    /**
+     * Constructor.
+     *
+     * @param ArrayStr a line from CSV-File.
+     */
+    public Row (String[] ArrayStr){
+    	this (ArrayStr.length);
+    	int nLength = ArrayStr.length;
+    	for (int i=0; i < nLength; i++){
+    		//if (sDebug)
+    		//	sLogger.debug(" ArrayStr["+i+" ]=" + ArrayStr[i]);
+    		addObject(ArrayStr[i], i);
+    		
+    	}	
+    	
+    }
+    
+    
+    /**
+     * Adds an attribute value to a specific position of this row.
+     *
+     * @param pObject the object to be stored.
+     * @param pPos    the postion the value to be saved
+     */
+    public void addObject(Object pObject, int pPos) {
+        mObjects[pPos] = pObject;
+    }
+
+    /**
+     * Returns a Value out of the Row.
+     *
+     * @param pPos the position of the value to be returned.
+     * @return an Object! (not strongly typed)
+     * @throws TechnicalException
+     */
+    public Object getValue(int pPos) throws TechnicalException {
+        if (pPos < mObjects.length) {
+            return mObjects[pPos];
+        } else {
+            throw new TechnicalException("Cannot access this field position. Size is: " + mObjects.length);
+        }
+    }
+
+
+    /**
+     * This is a covenient method for getting strongly typed objects out of the row.
+     * It has to be ensured, that the type of the requested row position has been resolved out of the ColumnDefinition ({@link ResultSet#getColumnDefinitions()}).
+     * In fact, this method executes a simple cast to the desired type.
+     *
+     * @param pPos the position of the object to be resolved.
+     * @return a strongly typed Date
+     * @throws TechnicalException
+     * @see #getValue(int)
+     */
+    public Date getDateValue(int pPos) throws TechnicalException {
+    	Date date =  null;
+        try {
+            Calendar lCalendar = (Calendar) getValue(pPos);
+            date = lCalendar.getTime();
+        } 
+        catch (ClassCastException e) {
+        	try{
+        		//SimpleDateFormat formatter = new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss");
+        		date = DateUtils.getDateFromString ((String)getValue(pPos)); //(Date)formatter.parse((String)getValue(pPos));
+        	    
+        		
+        	}
+        	catch (Exception ex){
+        		sLogger.error(getValue(pPos) + " " + ex.getMessage(), ex);
+        		throw new TechnicalException("Could not cast this value to the Date Type. Object is of value type: " + getValue(pPos).getClass().getName());
+        	}
+        }	
+      
+        return date;
+    }
+
+    /**
+     * This is a covenient method for getting strongly typed objects out of the row.
+     * It has to be ensured, that the type of the requested row position has been resolved out of the ColumnDefinition ({@link ResultSet#getColumnDefinitions()}).
+     * In fact, this method executes a simple cast to the desired type.
+     *
+     * @param pPos the position of the object to be resolved.
+     * @return a strongly typed String
+     * @throws TechnicalException
+     * @see #getValue(int)
+     */
+    public String getStringValue(int pPos) throws TechnicalException {
+        try {
+            return (String) getValue(pPos);
+        } catch (ClassCastException e) {
+            throw new TechnicalException("Could not cast this value to the String Type. Object is of value type: " + getValue(pPos).getClass().getName());
+        }
+    }
+
+    /**
+     * This is a covenient method for getting strongly typed objects out of the row.
+     * It has to be ensured, that the type of the requested row position has been resolved out of the ColumnDefinition ({@link ResultSet#getColumnDefinitions()}).
+     * In fact, this method executes a simple cast to the desired type.
+     *
+     * @param pPos the position of the object to be resolved.
+     * @throws TechnicalException
+     * @see #getValue(int)
+     *      * @return a strongly typed int
+     */
+    public int getIntValue(int pPos) throws TechnicalException {
+        try {
+            return (Integer) getValue(pPos);
+        } catch (ClassCastException e) {
+            throw new TechnicalException("Could not cast this value to the Integer Type. Object is of value type: " + getValue(pPos).getClass().getName());
+        }
+    }
+
+    /**
+     * This is a covenient method for getting strongly typed objects out of the row.
+     * It has to be ensured, that the type of the requested row position has been resolved out of the ColumnDefinition ({@link ResultSet#getColumnDefinitions()}).
+     * In fact, this method executes a simple cast to the desired type.
+     *
+     * @param pPos the position of the object to be resolved.
+     * @throws TechnicalException
+     * @see #getValue(int)
+     *      * @return a strongly typed Double
+     */
+    public Double getDoubleValue(int pPos) throws TechnicalException {
+        try {
+            return (Double) getValue(pPos);
+        } catch (ClassCastException e) {
+        	try{
+        		return new Double ((String)getValue(pPos));
+        	}
+        	catch(Exception ex){
+        		sLogger.error(getValue(pPos) + " " + ex.getMessage(), ex);
+        		throw new TechnicalException("Could not cast this value to the Double Type. Object is of value type: " + getValue(pPos).getClass().getName());
+        	}
+        }
+    }
+
+    /**
+     * This is a covenient method for getting strongly typed objects out of the row.
+     * It has to be ensured, that the type of the requested row position has been resolved out of the ColumnDefinition ({@link ResultSet#getColumnDefinitions()}).
+     * In fact, this method executes a simple cast to the desired type.
+     *
+     * @param pPos the position of the object to be resolved.
+     * @return a strongly typed Float
+     * @throws TechnicalException
+     * @see #getValue(int)
+     */
+    public Float getFloatValue(int pPos) throws TechnicalException {
+        try {
+            return (Float) getValue(pPos);
+        } catch (ClassCastException e) {
+            throw new TechnicalException("Could not cast this value to the Float Type. Object is of value type: " + getValue(pPos).getClass().getName());
+        }
+    }
+    /**
+     * This is a covenient method for getting strongly typed objects out of the row.
+     * It has to be ensured, that the type of the requested row position has been resolved out of the ColumnDefinition ({@link ResultSet#getColumnDefinitions()}).
+     * In fact, this method executes a simple cast to the desired type.
+     *
+     * @param pPos the position of the object to be resolved.
+     * @return a strongly typed Float
+     * @throws TechnicalException
+     * @see #getValue(int)
+     */    
+    public String getPosValue(int pPos)throws TechnicalException{
+    	SeShape val;
+    	ArrayList aList;
+    	SDEPoint mPoint[];
+    	double lat,lon;
+    	try {
+    		val = (SeShape) getValue(pPos);
+    		aList = val.getAllPoints(0,false);
+    		mPoint = (SDEPoint[])aList.get(0);
+    		lat = mPoint[0].getY();
+    		lon = mPoint[0].getX();
+    		String nord="N";
+    		String ost="E";
+    		if (lat <0 ){nord="S"; lat=-lat;}
+    		if (lon <0 ){ost="W"; lon=-lon;}
+    		return String.format("%1$02d°%2$1S %3$05.2f' %4$03d°%5$1S %6$05.2f'",
+    				              (int)lat, nord,60.*(lat-((int)lat)),(int)lon,ost,60.*(lon-((int)lon)));
+    				              
+
+        } catch (SeException e) {
+            throw new TechnicalException("Could not cast this value to the Float Type. Object is of value type: " + getValue(pPos).getClass().getName());   
+        }
+    }
+}

http://dive4elements.wald.intevation.org