public PropertyName property(String name) { return new AttributeExpressionImpl(name); }
public void testSetupAndExtraction() throws Exception { // this should move out to a more configurable system run from scripts // but we can start with a set of hard coded tests SimpleFeature[] f = sampleFeatures(); AttributeExpressionImpl e1 = new AttributeExpressionImpl(schema, "value"); AttributeExpressionImpl e2 = new AttributeExpressionImpl(schema, "name"); assertEquals(12d, ((Integer) e1.evaluate(f[0])).doubleValue(), 0); assertEquals(3d, ((Integer) e1.evaluate(f[1])).doubleValue(), 0); assertEquals(15d, ((Integer) e1.evaluate(f[2])).doubleValue(), 0); assertEquals("first", (String) e2.evaluate(f[0])); assertEquals("second", (String) e2.evaluate(f[1])); } }
+ isEqual + "; in:" + expAttr.getPropertyName() + "; out:" + this.attPath);
public PropertyName property(String name) { AttributeExpressionImpl att = new AttributeExpressionImpl(name); att.setLenient(false); return att; } }
new AttributeExpressionImpl( "eg:simpleAttribute", new Hints(FeaturePropertyAccessorFactory.NAMESPACE_CONTEXT, NAMESPACES)); assertEquals(simpleAttribute, ex.evaluate(feature)); new AttributeExpressionImpl( "eg:complexAttribute", new Hints(FeaturePropertyAccessorFactory.NAMESPACE_CONTEXT, NAMESPACES)); assertEquals(complexAttribute, ex.evaluate(feature)); new AttributeExpressionImpl( "eg:complexAttribute/eg:rootAttribute", new Hints(FeaturePropertyAccessorFactory.NAMESPACE_CONTEXT, NAMESPACES)); Object o = ex.evaluate(feature); assertTrue(o instanceof List); assertEquals(3, ((List) o).size()); new AttributeExpressionImpl( "eg:complexAttribute/eg:rootAttribute/eg:singleLeafAttribute", new Hints(FeaturePropertyAccessorFactory.NAMESPACE_CONTEXT, NAMESPACES)); o = ex.evaluate(feature); assertTrue(o instanceof List); assertEquals(3, ((List) o).size()); new AttributeExpressionImpl( "eg:complexAttribute/eg:rootAttribute[1]", new Hints(FeaturePropertyAccessorFactory.NAMESPACE_CONTEXT, NAMESPACES));
/** * Gets the value of this property from the passed object. * * @param obj Object from which we need to extract a property value. */ public Object evaluate(Object obj) { return evaluate(obj, null); }
AttributeExpressionImpl expAttr = (AttributeExpressionImpl) obj; boolean isEqual = (expAttr.getType() == this.expressionType); if(LOGGER.isLoggable(Level.FINEST)) LOGGER.finest("expression type match:" + isEqual + "; in:" + expAttr.getType() + "; out:" + this.expressionType); isEqual = (expAttr.attPath != null) ? (isEqual && expAttr.attPath.equals(this.attPath)) if(LOGGER.isLoggable(Level.FINEST)) LOGGER.finest("attribute match:" + isEqual + "; in:" + expAttr.getAttributePath() + "; out:" + this.attPath); isEqual = (expAttr.schema != null) ? (isEqual && expAttr.schema.equals(this.schema))
/** * Constructor with schema and path to the attribute. * * @param schema The initial (required) sub filter. * @param attPath the xpath to the attribute. * * @throws IllegalFilterException If the attribute path is not in the * schema. */ protected AttributeExpressionImpl(SimpleFeatureType schema, String attPath) throws IllegalFilterException { this.schema = schema; this.expressionType = ATTRIBUTE; setAttributePath(attPath); }
AttributeExpressionImpl ex = new AttributeExpressionImpl("eg:simpleAttribute", new Hints( FeaturePropertyAccessorFactory.NAMESPACE_CONTEXT, NAMESPACES)); assertEquals(simpleAttribute, ex.evaluate(feature)); ex = new AttributeExpressionImpl("eg:complexAttribute", new Hints( FeaturePropertyAccessorFactory.NAMESPACE_CONTEXT, NAMESPACES)); assertEquals(complexAttribute, ex.evaluate(feature)); ex = new AttributeExpressionImpl("eg:complexAttribute/eg:rootAttribute", new Hints( FeaturePropertyAccessorFactory.NAMESPACE_CONTEXT, NAMESPACES)); Object o = ex.evaluate(feature); assertTrue( o instanceof List ); assertEquals(3, ((List) o).size()); ex = new AttributeExpressionImpl("eg:complexAttribute/eg:rootAttribute/eg:singleLeafAttribute", new Hints( FeaturePropertyAccessorFactory.NAMESPACE_CONTEXT, NAMESPACES)); o = ex.evaluate(feature); assertTrue( o instanceof List ); assertEquals(3, ((List) o).size()); ex = new AttributeExpressionImpl("eg:complexAttribute/eg:rootAttribute[1]", new Hints( FeaturePropertyAccessorFactory.NAMESPACE_CONTEXT, NAMESPACES)); assertEquals(rootOne, ex.evaluate(feature)); ex = new AttributeExpressionImpl("eg:complexAttribute/eg:rootAttribute[2]", new Hints( FeaturePropertyAccessorFactory.NAMESPACE_CONTEXT, NAMESPACES)); assertEquals(rootTwo, ex.evaluate(feature));
public PropertyName property(String name) { AttributeExpressionImpl att = new AttributeExpressionImpl(name); att.setLenient(false); return att; }
/** * Gets the value of this attribute from the passed feature. * * @param feature Feature from which to extract attribute value. */ public Object evaluate(SimpleFeature feature) { //NC - is exact copy of code anyway, don't need to keep changing both //this method can probably be removed all together return evaluate((Object) feature, null); }
AttributeExpressionImpl expAttr = (AttributeExpressionImpl) obj; boolean isEqual = (expAttr.getType() == this.expressionType); if(LOGGER.isLoggable(Level.FINEST)) LOGGER.finest("expression type match:" + isEqual + "; in:" + expAttr.getType() + "; out:" + this.expressionType); isEqual = (expAttr.attPath != null) ? (isEqual && expAttr.attPath.equals(this.attPath)) if(LOGGER.isLoggable(Level.FINEST)) LOGGER.finest("attribute match:" + isEqual + "; in:" + expAttr.getAttributePath() + "; out:" + this.attPath); isEqual = (expAttr.schema != null) ? (isEqual && expAttr.schema.equals(this.schema))
/** * Constructor with schema and path to the attribute. * * @param schema The initial (required) sub filter. * @param attPath the xpath to the attribute. * * @throws IllegalFilterException If the attribute path is not in the * schema. */ protected AttributeExpressionImpl(FeatureType schema, String attPath) throws IllegalFilterException { this.schema = schema; this.expressionType = ATTRIBUTE; setAttributePath(attPath); }
public PropertyName property(Name name) { return new AttributeExpressionImpl(name); }
public void testSetupAndExtraction() throws Exception { // this should move out to a more configurable system run from scripts // but we can start with a set of hard coded tests SimpleFeature[] f = sampleFeatures(); AttributeExpressionImpl e1 = new AttributeExpressionImpl(schema, "value"); AttributeExpressionImpl e2 = new AttributeExpressionImpl(schema, "name"); assertEquals(12d, ((Integer) e1.evaluate(f[0])).doubleValue(), 0); assertEquals(3d, ((Integer) e1.evaluate(f[1])).doubleValue(), 0); assertEquals(15d, ((Integer) e1.evaluate(f[2])).doubleValue(), 0); assertEquals("first", (String) e2.evaluate(f[0])); assertEquals("second", (String) e2.evaluate(f[1])); } }
new AttributeExpressionImpl( "eg:simpleAttribute", new Hints(FeaturePropertyAccessorFactory.NAMESPACE_CONTEXT, NAMESPACES)); assertEquals(simpleAttribute, ex.evaluate(feature)); new AttributeExpressionImpl( "eg:complexAttribute", new Hints(FeaturePropertyAccessorFactory.NAMESPACE_CONTEXT, NAMESPACES)); assertEquals(complexAttribute, ex.evaluate(feature)); new AttributeExpressionImpl( "eg:complexAttribute/eg:rootAttribute", new Hints(FeaturePropertyAccessorFactory.NAMESPACE_CONTEXT, NAMESPACES)); Object o = ex.evaluate(feature); assertTrue(o instanceof List); assertEquals(3, ((List) o).size()); new AttributeExpressionImpl( "eg:complexAttribute/eg:rootAttribute/eg:singleLeafAttribute", new Hints(FeaturePropertyAccessorFactory.NAMESPACE_CONTEXT, NAMESPACES)); o = ex.evaluate(feature); assertTrue(o instanceof List); assertEquals(3, ((List) o).size()); new AttributeExpressionImpl( "eg:complexAttribute/eg:rootAttribute[1]", new Hints(FeaturePropertyAccessorFactory.NAMESPACE_CONTEXT, NAMESPACES));
protected Object getValues( boolean isMultiValued, Expression expression, Object sourceFeatureInput) { if (isMultiValued && sourceFeatureInput instanceof FeatureImpl && expression instanceof AttributeExpressionImpl) { // RA: Feature Chaining // complex features can have multiple nodes of the same attribute.. and if they are used // as input to an app-schema data access to be nested inside another feature type of a // different XML type, it has to be mapped like this: // <AttributeMapping> // <targetAttribute> // gsml:composition // </targetAttribute> // <sourceExpression> // <inputAttribute>mo:composition</inputAttribute> // <linkElement>gsml:CompositionPart</linkElement> // <linkField>gml:name</linkField> // </sourceExpression> // <isMultiple>true</isMultiple> // </AttributeMapping> // As there can be multiple nodes of mo:composition in this case, we need to retrieve // all of them AttributeExpressionImpl attribExpression = ((AttributeExpressionImpl) expression); String xpath = attribExpression.getPropertyName(); ComplexAttribute sourceFeature = (ComplexAttribute) sourceFeatureInput; StepList xpathSteps = XPath.steps(sourceFeature.getDescriptor(), xpath, namespaces); return getProperties(sourceFeature, xpathSteps); } return expression.evaluate(sourceFeatureInput); }
/** * Gets the value of this property from the passed object. * * @param obj Object from which we need to extract a property value. */ public Object evaluate(Object obj) { return evaluate(obj, null); }
public PropertyName property(String name, NamespaceSupport namespaceContext) { if (namespaceContext == null) { return property(name); } return new AttributeExpressionImpl(name, namespaceContext); }
public void testTypeMissmatch() throws Exception { SimpleFeature[] f = sampleFeatures(); // the following are intentionaly backwards AttributeExpressionImpl e1 = new AttributeExpressionImpl(schema, "value"); AttributeExpressionImpl e2 = new AttributeExpressionImpl(schema, "name"); boolean pass = false; Object value = null; value = e1.evaluate(f[0]); if (value instanceof Integer) { pass = true; } assertTrue("String expresion returned an Integer", pass); pass = false; value = e2.evaluate(f[0]); if (value instanceof String) { pass = true; } assertTrue("Integer expresion returned a String", pass); }