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 org.geotools.feature.GeometryAttributeType;
020: import org.geotools.feature.IllegalAttributeException;
021: import org.opengis.feature.type.AttributeDescriptor;
022: import org.opengis.feature.type.AttributeType;
023: import org.opengis.feature.type.GeometryType;
024: import org.opengis.feature.type.Name;
025: import org.opengis.filter.Filter;
026: import org.opengis.referencing.crs.CoordinateReferenceSystem;
027:
028: import com.vividsolutions.jts.geom.GeometryFactory;
029:
030: /**
031: * Adapts an ISO simple AttributeType to a GeoTools AttributeType
032: *
033: * @author Gabriel Roldan, Axios Engineering
034: * @version $Id: GTAttributeTypeAdapter.java 28577 2008-01-03 15:44:29Z groldan $
035: * @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/GTAttributeTypeAdapter.java $
036: * @since 2.4
037: */
038: public class GTAttributeTypeAdapter implements
039: org.geotools.feature.AttributeType {
040:
041: protected Name name;
042:
043: protected AttributeDescriptor adaptee;
044:
045: /**
046: * Protected constructor, use
047: * {@link #adapter(String, org.geotools.feature.AttributeType)} to create an
048: * appropriate instance for your geotools attribute type.
049: *
050: * @param nsUri
051: * @param gtType
052: */
053: protected GTAttributeTypeAdapter(AttributeDescriptor descriptor) {
054: this .adaptee = descriptor;
055: }
056:
057: public Class getBinding() {
058: return ((AttributeType) adaptee.type()).getBinding();
059: }
060:
061: private static class GTGeometryTypeAdapter extends
062: GTAttributeTypeAdapter implements GeometryAttributeType {
063:
064: GeometryType type;
065:
066: public GTGeometryTypeAdapter(AttributeDescriptor descriptor) {
067: super (descriptor);
068: type = (GeometryType) descriptor.type();
069: }
070:
071: public CoordinateReferenceSystem getCoordinateSystem() {
072: return type.getCRS();
073: }
074:
075: public GeometryFactory getGeometryFactory() {
076: return null;
077: }
078:
079: public boolean isGeometry() {
080: return true;
081: }
082:
083: }
084:
085: public static org.geotools.feature.AttributeType adapter(
086: AttributeDescriptor adaptee) {
087: org.geotools.feature.AttributeType attType;
088: if (adaptee.type() instanceof GeometryType) {
089: attType = new GTGeometryTypeAdapter(adaptee);
090: } else {
091: attType = new GTAttributeTypeAdapter(adaptee);
092: }
093: return attType;
094: }
095:
096: public Object createDefaultValue() {
097: return null;
098: }
099:
100: public Object duplicate(Object src)
101: throws IllegalAttributeException {
102: throw new UnsupportedOperationException("duplicate");
103: }
104:
105: public int getMaxOccurs() {
106: return adaptee.getMaxOccurs();
107: }
108:
109: public int getMinOccurs() {
110: return adaptee.getMinOccurs();
111: }
112:
113: public String getName() {
114: return getLocalName();
115: }
116:
117: public String getLocalName() {
118: return adaptee.getName().getLocalPart();
119: }
120:
121: public Filter getRestriction() {
122: return null;
123: }
124:
125: public Class getType() {
126: return ((AttributeType) adaptee.type()).getBinding();
127: }
128:
129: public boolean isNillable() {
130: return adaptee.isNillable();
131: }
132:
133: public Object parse(Object value) throws IllegalArgumentException {
134: return value;
135: }
136:
137: public void validate(Object obj) throws IllegalArgumentException {
138: // TODO Auto-generated method stub
139: }
140:
141: }
|