*
* @param element
* @return 0 for a perfect match,
*/
public int matches( Object element ) {
SimpleFeatureType schema = null;
if (element instanceof SimpleFeature) {
schema = ((SimpleFeature) element).getFeatureType();
} else if (element instanceof SimpleFeatureType) {
schema = (SimpleFeatureType) element;
} else if(element instanceof IAdaptable) {
IAdaptable adaptable = (IAdaptable) element;
if(adaptable.getAdapter(SimpleFeatureType.class) != null) {
schema = (SimpleFeatureType) adaptable.getAdapter(SimpleFeatureType.class);
} else if(adaptable.getAdapter(SimpleFeature.class) != null) {
schema = ((SimpleFeature) adaptable.getAdapter(SimpleFeatureType.class)).getFeatureType();
}
}
if (schema != null) {
Name featureName = schema.getName();
if (namespace != null) {
if (namespace.compareTo(URI.create(featureName.getNamespaceURI())) == 0
&& typeName.equals(featureName.getLocalPart())) {
return PERFECT;
}
return NO_MATCH;
}
if (attributes.length == 0) {
return NO_MATCH;
}
int accuracy = 0;
accuracy++;
List<AttributeDescriptor> matched = new ArrayList<AttributeDescriptor>();
// 1st pass check all named attributes are accounted for
for( AttributeMatcher current : attributes ) {
if (current.name == null) {
continue; // skip
}
AttributeDescriptor currentMatch = current.match(schema, matched);
if (currentMatch == null) {
return NO_MATCH;
}
matched.add(currentMatch);
}
// section pass check unnamed attributes ... match default geometry type?
for( AttributeMatcher current : attributes ) {
if (current.name != null) {
continue;
}
accuracy++;
AttributeDescriptor currentMatch = current.match(schema, matched);
if (currentMatch == null) {
return NO_MATCH;
}
matched.add(currentMatch);
}
accuracy += schema.getAttributeCount() - matched.size();
return accuracy;
}
return NO_MATCH;
}