Search in sources :

Example 1 with FeatureAssociation

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);
    }
}
Also used : FeatureAssociation(org.opengis.feature.FeatureAssociation) Attribute(org.opengis.feature.Attribute) Feature(org.opengis.feature.Feature)

Example 2 with FeatureAssociation

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];
}
Also used : FeatureAssociation(org.opengis.feature.FeatureAssociation) AttributeType(org.opengis.feature.AttributeType) PropertyType(org.opengis.feature.PropertyType) Operation(org.opengis.feature.Operation) FeatureAssociationRole(org.opengis.feature.FeatureAssociationRole)

Example 3 with FeatureAssociation

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;
    }
}
Also used : FeatureAssociation(org.opengis.feature.FeatureAssociation) Attribute(org.opengis.feature.Attribute) Operation(org.opengis.feature.Operation)

Example 4 with FeatureAssociation

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());
            }
        }
    }
}
Also used : GeneralParameterValue(org.opengis.parameter.GeneralParameterValue) FeatureAssociation(org.opengis.feature.FeatureAssociation) ParameterValue(org.opengis.parameter.ParameterValue) GeneralParameterValue(org.opengis.parameter.GeneralParameterValue) ParameterValueGroup(org.opengis.parameter.ParameterValueGroup) DefaultAttributeType(org.apache.sis.feature.DefaultAttributeType) AttributeType(org.opengis.feature.AttributeType) ParameterDescriptorGroup(org.opengis.parameter.ParameterDescriptorGroup) PropertyType(org.opengis.feature.PropertyType) FeatureAssociationRole(org.opengis.feature.FeatureAssociationRole) Feature(org.opengis.feature.Feature) ArrayFeature(org.geotoolkit.internal.feature.ArrayFeature) FactoryException(org.opengis.util.FactoryException) BackingStoreException(org.apache.sis.util.collection.BackingStoreException) PropertyNotFoundException(org.opengis.feature.PropertyNotFoundException)

Example 5 with FeatureAssociation

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;
}
Also used : FeatureAssociation(org.opengis.feature.FeatureAssociation) Fake(org.geotoolkit.filter.binding.JaxenFeatureNavigator.Fake) Attribute(org.opengis.feature.Attribute) JaxenException(org.jaxen.JaxenException) Iterator(java.util.Iterator) Collection(java.util.Collection) Property(org.opengis.feature.Property)

Aggregations

FeatureAssociation (org.opengis.feature.FeatureAssociation)5 Attribute (org.opengis.feature.Attribute)3 AttributeType (org.opengis.feature.AttributeType)2 Feature (org.opengis.feature.Feature)2 FeatureAssociationRole (org.opengis.feature.FeatureAssociationRole)2 Operation (org.opengis.feature.Operation)2 PropertyType (org.opengis.feature.PropertyType)2 Collection (java.util.Collection)1 Iterator (java.util.Iterator)1 DefaultAttributeType (org.apache.sis.feature.DefaultAttributeType)1 BackingStoreException (org.apache.sis.util.collection.BackingStoreException)1 Fake (org.geotoolkit.filter.binding.JaxenFeatureNavigator.Fake)1 ArrayFeature (org.geotoolkit.internal.feature.ArrayFeature)1 JaxenException (org.jaxen.JaxenException)1 Property (org.opengis.feature.Property)1 PropertyNotFoundException (org.opengis.feature.PropertyNotFoundException)1 GeneralParameterValue (org.opengis.parameter.GeneralParameterValue)1 ParameterDescriptorGroup (org.opengis.parameter.ParameterDescriptorGroup)1 ParameterValue (org.opengis.parameter.ParameterValue)1 ParameterValueGroup (org.opengis.parameter.ParameterValueGroup)1