001: package org.geotools.feature.iso.simple;
002:
003: import java.util.ArrayList;
004: import java.util.Collection;
005: import java.util.Iterator;
006: import java.util.List;
007: import java.util.Set;
008:
009: import org.geotools.feature.iso.Descriptors;
010: import org.geotools.feature.iso.Types;
011: import org.geotools.feature.iso.type.FeatureTypeImpl;
012: import org.opengis.feature.simple.SimpleFeatureType;
013: import org.opengis.feature.type.AttributeDescriptor;
014: import org.opengis.feature.type.AttributeType;
015: import org.opengis.feature.type.GeometryType;
016: import org.opengis.feature.type.Name;
017: import org.opengis.referencing.crs.CoordinateReferenceSystem;
018: import org.opengis.util.InternationalString;
019:
020: /**
021: * Implementation fo SimpleFeatureType, subtypes must be atomic and are stored
022: * in a list.
023: *
024: * @author Justin
025: */
026: public class SimpleFeatureTypeImpl extends FeatureTypeImpl implements
027: SimpleFeatureType {
028:
029: // list of types
030: List types = null;
031:
032: public SimpleFeatureTypeImpl(Name name, Collection schema,
033: AttributeDescriptor defaultGeometry,
034: CoordinateReferenceSystem crs,
035: Set/* <Filter> */restrictions,
036: InternationalString description) {
037: super (name, new ArrayList(schema), defaultGeometry, crs, false,
038: restrictions, null, description);
039: }
040:
041: public SimpleFeatureTypeImpl(Name name, List typeList,
042: AttributeType geometryType, CoordinateReferenceSystem crs,
043: Set restrictions, InternationalString description) {
044: this (name, SimpleFeatureFactoryImpl.descriptors(typeList),
045: SimpleFeatureFactoryImpl.geometryName(geometryType),
046: crs, restrictions, description);
047: types = typeList;
048: }
049:
050: private SimpleFeatureTypeImpl(Name name, List list, Name geomName,
051: CoordinateReferenceSystem crs, Set restrictions,
052: InternationalString description) {
053: this (name, list, SimpleFeatureFactoryImpl.find(list, geomName),
054: crs, restrictions, description);
055: }
056:
057: public AttributeType get(Name qname) {
058: return Descriptors.type(SCHEMA, qname);
059: }
060:
061: public AttributeType getType(String name) {
062: return get(Types.typeName(name));
063: }
064:
065: public AttributeType getType(int index) {
066: return (AttributeType) getTypes().get(index);
067: }
068:
069: public int indexOf(String arg0) {
070: int index = 0;
071: for (Iterator itr = SCHEMA.iterator(); itr.hasNext(); index++) {
072: AttributeDescriptor descriptor = (AttributeDescriptor) itr
073: .next();
074: if (name.equals(descriptor.getName().getLocalPart())) {
075: return index;
076: }
077: }
078: return -1;
079: }
080:
081: /**
082: * Number of available attributes
083: */
084: public int getNumberOfAttribtues() {
085: return SCHEMA.size();
086: }
087:
088: /**
089: * Types are returned in the perscribed index order.
090: *
091: * @return Types in prescribed order
092: */
093: public List /* List<AttributeType> */getTypes() {
094: if (types == null) {
095: synchronized (this ) {
096: if (types == null) {
097: types = new ArrayList();
098: for (Iterator itr = SCHEMA.iterator(); itr
099: .hasNext();) {
100: AttributeDescriptor ad = (AttributeDescriptor) itr
101: .next();
102: types.add(ad.type());
103: }
104: }
105: }
106: }
107:
108: return types;
109: }
110:
111: public GeometryType getDefaultGeometryType() {
112: AttributeDescriptor desc = getDefaultGeometry();
113: if (desc != null)
114: return (GeometryType) desc.type();
115:
116: return null;
117: }
118:
119: public AttributeDescriptor getAttribute(String name) {
120: // TODO Auto-generated method stub
121: return null;
122: }
123:
124: public AttributeDescriptor getAttribute(int index) {
125: return (AttributeDescriptor) ((List) SCHEMA).get(index);
126: }
127:
128: public int getAttributeCount() {
129: return SCHEMA.size();
130: }
131:
132: public List getAttributes() {
133: return (List) SCHEMA;
134: }
135:
136: }
|