001 //$HeadURL: svn+ssh://rbezema@svn.wald.intevation.org/deegree/base/branches/2.2_testing/src/org/deegree/ogcbase/PropertyPathFactory.java $ 002 /*---------------- FILE HEADER ------------------------------------------ 003 004 This file is part of deegree. 005 Copyright (C) 2001-2008 by: 006 EXSE, Department of Geography, University of Bonn 007 http://www.giub.uni-bonn.de/deegree/ 008 lat/lon GmbH 009 http://www.lat-lon.de 010 011 This library is free software; you can redistribute it and/or 012 modify it under the terms of the GNU Lesser General Public 013 License as published by the Free Software Foundation; either 014 version 2.1 of the License, or (at your option) any later version. 015 016 This library is distributed in the hope that it will be useful, 017 but WITHOUT ANY WARRANTY; without even the implied warranty of 018 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 019 Lesser General Public License for more details. 020 021 You should have received a copy of the GNU Lesser General Public 022 License along with this library; if not, write to the Free Software 023 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 024 025 Contact: 026 027 Andreas Poth 028 lat/lon GmbH 029 Aennchenstraße 19 030 53177 Bonn 031 Germany 032 E-Mail: poth@lat-lon.de 033 034 Prof. Dr. Klaus Greve 035 Department of Geography 036 University of Bonn 037 Meckenheimer Allee 166 038 53115 Bonn 039 Germany 040 E-Mail: greve@giub.uni-bonn.de 041 042 ---------------------------------------------------------------------------*/ 043 package org.deegree.ogcbase; 044 045 import java.util.ArrayList; 046 import java.util.List; 047 048 import org.deegree.datatypes.QualifiedName; 049 050 /** 051 * Factory class for <code>PropertyPath</code> and <code>PropertyPathStep</code> instances. 052 * 053 * @author <a href="mailto:schneider@lat-lon.de">Markus Schneider </a> 054 * 055 * @author last edited by: $Author: apoth $ 056 * 057 * @version 2.0, $Revision: 9344 $, $Date: 2007-12-27 17:21:56 +0100 (Do, 27 Dez 2007) $ 058 * 059 * @since 2.0 060 * 061 * @see PropertyPath 062 * @see PropertyPathStep 063 */ 064 public class PropertyPathFactory { 065 066 /** 067 * Creates a new <code>PropertyPath</code> instance that consists of one element step. 068 * 069 * @param elementName 070 * name of selected element 071 * @return new <code>PropertyPath</code> instance 072 */ 073 public static PropertyPath createPropertyPath (QualifiedName elementName) { 074 List<PropertyPathStep> steps = new ArrayList<PropertyPathStep> (); 075 steps.add (new ElementStep (elementName)); 076 PropertyPath path = new PropertyPath (steps); 077 return path; 078 } 079 080 /** 081 * Creates a new <code>PropertyPath</code> instance that consists of a subset of the steps 082 * from the given <code>PropertyPath</code>. 083 * 084 * @param propertyPath 085 * original <code>PropertyPath</code> 086 * @param fromIndex 087 * index of the first step to be included 088 * @param toIndex 089 * index of the final step to be included 090 * @return new <code>PropertyPath</code> instance 091 */ 092 public static PropertyPath createPropertyPath( PropertyPath propertyPath, int fromIndex, int toIndex ) { 093 if (toIndex - fromIndex < 1) { 094 throw new IllegalArgumentException ("PropertyPath must contain at least one step."); 095 } 096 List<PropertyPathStep> steps = propertyPath.getAllSteps(); 097 List<PropertyPathStep> newSteps = steps.subList(fromIndex, toIndex); 098 PropertyPath newPath = new PropertyPath (newSteps); 099 return newPath; 100 } 101 102 /** 103 * Creates a new <code>PropertyPath</code> instance with the specified steps. 104 * 105 * @param steps 106 * property path steps, may not be null 107 * @return new <code>PropertyPath</code> instance 108 */ 109 public static PropertyPath createPropertyPath ( List<PropertyPathStep> steps ) { 110 return new PropertyPath (steps); 111 } 112 113 /** 114 * Creates a new <code>PropertyPathStep</code> instance that selects the attribute with the 115 * given name. 116 * 117 * @param attrName 118 * attribute to be selected 119 * @return new <code>PropertyPathStep</code> instance 120 */ 121 public static PropertyPathStep createAttributePropertyPathStep (QualifiedName attrName) { 122 return new AttributeStep (attrName); 123 } 124 125 /** 126 * Creates a new <code>PropertyPathStep</code> instance that selects the element with the 127 * given name. 128 * 129 * @param elementName 130 * element to be selected 131 * @return new <code>PropertyPathStep</code> instance 132 */ 133 public static PropertyPathStep createPropertyPathStep (QualifiedName elementName) { 134 return new ElementStep (elementName); 135 } 136 137 /** 138 * Creates a new <code>PropertyPathStep</code> instance that selects the specified occurence 139 * of the element with the given name. 140 * 141 * @param elementName 142 * element to be selected 143 * @param selectedIndex 144 * occurence of the element 145 * @return new <code>PropertyPathStep</code> instance 146 */ 147 public static PropertyPathStep createPropertyPathStep (QualifiedName elementName, int selectedIndex) { 148 return new IndexStep (elementName, selectedIndex); 149 } 150 151 }