/** * Retrieve prefix set. * * @see org.geotools.data.Catalog#getPrefixes() * * @return Set of namespace prefixes * @throws IOException */ public Set getPrefixes() throws IOException { Set prefix = new HashSet(); for( Iterator i=featuresources.values().iterator(); i.hasNext();){ FeatureSource fs = (FeatureSource) i.next(); FeatureType schema = fs.getSchema(); prefix.add( schema.getNamespace().toString() ); } return prefix; } private SortedSet typeNames() throws IOException {
/** * Retrieve prefix set. * * @see org.geotools.data.Catalog#getPrefixes() * * @return Set of namespace prefixes * @throws IOException */ public Set getPrefixes() throws IOException { Set prefix = new HashSet(); for( Iterator i=datastores.values().iterator(); i.hasNext();){ DataStore ds = (DataStore) i.next(); for( Iterator t = types( ds ).values().iterator(); t.hasNext();){ FeatureType schema = (FeatureType) t.next(); prefix.add( schema.getNamespace().toString() ); } } return prefix; } private SortedSet typeNames( DataStore ds ) throws IOException {
/** * Test to determine whether this FeatureType is descended from the given * FeatureType. Think of this relationship likes the "extends" * relationship in java. * * @param nsURI The namespace URI to use. * @param typeName1 The typeName. * * @return true if descendant, false otherwise. * * @task HACK: if nsURI is null only typeName is tested. */ public boolean isDescendedFrom(URI nsURI, String typeName1) { for (int i = 0, ii = ancestors.length; i < ii; i++) { if (((nsURI == null) || ancestors[i].getNamespace().equals(nsURI)) && ancestors[i].getTypeName().equals(typeName1)) { return true; } } return false; }
/** Quick check of namespace and typename */ public static boolean equalsId( FeatureType typeA, FeatureType typeB ) { if (typeA == typeB) return true; if (typeA == null || typeB == null) { return false; } String typeNameA = typeA.getTypeName(); String typeNameB = typeB.getTypeName(); if (typeNameA == null && typeNameB != null) return false; else if (!typeNameA.equals(typeNameB)) return false; URI namespaceA = typeA.getNamespace(); URI namespaceB = typeB.getNamespace(); if (namespaceA == null && namespaceB != null) return false; else if (!namespaceA.equals(namespaceB)) return false; return true; }
public Element encode(Object object, Document document, Element value) throws Exception { Feature feature = (Feature) object; FeatureType featureType = feature.getFeatureType(); String namespace = featureType.getNamespace().toString(); String typeName = featureType.getTypeName(); Element encoding = document.createElementNS(namespace, typeName); encoding.setAttributeNS(GML.NAMESPACE, "id", feature.getID()); return encoding; }
/** * A convenience method for calling<br> * <code> FeatureType f1; FeatureType f2; * f1.isDescendedFrom(f2.getNamespace(),f2.getName()); </code> * * @param type The type to compare to. * * @return true if descendant, false otherwise. */ public boolean isDescendedFrom(FeatureType type) { return isDescendedFrom(type.getNamespace(), type.getTypeName()); }
/** * A convenience method for calling<br> * <code> FeatureType f1; FeatureType f2; * f1.isDescendedFrom(f2.getNamespace(),f2.getName()); </code> * * @param type The type to compare to. * * @return true if descendant, false otherwise. */ public boolean isDescendedFrom(FeatureType type) { return isDescendedFrom(type.getNamespace(), type.getTypeName()); }
public boolean equals(FeatureType other) { if(other == this) return true; if (other == null) { return false; } if ((typeName == null) && (other.getTypeName() != null)) { return false; } else if (!typeName.equals(other.getTypeName())) { return false; } if ((namespace == null) && (other.getNamespace() != null)) { return false; } else if (!namespace.equals(other.getNamespace())) { return false; } if (types.length != other.getAttributeCount()) { return false; } for (int i = 0, ii = types.length; i < ii; i++) { if (!types[i].equals(other.getAttributeType(i))) { return false; } } return true; }
TEST: for( int i = 0; i < ancestors.length; i++ ) { FeatureType ancestor = ancestors[i]; if (namespace != null && !namespace.equals(ancestor.getNamespace())) { continue TEST;
public boolean canHandle(Object object) { try { if (!(object instanceof Feature) || object instanceof FeatureCollection) return false; Feature f = (Feature) object; FeatureTypeInfo info = catalog.getFeatureTypeInfo(f .getFeatureType().getTypeName(), f.getFeatureType() .getNamespace().toString()); return info != null && info.getFeatureSource() instanceof VersioningFeatureSource; } catch (Exception e) { LOGGER .log( Level.FINE, "Error occurred trying to determine versioning status of a feature type", e); return false; } }
/** * Encode the supplied feature type. * * @param type the feature type to encode * * @throws RuntimeException DOCUMENT ME! */ protected void encode(FeatureType type) { AttributeType[] attributes = type.getAttributeTypes(); try { startSchemaType(type.getTypeName(), type.getNamespace()); for (int i = 0; i < attributes.length; i++) { encode(attributes[i]); } endSchemaType(); } catch (SAXException e) { throw new RuntimeException(e); } }
public FeatureType getSchema(String typeName) throws IOException { FeatureType ft = wrapped.getSchema(typeName); if(!isVersioned(typeName)) { return ft; } // if the feature type is versioned, we have to map the internal feature // type to an outside vision where versioned and pk columns are not // included Set names = new HashSet(Arrays.asList(filterPropertyNames(new DefaultQuery(typeName)))); List filtered = new ArrayList(); for (int i = 0; i < ft.getAttributeCount(); i++) { AttributeType cat = ft.getAttributeType(i); String name = cat.getName().toLowerCase(); if (names.contains(name)) { filtered.add(cat); } } AttributeType[] ats = (AttributeType[]) filtered .toArray(new AttributeType[filtered.size()]); try { return FeatureTypeBuilder.newFeatureType(ats, ft.getTypeName(), ft.getNamespace(), ft .isAbstract(), ft.getAncestors(), ft.getDefaultGeometry()); } catch (SchemaException e) { throw new DataSourceException( "Error converting FeatureType from versioned (internal) schema " + "to unversioned (external) schema " + typeName, e); } }
featureType.getNamespace().equals( namespace ); if( namespace == null ) namespace = featureType.getNamespace();
/** * DOCUMENT ME! * * @param featureType DOCUMENT ME! * @param properties DOCUMENT ME! * * @return DOCUMENT ME! * * @throws SchemaException DOCUMENT ME! */ public static FeatureType createSubType(FeatureType featureType, String[] properties) throws SchemaException { if (properties == null) { return featureType; } boolean same = featureType.getAttributeCount() == properties.length; for (int i = 0; (i < featureType.getAttributeCount()) && same; i++) { same = featureType.getAttributeType(i).getName().equals(properties[i]); } if (same) { return featureType; } AttributeType[] types = new AttributeType[properties.length]; for (int i = 0; i < properties.length; i++) { types[i] = featureType.getAttributeType(properties[i]); } return FeatureTypeFactory.newFeatureType(types, featureType.getTypeName(), featureType.getNamespace()); }
builder.setNamespace(original.getNamespace()); builder.setDefaultGeometry(original.getGeometryDescriptor());
builder.setNamespace(original.getNamespace()); builder.setDefaultGeometry(original.getDefaultGeometry());
if ( Utilities.equals(superType.getNamespace(),nsURI) && Utilities.equals(superType.getTypeName(), typeName1)) { return true;
public FeatureCollection getVersionedFeatures(Query query) throws IOException { final FeatureType ft = getSchema(); // check the feature type is the right one final String typeName = ft.getTypeName(); if(query.getTypeName() != null && !query.getTypeName().equals(typeName)) throw new IOException("Incompatible type, this class can access only " + typeName); // make sure the view is around if(!Arrays.asList(store.wrapped.getTypeNames()).contains(store.getVFCViewName(typeName))) store.createVersionedFeatureCollectionView(typeName); // we have to hit the view DefaultQuery vq = new DefaultQuery(query); vq.setTypeName(VersionedPostgisDataStore.getVFCViewName(typeName)); vq = store.buildVersionedQuery(vq); FeatureCollection fc = store.wrapped.getFeatureSource(VersionedPostgisDataStore.getVFCViewName(typeName)).getFeatures(vq); try { final FeatureType fcSchema = fc.getSchema(); FeatureType renamedFt = FeatureTypes.newFeatureType(fcSchema.getAttributeTypes(), ft.getTypeName(), ft.getNamespace(), ft.isAbstract(), ft.getAncestors(), fcSchema.getDefaultGeometry()); return new ReTypingFeatureCollection(fc, renamedFt); } catch(SchemaException e) { throw new DataSourceException("Error ranming feature type", e); } }
public void testFixture() throws Exception { FeatureType type = DataUtilities.createType("namespace.typename", "name:String,id:0,geom:MultiLineString"); assertEquals("namespace", new URI("namespace"), type.getNamespace()); assertEquals("typename", "typename", type.getTypeName()); assertEquals("attributes", 3, type.getAttributeCount()); AttributeType[] a = type.getAttributeTypes(); assertEquals("a1", "name", a[0].getName()); assertEquals("a1", String.class, a[0].getType()); assertEquals("a2", "id", a[1].getName()); assertEquals("a2", Integer.class, a[1].getType()); assertEquals("a3", "geom", a[2].getName()); assertEquals("a3", MultiLineString.class, a[2].getType()); }
FeatureTypeFactory factory = FeatureTypeFactory.newInstance(schema.getTypeName()); factory.setNamespace(schema.getNamespace()); factory.setName(schema.getTypeName());