001    //$HeadURL: svn+ssh://developername@svn.wald.intevation.org/deegree/base/trunk/resources/eclipse/files_template.xml $
002    /*----------------------------------------------------------------------------
003     This file is part of deegree, http://deegree.org/
004     Copyright (C) 2001-2009 by:
005     - Department of Geography, University of Bonn -
006     and
007     - lat/lon GmbH -
008    
009     This library is free software; you can redistribute it and/or modify it under
010     the terms of the GNU Lesser General Public License as published by the Free
011     Software Foundation; either version 2.1 of the License, or (at your option)
012     any later version.
013     This library is distributed in the hope that it will be useful, but WITHOUT
014     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
015     FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
016     details.
017     You should have received a copy of the GNU Lesser General Public License
018     along with this library; if not, write to the Free Software Foundation, Inc.,
019     59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020    
021     Contact information:
022    
023     lat/lon GmbH
024     Aennchenstr. 19, 53177 Bonn
025     Germany
026     http://lat-lon.de/
027    
028     Department of Geography, University of Bonn
029     Prof. Dr. Klaus Greve
030     Postfach 1147, 53001 Bonn
031     Germany
032     http://www.geographie.uni-bonn.de/deegree/
033    
034     e-mail: info@deegree.org
035     ----------------------------------------------------------------------------*/
036    package org.deegree.tools.xml;
037    
038    import java.util.ArrayList;
039    import java.util.List;
040    
041    import org.deegree.framework.util.Pair;
042    import org.deegree.framework.util.StringTools;
043    import org.deegree.model.crs.CRSFactory;
044    import org.deegree.model.crs.CoordinateSystem;
045    import org.deegree.model.crs.UnknownCRSException;
046    
047    /**
048     * TODO add class documentation here
049     * 
050     * @author <a href="mailto:name@deegree.org">Andreas Poth</a>
051     * @author last edited by: $Author: admin $
052     * 
053     * @version $Revision: $, $Date: $
054     */
055    public class Table {
056    
057        private String select;
058    
059        private String name;
060    
061        private List<Table> tables = new ArrayList<Table>();
062    
063        private List<String> variables = new ArrayList<String>();
064    
065        private List<Pair<String, CoordinateSystem>> geometryColumns = new ArrayList<Pair<String, CoordinateSystem>>();
066    
067        /**
068         * 
069         * @param name
070         * @param select
071         * @throws UnknownCRSException
072         */
073        Table( String name, String select, List<Pair<String, String>> geometryColumns ) throws UnknownCRSException {
074            this.name = name;
075            this.select = select.trim();
076            String[] tmp = StringTools.toArray( select, " ", false );
077            for ( String value : tmp ) {
078                if ( value.startsWith( "$" ) ) {
079                    variables.add( value );
080                }
081            }
082            for ( Pair<String, String> pair : geometryColumns ) {
083                CoordinateSystem crs = CRSFactory.create( pair.second );
084                Pair<String, CoordinateSystem> p = new Pair<String, CoordinateSystem>( pair.first, crs );
085                this.geometryColumns.add( p );
086            }
087        }
088    
089        /**
090         * @return the select
091         */
092        public String getSelect() {
093            return select;
094        }
095    
096        /**
097         * @param select
098         *            the select to set
099         */
100        public void setSelect( String select ) {
101            this.select = select;
102        }
103    
104        /**
105         * @return the name
106         */
107        public String getName() {
108            return name;
109        }
110    
111        /**
112         * @param name
113         *            the name to set
114         */
115        public void setName( String name ) {
116            this.name = name;
117        }
118    
119        /**
120         * @return the tables
121         */
122        public List<Table> getTables() {
123            return tables;
124        }
125    
126        /**
127         * @return the variables
128         */
129        public List<String> getVariables() {
130            return variables;
131        }
132    
133        /**
134         * @return
135         */
136        public Pair<String, CoordinateSystem> getGeometryColumn( String field ) {
137            for ( Pair<String, CoordinateSystem> p : geometryColumns ) {
138                if ( p.first.equals( field ) ) {
139                    return p;
140                }
141            }
142            return null;
143        }
144    
145    }