001 //$HeadURL: https://svn.wald.intevation.org/svn/deegree/base/branches/2.3_testing/src/org/deegree/ogcbase/PropertyPathFactory.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 package org.deegree.ogcbase;
037
038 import java.util.ArrayList;
039 import java.util.List;
040
041 import org.deegree.datatypes.QualifiedName;
042
043 /**
044 * Factory class for <code>PropertyPath</code> and <code>PropertyPathStep</code> instances.
045 *
046 * @author <a href="mailto:schneider@lat-lon.de">Markus Schneider </a>
047 *
048 * @author last edited by: $Author: mschneider $
049 *
050 * @version 2.0, $Revision: 18195 $, $Date: 2009-06-18 17:55:39 +0200 (Do, 18. Jun 2009) $
051 *
052 * @since 2.0
053 *
054 * @see PropertyPath
055 * @see PropertyPathStep
056 */
057 public class PropertyPathFactory {
058
059 /**
060 * Creates a new <code>PropertyPath</code> instance that consists of one element step.
061 *
062 * @param elementName
063 * name of selected element
064 * @return new <code>PropertyPath</code> instance
065 */
066 public static PropertyPath createPropertyPath( QualifiedName elementName ) {
067 List<PropertyPathStep> steps = new ArrayList<PropertyPathStep>();
068 steps.add( new ElementStep( elementName ) );
069 PropertyPath path = new PropertyPath( steps );
070 return path;
071 }
072
073 /**
074 * Creates a new <code>PropertyPath</code> instance that consists of a subset of the steps from the given
075 * <code>PropertyPath</code>.
076 *
077 * @param propertyPath
078 * original <code>PropertyPath</code>
079 * @param fromIndex
080 * index of the first step to be included
081 * @param toIndex
082 * index of the final step to be included
083 * @return new <code>PropertyPath</code> instance
084 */
085 public static PropertyPath createPropertyPath( PropertyPath propertyPath, int fromIndex, int toIndex ) {
086 if ( toIndex - fromIndex < 1 ) {
087 throw new IllegalArgumentException( "PropertyPath must contain at least one step." );
088 }
089 List<PropertyPathStep> steps = propertyPath.getAllSteps();
090 List<PropertyPathStep> newSteps = steps.subList( fromIndex, toIndex );
091 PropertyPath newPath = new PropertyPath( newSteps );
092 return newPath;
093 }
094
095 /**
096 * Creates a new <code>PropertyPath</code> instance with the specified steps.
097 *
098 * @param steps
099 * property path steps, may not be null
100 * @return new <code>PropertyPath</code> instance
101 */
102 public static PropertyPath createPropertyPath( List<PropertyPathStep> steps ) {
103 return new PropertyPath( steps );
104 }
105
106 /**
107 * Creates a new <code>PropertyPathStep</code> instance that selects the attribute with the given name.
108 *
109 * @param attrName
110 * attribute to be selected
111 * @return new <code>PropertyPathStep</code> instance
112 */
113 public static PropertyPathStep createAttributePropertyPathStep( QualifiedName attrName ) {
114 return new AttributeStep( attrName );
115 }
116
117 /**
118 * Creates a new <code>PropertyPathStep</code> instance that selects the element with the given name.
119 *
120 * @param elementName
121 * element to be selected
122 * @return new <code>PropertyPathStep</code> instance
123 */
124 public static PropertyPathStep createPropertyPathStep( QualifiedName elementName ) {
125 return new ElementStep( elementName );
126 }
127
128 /**
129 * Creates a new <code>PropertyPathStep</code> instance that selects the specified occurence of the element with
130 * the given name.
131 *
132 * @param elementName
133 * element to be selected
134 * @param selectedIndex
135 * occurence of the element
136 * @return new <code>PropertyPathStep</code> instance
137 */
138 public static PropertyPathStep createPropertyPathStep( QualifiedName elementName, int selectedIndex ) {
139 return new IndexStep( elementName, selectedIndex );
140 }
141
142 /**
143 * @return a new step which matches anything.
144 */
145 public static AnyStep createAnyStep() {
146 return new AnyStep( new QualifiedName( "*" ) );
147 }
148
149 /**
150 * @param index
151 * @return a new step which matches anything.
152 */
153 public static AnyStep createAnyStep( int index ) {
154 return new AnyStep( new QualifiedName( "*" ), index );
155 }
156
157 }