/** * Returns the underlying resource for a feature type, caching the result. * * <p>In the event that the resource is not in the cache the associated data store resource is * loaded, and the feature type resource obtained. During loading the underlying feature type * resource is "wrapped" to take into account feature type name aliasing and reprojection. * * @param info The feature type metadata. * @throws IOException Any errors that occure while loading the resource. */ public FeatureType getFeatureType(FeatureTypeInfo info) throws IOException { return getFeatureType(info, true); }
final SimpleFeatureType nativeFeatureType = dataStore.getSchema(typeName); final SimpleFeatureType renamedFeatureType = (SimpleFeatureType) getFeatureType(info, false); if (!typeName.equals(alias) || DataUtilities.compare(nativeFeatureType, renamedFeatureType) != 0) { SimpleFeatureType schema = (SimpleFeatureType) getFeatureType(info); try { if (!CRS.equalsIgnoreMetadata(resultCRS, schema.getCoordinateReferenceSystem()))
public FeatureType getFeatureType() throws IOException { return catalog.getResourcePool().getFeatureType(this); }
/** * Loads an attribute descriptor from feature type and attribute type metadata. * * <p>This method returns null if the attribute descriptor could not be loaded. */ public AttributeDescriptor getAttributeDescriptor( FeatureTypeInfo ftInfo, AttributeTypeInfo atInfo) throws Exception { FeatureType featureType = getFeatureType(ftInfo); if (featureType != null) { for (PropertyDescriptor pd : featureType.getDescriptors()) { if (pd instanceof AttributeDescriptor) { AttributeDescriptor ad = (AttributeDescriptor) pd; if (atInfo.getName().equals(ad.getLocalName())) { return ad; } } } } return null; }
/** * Test that the {@link FeatureType} cache returns the same instance every time. This is assumed * by some nasty code in other places that tampers with the CRS. If a new {@link FeatureType} is * constructed for the same {@link FeatureTypeInfo}, Bad Things Happen (TM). */ @Test public void testFeatureTypeCacheInstance() throws Exception { ResourcePool pool = ResourcePool.create(getCatalog()); FeatureTypeInfo info = getCatalog() .getFeatureTypeByName( MockData.LAKES.getNamespaceURI(), MockData.LAKES.getLocalPart()); FeatureType ft1 = pool.getFeatureType(info); FeatureType ft2 = pool.getFeatureType(info); FeatureType ft3 = pool.getFeatureType(info); assertSame(ft1, ft2); assertSame(ft1, ft3); }
public List<AttributeTypeInfo> loadAttributes(FeatureTypeInfo info) throws IOException { List<AttributeTypeInfo> attributes = new ArrayList(); FeatureType ft = getFeatureType(info); for (PropertyDescriptor pd : ft.getDescriptors()) { AttributeTypeInfo att = catalog.getFactory().createAttribute(); att.setFeatureType(info); att.setName(pd.getName().getLocalPart()); att.setMinOccurs(pd.getMinOccurs()); att.setMaxOccurs(pd.getMaxOccurs()); att.setNillable(pd.isNillable()); att.setBinding(pd.getType().getBinding()); int length = FeatureTypes.getFieldLength(pd); if (length > 0) { att.setLength(length); } attributes.add(att); } return attributes; }
@Test public void testCacheClearing() throws IOException { cleared = false; ResourcePool pool = new ResourcePool(getCatalog()) { @Override public void clear(FeatureTypeInfo info) { cleared = true; super.clear(info); } }; FeatureTypeInfo info = getCatalog() .getFeatureTypeByName( MockData.LAKES.getNamespaceURI(), MockData.LAKES.getLocalPart()); assertNotNull(pool.getFeatureType(info)); info.setTitle("changed"); assertFalse(cleared); getCatalog().save(info); assertTrue(cleared); cleared = false; assertNotNull(pool.getFeatureType(info)); for (LayerInfo l : getCatalog().getLayers(info)) { getCatalog().remove(l); } getCatalog().remove(info); assertTrue(cleared); }
final FeatureType featureType = resourcePool.getFeatureType(typeInfo); org.opengis.feature.type.PropertyDescriptor pd = featureType.getDescriptor(attribute.getName()); String typeName = "?";
final ResourcePool resourcePool = GeoServerApplication.get().getCatalog().getResourcePool(); final FeatureType featureType = resourcePool.getFeatureType(typeInfo); org.opengis.feature.type.PropertyDescriptor pd = featureType.getDescriptor(attribute.getName());