Stefano,

I do not know. This is a good observation. It is possible that this 
occurred during API change, and is just a mistake. It is also possible 
that this is some special functionality required to support multiple 
mappings of the same type, or some other cyclic dependency problem:
http://docs.geoserver.org/latest/en/user/data/app-schema/feature-chaining.html#multiple-mappings-of-the-same-type

If the latter, getFeatureSourceByName is confusingly named. Perhaps 
getFeatureSourceByElementName would be better? And the javadoc would 
need improvement.

What happens if getFeatureSource is removed and replaced by 
getFeatureSourceByName? (In the GeoTools build, GeoServer build, and 
GeoServer app-schema online tests.)

Kind regards,
Ben.

On 07/08/15 00:39, Stefano Costa wrote:
> Hi all,
> playing with the new GeoServer REST API for uploading app-schema
> mappings, I stumbled upon what might be an issue in app-schema's
> implementation of the DataAccess interface, AppSchemaDataAccess:
> https://github.com/geotools/geotools/blob/master/modules/extension/app-schema/app-schema/src/main/java/org/geotools/data/complex/AppSchemaDataAccess.java
>
>
> The following is the body of the "List<Name> getNames()" method:
>
> /**
>   * Return the names of the target features.
>   *
>   * @see org.geotools.data.DataAccess#getNames()
>   */
> public List<Name> getNames() {
>      List<Name> names = new LinkedList<Name>();
>      names.addAll(mappings.keySet());
>      return names;
> }
>
> The returned names are taken from the "mappings" hash map: this implies
> that, if a feature type mapping defines a "mappingName", that is
> returned; otherwise, the mapping's "targetElement" is returned.
>
> In contrast, the "FeatureSource getFeatureSource(Name typeName)" method
> is implemented thus:
>
> return new MappingFeatureSource(this, getMappingByElement(typeName));
>
> Here is the relevant part of the "getMappingByElement(Name typeName)"
> method:
>
> for (FeatureTypeMapping mapping : mappings.values()) {
>      if (mapping.getTargetFeature().getName().equals(typeName)) {
>          return mapping;
>      }
> }
>
> The provided "typeName" is not used as hash key in the mappings map, but
> rather compared to the mapped feature's
> "targetElement" (mapping.getTargetFeature().getName()), so the lookup
> will find nothing when a "mappingName" is specified in the type's
> mapping configuration.
>
> I noticed AppSchemaDataAccess provides another getFeatureSource* method,
> "getFeatureSourceByName(Name typeName)", which does the right thing (in
> my opinion) and:
>
>   "Returns a feature source that can be used to obtain features of a
> particular name. This name would be the mappingName in the TypeMapping
> if it exists, otherwise it's the target element name"
>
> as the JavaDoc puts it. However, this method is not part of the
> DataAccess interface, so client code like the following, written against
> the DataAccess interface, will fail when at least one type mapping
> defines a "mappingName":
>
> DataAccess source = ...; // obtain AppSchemaDataAccess somehow
> List<Name> featureTypeNames = source.getNames();
> for ( int i = 0; i < featureTypeNames.size(); i++ ) {
>      // will throw 'mappingName not found' exception!
>      FeatureSource fs = source.getFeatureSource(featureTypeNames.get(i));
> }
>
> I was wondering why an alternative method, getFeatureSourceByName(Name),
> was created, instead of making it the one and only getFeature(Name)
> method?
>
>

-- 
Ben Caradoc-Davies <[email protected]>
Director
Transient Software Limited <http://transient.nz/>
New Zealand

------------------------------------------------------------------------------
_______________________________________________
GeoTools-Devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-devel

Reply via email to