Package org.geotools.data.complex.filter.XPathUtil

Examples of org.geotools.data.complex.filter.XPathUtil.StepList


                return values;
            }
        }

        boolean isClientProperty = isClientProperty(steps);
        StepList newSteps = null;
        if (isClientProperty) {
            // check for client properties for this mapping
            newSteps = steps.subList(0, steps.size() - 1);
            if (newSteps.size() == 1) {
                // special case for client property for this NestedAttributeMapping
                for (Feature f : nestedFeatures) {
                    values.addAll(getClientProperties(nestedMapping, f));
                }
            }
        }       
        // skip element name that is mapped at the next FeatureTypeMapping
        // except when it's a simple content
        // if simple content, then there will be no type name in the xpath, e.g. when gml:name
        // is
        // feature chained the path stays as gml:name.. but if it's a complex type with complex
        // content, e.g. gsml:specification the path will be
        // gsml:specification/gsml:GeologicUnit/<some leaf attribute to filter by>       
        Name nextElementName = nextFMapping.getTargetFeature().getName();
        // starting index for the next search
        int startPos = -1;           
        if (Types.equals(nextElementName, steps.get(0).getName())) {
            // simple contents where nested element name is the same as the nesting element
            startPos = 0;
        } else {
            Step elementNameStep = steps.get(nestedMapping.getTargetXPath().size());
            // support polymorphism
            // check that element type matches the steps
            if (Types.equals(nextElementName, elementNameStep.getName())) {
                startPos = nestedMapping.getTargetXPath().size();
                if (steps.size() > startPos + 1 && !steps.get(startPos + 1).isXmlAttribute()) {
                    // skip next element name for next evaluation
                    // except if the next step is a client property for that element name
                    // since we'd need the AttributeMapping for the client property
                    startPos++;
                }
            }
        }
        if (startPos > -1) {
            newSteps = steps.subList(startPos, steps.size());
            if (!newSteps.isEmpty()) {
                List<NestedAttributeMapping> nestedMappings = nextFMapping.getNestedMappings();
                if (!nestedMappings.isEmpty()) {
                    for (NestedAttributeMapping mapping : nestedMappings) {
                        if (newSteps.startsWith(mapping.getTargetXPath())) {
                            for (Feature f : nestedFeatures) {
                                // loop to this method
                                values.addAll(getValues(f, mapping, newSteps));
                            }
                        }
                    }
                }
                if (isClientProperty) {
                    // check for client properties
                    newSteps = newSteps.subList(0, newSteps.size() - 1);
                }
                boolean isXlinkHref = isClientProperty && isXlinkHref(steps);

                List<AttributeMapping> attMappings = nextFMapping
                        .getAttributeMappingsIgnoreIndex(newSteps);
View Full Code Here


            if (idExpr == null) {
             // this might be because it's an XPath expression
                idXpath = attDto.getIdentifierPath();
                if (idXpath != null) {
                    //validate without indexed elements
                    final StepList inputXPathSteps = XPath.steps(root, itemXpath + "/"+ idXpath, namespaces);
                    validateConfiguredNamespaces(inputXPathSteps);
                }                        
            }
                       
            String sourceExpr = attDto.getSourceExpression();
            String inputXPath = null;
            if (sourceExpr == null) {
                // this might be because it's an XPath expression
                inputXPath = attDto.getInputAttributePath();
                if (inputXPath != null) {
                    final StepList inputXPathSteps = XPath.steps(root, itemXpath + "/" + inputXPath, namespaces);
                    validateConfiguredNamespaces(inputXPathSteps);
                }
            }
            String expectedInstanceTypeName = attDto.getTargetAttributeSchemaElement();

            final String targetXPath = attDto.getTargetAttributePath();
            final StepList targetXPathSteps = XPath.steps(root, targetXPath, namespaces);
            validateConfiguredNamespaces(targetXPathSteps);

            final boolean isMultiValued = attDto.isMultiple();
           
            final Expression idExpression = (idXpath == null) ? parseOgcCqlExpression(idExpr)
                    : new AttributeExpressionImpl(idXpath, new Hints(
                            FeaturePropertyAccessorFactory.NAMESPACE_CONTEXT, this.namespaces));
            // if the data source is a data access, the input XPath expression is the source
            // expression
            final Expression sourceExpression;

            sourceExpression = (inputXPath == null) ? parseOgcCqlExpression(sourceExpr)
                    : new AttributeExpressionImpl(inputXPath, new Hints(
                            FeaturePropertyAccessorFactory.NAMESPACE_CONTEXT, this.namespaces));

            final AttributeType expectedInstanceOf;

            final Map clientProperties = getClientProperties(attDto);

            if (expectedInstanceTypeName != null) {
                Name expectedNodeTypeName = Types.degloseName(expectedInstanceTypeName, namespaces);
                expectedInstanceOf = typeRegistry.getAttributeType(expectedNodeTypeName, null, crs);
                if (expectedInstanceOf == null) {
                    String msg = "mapping expects and instance of " + expectedNodeTypeName
                            + " for attribute " + targetXPath
                            + " but the attribute descriptor was not found";
                    throw new DataSourceException(msg);
                }
            } else {
                expectedInstanceOf = null;
            }
            AttributeMapping attMapping;
            String sourceElement = attDto.getLinkElement();           
            if (sourceElement != null) {
                // nested complex attributes, this could be a function expression for polymorphic
                // types
                Expression elementExpr = parseOgcCqlExpression(sourceElement);
                String sourceField = attDto.getLinkField();
                StepList sourceFieldSteps = null;
                if (sourceField != null) {
                    // it could be null for polymorphism mapping,
                    // i.e. when the linked element maps to the same table as the container mapping
                    sourceFieldSteps = XPath.steps(root, sourceField, namespaces);
                }
View Full Code Here

        this.namespaces = namespaces;
        this.isDenormalised = isDenormalised;
       
        // find id expression
        for (AttributeMapping attMapping : attributeMappings) {
            StepList targetXPath = attMapping.getTargetXPath();
            if (targetXPath.size() > 1) {
                continue;
            }
            Step step = (Step) targetXPath.get(0);
            QName stepName = step.getName();
            if (Types.equals(target.getName(), stepName)) {
                featureFidMapping = attMapping.getIdentifierExpression();
                break;
            }
View Full Code Here

        @Override
        public Object visit(PropertyName expression, Object extraData) {
            AttributeDescriptor root = mappings.getTargetFeature();
            String attPath = expression.getPropertyName();
            NamespaceSupport namespaces = mappings.getNamespaces();
            StepList simplifiedSteps = XPath.steps(root, attPath, namespaces);
            StepList targetXpath;
            for (AttributeMapping mapping : listMappings) {
                targetXpath = mapping.getTargetXPath();
                if (targetXpath.equals(simplifiedSteps)) {
                    // TODO: support feature chaining too?
                    isListFilter = true;
                    return extraData;
                }
            }
View Full Code Here

        NamespaceSupport namespaces = new NamespaceSupport();
        namespaces.declarePrefix("wq", name.getNamespaceURI());
        namespaces.declarePrefix("xlink", XLINK.NAMESPACE);

        StepList steps = XPathUtil.steps(descriptor, "wq_plus/measurement[2]/@xlink:href", namespaces);
        assertNotNull(steps);
        assertEquals(steps.toString(), 2, steps.size());

        XPathUtil.Step step1 = new XPathUtil.Step(new QName(rootQName.getNamespaceURI(), "measurement"), 2,
                false);
        XPathUtil.Step step2 = new XPathUtil.Step(XLINK.HREF, 1, true);

        assertEquals(step1, steps.get(0));
        assertEquals(step2, steps.get(1));
    }
View Full Code Here

        AttributeMapping featureMapping = null;
        Name featurePath = mapping.getTargetFeature().getName();
        QName featureName = Types.toQName(featurePath);
        for (Iterator it = mapping.getAttributeMappings().iterator(); it.hasNext();) {
            AttributeMapping attMapping = (AttributeMapping) it.next();
            StepList targetXPath = attMapping.getTargetXPath();
            if (targetXPath.size() > 1) {
                continue;
            }
            Step step = (Step) targetXPath.get(0);
            if (featureName.equals(step.getName())) {
                featureMapping = attMapping;
                break;
            }
        }
View Full Code Here

        List attributeMappings = mapping.getAttributeMappings();
        assertEquals(24, attributeMappings.size());

        AttributeMapping attMapping = (AttributeMapping) attributeMappings.get(0);
        assertNotNull(attMapping);
        StepList targetXPath = attMapping.getTargetXPath();
        assertNotNull(targetXPath);
        assertEquals("xmml:Borehole", targetXPath.toString());

        Expression idExpression = attMapping.getIdentifierExpression();
        assertNotNull(idExpression);
        assertTrue(idExpression instanceof Function);
        Function idFunction = (Function) idExpression;
View Full Code Here

                        String label = getFullQueryPath(attMapping);

                        mapping.put(label + XPATH_PROPERTY_SEPARATOR + "gml:id", ff
                            .property(xpath));
                       
                        StepList sl = attMapping.getTargetXPath();
                        setPathIndex(j, sl);
                        Attribute subFeature = null;
                        elements.put(attMapping.getLabel(), countXpath + bracketIndex, subFeature);
                    }
                }
View Full Code Here

        } else {
            final AttributeDescriptor targetDescriptor = mapping.getTargetFeature();
            selectedMapping = new ArrayList<AttributeMapping>();

            for (AttributeMapping attMapping : mapping.getAttributeMappings()) {
                final StepList targetSteps = attMapping.getTargetXPath();
                boolean alreadyAdded = false;

                if (includeMandatory) {
                    PropertyName targetProp = namespaceAwareFilterFactory.property(targetSteps
                            .toString());
                    Object descr = targetProp.evaluate(targetDescriptor.getType());
                    if (descr instanceof PropertyDescriptor) {
                        if (((PropertyDescriptor) descr).getMinOccurs() >= 1) {
                            selectedMapping.add(attMapping);
                            selectedProperties.put(attMapping, new ArrayList<PropertyName>());
                            alreadyAdded = true;
                        }
                    }
                }

                for (PropertyName requestedProperty : propertyNames) {
                    StepList requestedPropertySteps;                   
                    if (requestedProperty.getNamespaceContext() == null) {
                        requestedPropertySteps = XPath.steps(targetDescriptor, requestedProperty.getPropertyName(),
                                namespaces);
                    } else {
                        requestedPropertySteps = XPath.steps(targetDescriptor, requestedProperty.getPropertyName(),
                                    requestedProperty.getNamespaceContext());
                    }
                    if (requestedPropertySteps == null ? AppSchemaDataAccess.matchProperty(
                            requestedProperty.getPropertyName(), targetSteps) : AppSchemaDataAccess
                            .matchProperty(requestedPropertySteps, targetSteps)) {
                        if (!alreadyAdded) {
                            selectedMapping.add(attMapping);
                            selectedProperties.put(attMapping, new ArrayList<PropertyName>());
                            alreadyAdded = true;
                        }
                        if (requestedPropertySteps != null
                                && requestedPropertySteps.size() > targetSteps.size()) {
                            List<PropertyName> pnList = selectedProperties.get(attMapping);
                            StepList subProperty = requestedPropertySteps.subList(
                                    targetSteps.size(), requestedPropertySteps.size());
                            pnList.add(filterFac.property(subProperty.toString(),
                                    requestedProperty.getNamespaceContext()));
                        }
                    }
                }
            }
View Full Code Here

                // web service backend doesn't support getSchema()
                mappedType = null;
            }

            for (final AttributeMapping entry : attMappings) {
                final StepList targetSteps = entry.getTargetXPath();

                boolean addThis = false;

                if (includeMandatory) {
                    PropertyName targetProp = filterFac.property(targetSteps.toString(),
                            mapping.getNamespaces());
                    Object descr = targetProp.evaluate(targetDescriptor.getType());
                    if (descr instanceof PropertyDescriptor) {
                        if (((PropertyDescriptor) descr).getMinOccurs() >= 1) {
                            addThis = true;
                        }
                    }
                }

                if (!addThis) {
                    for (PropertyName requestedProperty : requestedProperties) {
                        StepList requestedPropertySteps;
                        if (requestedProperty.getNamespaceContext() == null) {
                            requestedPropertySteps = XPath.steps(targetDescriptor, requestedProperty.getPropertyName(),
                                    mapping.getNamespaces());
                        } else {
                            requestedPropertySteps = XPath.steps(targetDescriptor, requestedProperty.getPropertyName(),
View Full Code Here

TOP

Related Classes of org.geotools.data.complex.filter.XPathUtil.StepList

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.