use of org.geotoolkit.filter.binding.JaxenFeatureNavigator.Fake in project geotoolkit by Geomatys.
the class XPathBinding method get.
// @Override
// public boolean canHandle(final Class type, final String xpath, final Class target) {
//
// if(xpath == null || xpath.isEmpty()){
// return false;
// }
//
// if (!ComplexAttribute.class.isAssignableFrom(type)
// && !PropertyType.class.isAssignableFrom(type)
// && !PropertyDescriptor.class.isAssignableFrom(type)) {
// return false; // we only work with complex types.
// }
//
// return true;
// }
@Override
public <T> T get(C candidate, String path, Class<T> target) throws IllegalArgumentException {
if (candidate == null)
return null;
try {
final JaxenFeatureXPath xpath = JaxenFeatureXPath.create(path);
Object v = xpath.evaluate(candidate);
if (v instanceof Fake) {
v = ((Fake) v).value;
}
if (v instanceof Collection) {
// several property for this path
final Collection properties = (Collection) v;
if (target != null && target.isInstance(properties)) {
return (T) properties;
} else {
final Iterator ite = properties.iterator();
if (ite.hasNext()) {
v = ite.next();
}
}
}
if (v instanceof Fake && Property.class.isAssignableFrom(target)) {
v = ((Fake) v).value;
}
if (v instanceof Property) {
// extract value from property if necessary
final Property prop = (Property) v;
if (target != null && target.isInstance(prop)) {
return (T) prop;
} else {
if (prop instanceof Attribute && ((Attribute) prop).getType().getMaximumOccurs() > 1) {
v = ((Attribute) prop).getValues();
} else if (prop instanceof FeatureAssociation && ((FeatureAssociation) prop).getRole().getMaximumOccurs() > 1) {
v = ((FeatureAssociation) prop).getValues();
} else {
v = prop.getValue();
}
}
}
if (target == null) {
return (T) v;
} else {
return ObjectConverters.convert(v, target);
}
} catch (JaxenException ex) {
Logger.getLogger("org.geotoolkit.filter.binding").log(Level.WARNING, null, ex);
}
return null;
}
Aggregations