use of org.opengis.feature.FeatureAssociation in project geotoolkit by Geomatys.
the class XPathBinding method set.
@Override
public void set(final C candidate, final String xpath, final Object value) throws IllegalArgumentException {
final Object obj = get(candidate, xpath, Property.class);
if (obj instanceof Attribute) {
final Attribute prop = (Attribute) obj;
prop.setValue(value);
} else if (obj instanceof FeatureAssociation) {
final FeatureAssociation prop = (FeatureAssociation) obj;
prop.setValue((Feature) value);
} else {
throw new IllegalArgumentException("Can not set value for xpath : " + xpath);
}
}
use of org.opengis.feature.FeatureAssociation in project geotoolkit by Geomatys.
the class DefaultArrayFeature method getProperty.
@Override
public Property getProperty(String name) throws IllegalArgumentException {
final int idx = getIndex(name);
if (properties[idx] == null) {
final PropertyType pt = getType().getProperty(name);
if (pt instanceof Operation) {
final Operation op = (Operation) pt;
return op.apply(this, op.getParameters().createValue());
} else if (pt instanceof AttributeType) {
properties[idx] = ((AttributeType) pt).newInstance();
((Attribute) properties[idx]).setValue(values[idx]);
} else if (pt instanceof FeatureAssociationRole) {
properties[idx] = ((FeatureAssociationRole) pt).newInstance();
((FeatureAssociation) properties[idx]).setValue((Feature) values[idx]);
}
}
return properties[idx];
}
use of org.opengis.feature.FeatureAssociation in project geotoolkit by Geomatys.
the class DefaultArrayFeature method setPropertyValue.
@Override
public void setPropertyValue(int index, Object value) {
if (values[index] instanceof Operation) {
final Operation op = (Operation) values[index];
setOperationValue(op.getName().toString(), value);
} else if (properties[index] instanceof Attribute) {
((Attribute) properties[index]).setValue(value);
} else if (properties[index] instanceof FeatureAssociation) {
((FeatureAssociation) properties[index]).setValue((Feature) value);
} else {
values[index] = value;
}
}
use of org.opengis.feature.FeatureAssociation in project geotoolkit by Geomatys.
the class FeatureExt method fill.
private static void fill(final ParameterValueGroup source, final Feature target) {
final ParameterDescriptorGroup paramdesc = source.getDescriptor();
for (final PropertyType desc : target.getType().getProperties(true)) {
if (desc instanceof FeatureAssociationRole) {
final FeatureAssociationRole assRole = (FeatureAssociationRole) desc;
try {
final List<ParameterValueGroup> groups = source.groups(desc.getName().tip().toString());
if (groups != null) {
for (ParameterValueGroup gr : groups) {
final FeatureAssociation att = assRole.newInstance();
final Feature val = assRole.getValueType().newInstance();
att.setValue(val);
fill(gr, val);
target.setProperty(att);
}
}
} catch (Exception ex) {
// parameter might not exist of might be a group
}
} else if (desc instanceof AttributeType) {
final AttributeType at = (AttributeType) desc;
final String code = desc.getName().tip().toString();
final GeneralParameterValue gpv = searchParameter(source, code);
if (gpv instanceof ParameterValue) {
target.setPropertyValue(code, ((ParameterValue) gpv).getValue());
}
}
}
}
use of org.opengis.feature.FeatureAssociation 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