001    //$$HeadURL: svn+ssh://jwilden@svn.wald.intevation.org/deegree/base/branches/2.5_testing/src/org/deegree/io/datastore/sql/wherebuilder/FeaturePropertyNode.java $$
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    
037    package org.deegree.io.datastore.sql.wherebuilder;
038    
039    import java.util.ArrayList;
040    import java.util.Collection;
041    import java.util.Iterator;
042    
043    import org.deegree.io.datastore.schema.MappedFeaturePropertyType;
044    
045    /**
046     * Represents a {@link MappedFeaturePropertyType} as a node in a {@link QueryTableTree}.
047     *
048     * @author <a href="mailto:schneider@lat-lon.de">Markus Schneider </a>
049     * @author last edited by: $Author: mschneider $
050     *
051     * @version $Revision: 18195 $, $Date: 2009-06-18 17:55:39 +0200 (Do, 18 Jun 2009) $
052     */
053    class FeaturePropertyNode extends AbstractPropertyNode {
054    
055        private Collection<FeatureTypeNode> children = new ArrayList<FeatureTypeNode> ();
056    
057        /**
058         * Creates a new <code>FeaturePropertyNode</code> instance from the given parameters.
059         *
060         * @param property
061         *            the PropertyType that this FeaturePropertyNode represents
062         * @param parent
063         * @param tableAliases
064         *            the aliases for the tables that lead from the parent feature type node's table to
065         *            the table where the property's value is stored
066         */
067        FeaturePropertyNode( MappedFeaturePropertyType property, FeatureTypeNode parent,
068                            String[] tableAliases ) {
069            super( property, parent, tableAliases );
070        }
071    
072        /**
073         * Returns the children of this <code>FeaturePropertyNode</code>.
074         *
075         * @return the children of this FeaturePropertyNode.
076         */
077        public FeatureTypeNode[] getFeatureTypeNodes() {
078            return this.children.toArray( new FeatureTypeNode[this.children.size()] );
079        }
080    
081    
082        /**
083         * Adds a new child to this <code>FeaturePropertyNode</code>.
084         *
085         * @param newFeatureTypeNode child node to add
086         */
087        public void addFeatureTypeNode( FeatureTypeNode newFeatureTypeNode ) {
088            this.children.add(newFeatureTypeNode);
089        }
090    
091        @Override
092        public String toString( String indent ) {
093    
094            StringBuffer sb = new StringBuffer();
095            sb.append( indent );
096            sb.append( "+ " );
097            sb.append( this.getProperty().getName() );
098            sb.append( " (FeaturePropertyNode" );
099            if ( this.getTableAliases() != null ) {
100                for (int i = 0; i < this.getTableAliases().length; i++) {
101                    sb.append( " [" );
102                    sb.append( getPathFromParent()[i] );
103                    sb.append( " target alias: '" );
104                    sb.append( getTableAliases()[i] );
105                    sb.append( "'" );
106                    if ( i != this.getTableAliases().length - 1 ) {
107                        sb.append( ", " );
108                    } else {
109                        sb.append( "]" );
110                    }
111                }
112            }
113            sb.append( ")\n" );
114            Iterator<FeatureTypeNode> iter = this.children.iterator ();
115            while (iter.hasNext()) {
116                FeatureTypeNode child = iter.next ();
117                sb.append( child.toString( indent + "  " ) );
118            }
119            return sb.toString();
120        }
121    }