/* * GeoTools - The Open Source Java GIS Toolkit * http://geotools.org * * (C) 2002-2008, Open Source Geospatial Foundation (OSGeo) * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; * version 2.1 of the License. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. */ package org.geotools.feature.type; import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; import java.util.List; import java.util.logging.Logger; import org.geotools.feature.NameImpl; import org.opengis.feature.type.AttributeDescriptor; import org.opengis.feature.type.AttributeType; import org.opengis.feature.type.ComplexType; import org.opengis.feature.type.Name; /** * Helper methods for dealing with Descriptor. *

* This methods opperate directly on the interfaces provided by geoapi, no * actual classes were harmed in the making of these utility methods. *

* * @author Jody Garnett * @author Justin Deoliveira * * @since 2.5 * * * * @source $URL$ */ public class Descriptors { private static final Logger LOGGER = org.geotools.util.logging.Logging.getLogger(Descriptors.class.getPackage().getName()); /** * Wraps a list of {@link AttributeType} in {@link AttributeDescriptor}. * * @param typeList The list of attribute types. * @return The list of attribute descriptors. * * @see #wrapAttributeType(AttributeType) */ public final static List wrapAttributeTypes( List/**/ typeList ){ List descriptors = new ArrayList( typeList.size() ); for( Iterator i = typeList.iterator(); i.hasNext(); ){ AttributeType attributeType = (AttributeType) i.next(); descriptors.add( wrapAttributeType(attributeType)); } return descriptors; } /** * Wraps a {@link AttributeType} in {@link AttributeDescriptor}. * * @param type The attribute type. * @return The attribute descriptor. */ public final static AttributeDescriptor wrapAttributeType( AttributeType type ) { if ( type == null ) { return null; } return new AttributeDescriptorImpl(type, type.getName(), 1,1,true,null ); } /** * Returns the attribute descriptor from a list which matches the specified * name, or null if no such descriptor is found. * * @param descriptors The list of {@link AttributeDescriptor}. * @param name The name to match. * * @return The matching attribute descriptor, or null. */ public final static AttributeDescriptor find( List descriptors, Name name ){ if( name == null ) return null; for( Iterator i = descriptors.iterator(); i.hasNext(); ){ AttributeDescriptor attributeType = (AttributeDescriptor) i.next(); if( name.equals( attributeType.getType().getName() ) ){ return attributeType; } } return null; // no default geometry here? } // /** // * Handle subtyping in a "sensible" manner. // *

// * We explored using the XMLSchema of extention and restriction, and have // * instead opted for the traditional Java lanaguage notion of an override. // *

// * The concept of an overrided allows both: // *