001    //$$HeadURL: svn+ssh://rbezema@svn.wald.intevation.org/deegree/base/tags/2.1/src/org/deegree/io/datastore/sql/wherebuilder/FeaturePropertyNode.java $$
002    /*----------------    FILE HEADER  ------------------------------------------
003     This file is part of deegree.
004     Copyright (C) 2001-2006 by:
005     Department of Geography, University of Bonn
006     http://www.giub.uni-bonn.de/deegree/
007     lat/lon GmbH
008     http://www.lat-lon.de
009    
010     This library is free software; you can redistribute it and/or
011     modify it under the terms of the GNU Lesser General Public
012     License as published by the Free Software Foundation; either
013     version 2.1 of the License, or (at your option) any later version.
014    
015     This library is distributed in the hope that it will be useful,
016     but WITHOUT ANY WARRANTY; without even the implied warranty of
017     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
018     Lesser General Public License for more details.
019    
020     You should have received a copy of the GNU Lesser General Public
021     License along with this library; if not, write to the Free Software
022     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
023    
024     Contact:
025    
026     Andreas Poth
027     lat/lon GmbH
028     Aennchenstraße 19
029     53177 Bonn
030     Germany
031     E-Mail: poth@lat-lon.de
032    
033     Jens Fitzke
034     lat/lon GmbH
035     Aennchenstraße 19
036     53177 Bonn
037     Germany
038     E-Mail: jens.fitzke@uni-bonn.de
039     ---------------------------------------------------------------------------*/
040    
041    package org.deegree.io.datastore.sql.wherebuilder;
042    
043    import java.util.ArrayList;
044    import java.util.Collection;
045    import java.util.Iterator;
046    
047    import org.deegree.io.datastore.schema.MappedFeaturePropertyType;
048    
049    /**
050     * Represents a {@link MappedFeaturePropertyType} as a node in a {@link QueryTableTree}.
051     * 
052     * @author <a href="mailto:schneider@lat-lon.de">Markus Schneider </a>
053     * @author last edited by: $Author: mschneider $
054     * 
055     * @version $Revision: 7106 $, $Date: 2007-05-14 13:26:27 +0200 (Mo, 14 Mai 2007) $
056     */
057    class FeaturePropertyNode extends AbstractPropertyNode {
058    
059        private Collection<FeatureTypeNode> children = new ArrayList<FeatureTypeNode> ();
060    
061        /**
062         * Creates a new <code>FeaturePropertyNode</code> instance from the given parameters.
063         * 
064         * @param property
065         *            the PropertyType that this FeaturePropertyNode represents
066         * @param parent
067         * @param tableAliases
068         *            the aliases for the tables that lead from the parent feature type node's table to
069         *            the table where the property's value is stored
070         */
071        FeaturePropertyNode( MappedFeaturePropertyType property, FeatureTypeNode parent,
072                            String[] tableAliases ) {
073            super( property, parent, tableAliases );
074        }
075    
076        /**
077         * Returns the children of this <code>FeaturePropertyNode</code>.
078         * 
079         * @return the children of this FeaturePropertyNode.
080         */
081        public FeatureTypeNode[] getFeatureTypeNodes() {
082            return this.children.toArray( new FeatureTypeNode[this.children.size()] );
083        }    
084    
085    
086        /**
087         * Adds a new child to this <code>FeaturePropertyNode</code>.
088         * 
089         * @param newFeatureTypeNode child node to add
090         */
091        public void addFeatureTypeNode( FeatureTypeNode newFeatureTypeNode ) {
092            this.children.add(newFeatureTypeNode);
093        }    
094        
095        @Override
096        public String toString( String indent ) {
097    
098            StringBuffer sb = new StringBuffer();
099            sb.append( indent );
100            sb.append( "+ " );
101            sb.append( this.getProperty().getName() );
102            sb.append( " (FeaturePropertyNode" );
103            if ( this.getTableAliases() != null ) {
104                for (int i = 0; i < this.getTableAliases().length; i++) {
105                    sb.append( " [" );
106                    sb.append( getPathFromParent()[i] );
107                    sb.append( " target alias: '" );
108                    sb.append( getTableAliases()[i] );
109                    sb.append( "'" );
110                    if ( i != this.getTableAliases().length - 1 ) {
111                        sb.append( ", " );
112                    } else {
113                        sb.append( "]" );
114                    }
115                }
116            }
117            sb.append( ")\n" );
118            Iterator iter = this.children.iterator ();
119            while (iter.hasNext()) {
120                FeatureTypeNode child = (FeatureTypeNode) iter.next ();
121                sb.append( child.toString( indent + "  " ) );    
122            }        
123            return sb.toString();
124        }
125    }