001: /*
002: * Geotools2 - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2005-2006, GeoTools Project Managment Committee (PMC)
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation;
009: * version 2.1 of the License.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: */
017: package org.geotools.data.feature.adapter;
018:
019: import java.util.Collection;
020: import java.util.List;
021: import java.util.Set;
022:
023: import org.geotools.feature.GeometryAttributeType;
024: import org.geotools.feature.iso.TypeBuilder;
025: import org.geotools.feature.iso.Types;
026: import org.geotools.feature.iso.type.TypeFactoryImpl;
027: import org.opengis.feature.simple.SimpleFeatureType;
028: import org.opengis.feature.type.AttributeDescriptor;
029: import org.opengis.feature.type.AttributeType;
030: import org.opengis.feature.type.FeatureType;
031: import org.opengis.feature.type.GeometryType;
032: import org.opengis.feature.type.Name;
033: import org.opengis.feature.type.TypeFactory;
034: import org.opengis.referencing.crs.CoordinateReferenceSystem;
035: import org.opengis.util.InternationalString;
036:
037: /**
038: * Adapts a GeoTools FeatureType to an ISO SimpleFeatureType
039: *
040: * @author Gabriel Roldan, Axios Engineering
041: * @version $Id: ISOFeatureTypeAdapter.java 27002 2007-09-17 03:01:53Z jdeolive $
042: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/unsupported/community-schemas/community-schema-ds/src/main/java/org/geotools/data/feature/adapter/ISOFeatureTypeAdapter.java $
043: * @since 2.4
044: */
045: public class ISOFeatureTypeAdapter implements FeatureType,
046: SimpleFeatureType {
047:
048: private org.geotools.feature.FeatureType type;
049:
050: private FeatureType isoType;
051:
052: public ISOFeatureTypeAdapter(
053: org.geotools.feature.FeatureType featureType) {
054: if (featureType instanceof GTFeatureTypeAdapter) {
055: throw new IllegalArgumentException(
056: "No need to adapt GTFeatureTypeAdapter, use getAdaptee() instead");
057: }
058: this .type = featureType;
059:
060: String nsUri = type.getNamespace() == null ? null : type
061: .getNamespace().toString();
062:
063: org.geotools.feature.AttributeType[] types = type
064: .getAttributeTypes();
065:
066: TypeFactory tf = new TypeFactoryImpl();
067: TypeBuilder builder = new TypeBuilder(tf);
068:
069: for (int i = 0; i < types.length; i++) {
070: org.geotools.feature.AttributeType gtType = types[i];
071:
072: AttributeType attType = ISOAttributeTypeAdapter.adapter(
073: nsUri, gtType);
074:
075: Name name = Types.typeName(nsUri, attType.getName()
076: .getLocalPart());
077: builder.addAttribute(name, attType);
078: }
079: builder.defaultGeometry(featureType.getDefaultGeometry()
080: .getName());
081: builder.setName(type.getTypeName());
082: isoType = builder.feature();
083: }
084:
085: public org.geotools.feature.FeatureType getAdaptee() {
086: return type;
087: }
088:
089: public Name getName() {
090: String ns = type.getNamespace() == null ? null : type
091: .getNamespace().toString();
092: String localName = type.getTypeName();
093: Name name = Types.typeName(ns, localName);
094: return name;
095: }
096:
097: public Object getUserData(Object key) {
098: return null;
099: }
100:
101: public void putUserData(Object key, Object data) {
102: // do nothing
103: }
104:
105: public CoordinateReferenceSystem getCRS() {
106: GeometryAttributeType defGeom = type.getDefaultGeometry();
107: return defGeom == null ? null : defGeom.getCoordinateSystem();
108: }
109:
110: public AttributeDescriptor getDefaultGeometry() {
111: AttributeDescriptor defaultGeometry = isoType
112: .getDefaultGeometry();
113: return defaultGeometry;
114: }
115:
116: public Collection associations() {
117: return isoType.associations();
118: }
119:
120: public Collection attributes() {
121: return isoType.attributes();
122: }
123:
124: public Class getBinding() {
125: return isoType.getBinding();
126: }
127:
128: public Collection getProperties() {
129: return isoType.getProperties();
130: }
131:
132: public boolean isInline() {
133: return isoType.isInline();
134: }
135:
136: public Collection getOperations() {
137: return isoType.getOperations();
138: }
139:
140: public Set getRestrictions() {
141: return isoType.getRestrictions();
142: }
143:
144: public AttributeType getSuper() {
145: return isoType.getSuper();
146: }
147:
148: public boolean isAbstract() {
149: return false;
150: }
151:
152: public boolean isIdentified() {
153: return true;
154: }
155:
156: public InternationalString getDescription() {
157: return null;
158: }
159:
160: public GeometryType getDefaultGeometryType() {
161: return ((SimpleFeatureType) isoType).getDefaultGeometryType();
162: }
163:
164: public AttributeType get(Name name) {
165: return getType(name.getLocalPart());
166: }
167:
168: public AttributeType getType(String name) {
169: int index = type.find(name);
170: return getType(index);
171: }
172:
173: public AttributeType getType(int index) {
174: return ((SimpleFeatureType) isoType).getType(index);
175: }
176:
177: public int getAttributeCount() {
178: return type.getAttributeCount();
179: }
180:
181: public int indexOf(String name) {
182: return type.find(name);
183: }
184:
185: public List getTypes() {
186: return ((SimpleFeatureType) isoType).getTypes();
187: }
188:
189: public AttributeDescriptor getAttribute(String name) {
190: throw new UnsupportedOperationException("not implemented yet");
191: }
192:
193: public AttributeDescriptor getAttribute(int indedx) {
194: throw new UnsupportedOperationException("not implemented yet");
195: }
196:
197: public List getAttributes() {
198: throw new UnsupportedOperationException("not implemented yet");
199: }
200:
201: }
|