Package org.opengis.feature

Examples of org.opengis.feature.Attribute


   
    protected Attribute setAttributeContent(Attribute target, StepList xpath, Object value,
            String id, AttributeType targetNodeType, boolean isXlinkRef,
            Expression sourceExpression, Object source,
            final Map<Name, Expression> clientProperties, boolean ignoreXlinkHref) {
        Attribute instance = null;

        Map<Name, Expression> properties = new HashMap<Name, Expression>(clientProperties);

        if (ignoreXlinkHref) {
            properties.remove(XLINK_HREF_NAME);
View Full Code Here


                final Expression sourceExpression = attMapping.getSourceExpression();
                final Expression idExpression = attMapping.getIdentifierExpression();

                for (int i = 0; i < ls.size(); i++) {
                    Pair parentPair = ls.get(i);
                    Attribute setterTarget = parentPair.getAttribute();
                    // find the root attribute mapping from the xpath
                    // get the full xpath query including
                    StepList xpath = attMapping.getTargetXPath().clone();
                    Object value = getValue(parentPair.getXpath(), sourceExpression, target);
                   
View Full Code Here

        String featureId = getId(idExpression, parentPair, attMapping, "")
//        Attribute att = xpathAttributeBuilder.set(target,
//                xpath, value, featureId, attMapping.getTargetNodeInstance(), false, attMapping
//                        .getSourceExpression());
        Attribute att = setAttributeValue(target, featureId, null, attMapping, value, xpath, null);
        setClientProperties(att, parentPair.getXpath(), attMapping.getClientProperties());
    }
View Full Code Here

            final String bracketIndex = bracketedIndex(j);
            String featureId = getId(idExpression, parentAttribute, attMapping, bracketIndex);    
           
            setLastElementIndex(parentAttribute.getAttribute(), sl, j);
           
            Attribute subFeature = xpathAttributeBuilder.set(target,
                    sl, null, featureId, attMapping.getTargetNodeInstance(), false, attMapping
                            .getSourceExpression());
//            Attribute subFeature = setAttributeValue(parentAttribute.getAttribute(), featureId,
//                    null, attMapping, null, sl, null);
           
View Full Code Here

                    targetNodeType });
        }

        final StepList steps = new StepList(xpath);

        Attribute parent = att;
        Name rootName = null;
        AttributeDescriptor parentDescriptor = parent.getDescriptor();
        if (parentDescriptor != null) {
            rootName = parentDescriptor.getName();
            Step rootStep = (Step) steps.get(0);
            QName stepName = rootStep.getName();
            if (Types.equals(rootName, stepName)) {
                // first step is the self reference to att, so skip it
                if (steps.size() > 1) {
                    steps.remove(0);
                } else {
                    // except when the xpath is the root itself
                    // where it is done for feature chaining for simple content
                    if (Types.isSimpleContentType(parent.getType())) {
                        return setSimpleContentValue(parent, value);
                    } else if (Types.isGeometryType(parent.getType())) {
                        ComplexFeatureTypeFactoryImpl typeFactory = new ComplexFeatureTypeFactoryImpl();
                        GeometryType geomType;
                        if (parent.getType() instanceof GeometryType) {
                            geomType = (GeometryType) parent.getType();
                        } else {
                            geomType = (GeometryType) ((NonFeatureTypeProxy) parent.getType())
                                    .getSubject();
                        }
                        GeometryDescriptor geomDescriptor = typeFactory.createGeometryDescriptor(
                                geomType, rootName, parentDescriptor.getMinOccurs(),
                                parentDescriptor.getMaxOccurs(), parentDescriptor.isNillable(),
                                parentDescriptor.getDefaultValue());
                        GeometryAttributeImpl geom = new GeometryAttributeImpl(value,
                                geomDescriptor, null);
                        ArrayList<Property> geomAtts = new ArrayList<Property>();
                        geomAtts.add(geom);
                        parent.setValue(geomAtts);
                        return geom;
                    }
                }
            }
        }

        Iterator stepsIterator = steps.iterator();

        for (; stepsIterator.hasNext();) {
            final XPath.Step currStep = (Step) stepsIterator.next();
            AttributeDescriptor currStepDescriptor = null;
            final boolean isLastStep = !stepsIterator.hasNext();
            final QName stepName = currStep.getName();
            final Name attributeName = Types.toName(stepName);

            final AttributeType _parentType = parent.getType();
            if (_parentType.getName().equals(XSSchema.ANYTYPE_TYPE.getName()) && targetDescriptor != null) {
                // this needs to be passed on if casting anyType to something else, since it won't
                // exist in the schema
                currStepDescriptor = targetDescriptor;
            } else {
                ComplexType parentType = (ComplexType) _parentType;

                if (!isLastStep || targetNodeType == null) {
                    if (null == attributeName.getNamespaceURI()) {
                        currStepDescriptor = (AttributeDescriptor) Types.findDescriptor(parentType, attributeName.getLocalPart());
                    } else {
                        currStepDescriptor = (AttributeDescriptor) Types.findDescriptor(parentType, attributeName);
                    }

                    if (currStepDescriptor == null) {
                        // need to take the non easy way, may be the instance has a
                        // value for this step with a different name, of a derived
                        // type of the one declared in the parent type
                        String prefixedStepName = currStep.toString();
                        PropertyName name = FF.property(prefixedStepName);
                        Attribute child = (Attribute) name.evaluate(parent);
                        if (child != null) {
                            currStepDescriptor = child.getDescriptor();
                        }
                    }
                } else {
                    AttributeDescriptor actualDescriptor;
                    if (null == attributeName.getNamespaceURI()) {
View Full Code Here

        if (simpleContent == null) {
            Collection<Property> contents = new ArrayList<Property>();
          simpleContent = buildSimpleContent(attribute.getType(), value);
            contents.add(simpleContent);
            ArrayList<Attribute> nestedAttContents = new ArrayList<Attribute>();
            Attribute nestedAtt = new ComplexAttributeImpl(contents, attribute.getDescriptor(),
                    attribute.getIdentifier());
            nestedAttContents.add(nestedAtt);
            attribute.setValue(nestedAttContents);
           
            return nestedAtt;
View Full Code Here

   
    private Attribute setLeafAttribute(AttributeDescriptor currStepDescriptor,
            Step currStep, String id, Object value, Attribute parent,
            AttributeType targetNodeType, boolean isXlinkRef) {
        int index = currStep.isIndexed() ? currStep.getIndex() : -1;
        Attribute attribute = setValue(currStepDescriptor, id, value, index, parent,
                targetNodeType, isXlinkRef);
        return attribute;
    }
View Full Code Here

        } else {
            // adapt value to context
            convertedValue = convertValue(descriptor, value);  
        }
               
        Attribute leafAttribute = null;
        final Name attributeName = descriptor.getName();       
        if (!isXlinkRef) {
            // skip this process if the attribute would only contain xlink:ref
            // that is chained, because it won't contain any values, and we
            // want to create a new empty leaf attribute
            if (parent instanceof ComplexAttribute) {
                Object currStepValue = ((ComplexAttribute) parent).getProperties(attributeName);
                if (currStepValue instanceof Collection) {
                    List<Attribute> values = new ArrayList((Collection) currStepValue);
                    if (!values.isEmpty()) {
                        if (isEmpty(convertedValue)) {
                            // when attribute is empty, it is probably just a parent of a leaf
                            // attribute
                            // it could already exist from another attribute mapping for a different
                            // leaf
                            // e.g. 2 different attribute mappings:
                            // sa:relatedObservation/om:Observation/om:parameter[2]/swe:Time/swe:uom
                            // sa:relatedObservation/om:Observation/om:parameter[2]/swe:Time/swe:value
                            // and this could be processing om:parameter[2] the second time for
                            // swe:value
                            // so we need to find it if it already exists
                            if (index > -1) {
                                // get the attribute of specified index
                                int valueIndex = 1;
                                for (Attribute stepValue : values) {
                                    Object mappedIndex = stepValue.getUserData().get(
                                            ComplexFeatureConstants.MAPPED_ATTRIBUTE_INDEX);
                                    if (mappedIndex == null) {
                                        mappedIndex = valueIndex;
                                    }
                                    if (index == Integer.parseInt(String.valueOf(mappedIndex))) {
                                        leafAttribute = stepValue;
                                    }
                                    valueIndex++;
                                }
                            } else {
                                // get the last existing node
                                leafAttribute = values.get(values.size() - 1);
                            }
                        } else {
                            for (Attribute stepValue : values) {
                                // eliminate duplicates in case the values come from denormalized
                                // view..
                                boolean sameIndex = true;
                                if (index > -1) {
                                    if (stepValue.getUserData().containsKey(
                                            ComplexFeatureConstants.MAPPED_ATTRIBUTE_INDEX)) {
                                        sameIndex = (index == Integer.parseInt(
                                            String.valueOf(stepValue.getUserData().get(
                                                ComplexFeatureConstants.MAPPED_ATTRIBUTE_INDEX))));
                                    }
                                }
                                if (sameIndex && stepValue.getValue().equals(convertedValue)) {
                                    leafAttribute = stepValue;
                                }
                            }
                        }
                    }
                } else if (currStepValue instanceof Attribute) {
                    leafAttribute = (Attribute) currStepValue;
                } else if (currStepValue != null) {
                    throw new IllegalStateException("Unknown addressed object. Xpath:"
                            + attributeName + ", addressed: " + currStepValue.getClass().getName()
                            + " [" + currStepValue.toString() + "]");
                }
            }
        }
        if (leafAttribute == null) {
            AppSchemaAttributeBuilder builder = new AppSchemaAttributeBuilder(featureFactory);
            if (crs != null) {
                builder.setCRS(crs);
            }
            builder.setDescriptor(parent.getDescriptor());
            // check for mapped type override
            builder.setType(parent.getType());

            if (targetNodeType != null) {
                if (parent.getType().getName().equals(XSSchema.ANYTYPE_TYPE.getName())) {
                    // special handling for casting any type since there's no attributes in its
                    // schema
                    leafAttribute = builder.addAnyTypeValue(convertedValue, targetNodeType,
                            descriptor, id);
                } else {
                    leafAttribute = builder.add(id, convertedValue, attributeName, targetNodeType);
                }
            } else if (descriptor.getType().getName().equals(XSSchema.ANYTYPE_TYPE.getName())
                    && (value == null || (value instanceof Collection && ((Collection) value)
                            .isEmpty()))) {
                // casting anyType as a complex attribute so we can set xlink:href
                leafAttribute = builder.addComplexAnyTypeAttribute(convertedValue, descriptor, id);
            } else {
                leafAttribute = builder.add(id, convertedValue, attributeName);
            }
            if (index > -1) {
                // set attribute index if specified so it can be retrieved later for grouping
                leafAttribute.getUserData().put(ComplexFeatureConstants.MAPPED_ATTRIBUTE_INDEX,
                        index);
            }
            List newValue = new ArrayList();
            newValue.addAll((Collection) parent.getValue());
            newValue.add(leafAttribute);
            parent.setValue(newValue);
        }

        if (!isEmpty(convertedValue)) {
            leafAttribute.setValue(convertedValue);
        }
        if (simpleContentProperties != null) {
            mergeClientProperties(leafAttribute, simpleContentProperties);
        }
        return leafAttribute;
View Full Code Here

                // only need to set the href link value, not the nested feature properties
              setXlinkReference(target, clientPropsMappings, values, xpath, targetNodeType);
                return null;
            }
        }
        Attribute instance = null;
        if (values instanceof Collection) {
            // nested feature type could have multiple instances as the whole purpose
            // of feature chaining is to cater for multi-valued properties
            for (Object singleVal : (Collection) values) {
                ArrayList valueList = new ArrayList();
                // copy client properties from input features if they're complex features
                // wrapped in app-schema data access
                if (singleVal instanceof Attribute) {
                    // copy client properties from input features if they're complex features
                    // wrapped in app-schema data access
                    Map<Name, Expression> valueProperties = getClientProperties((Attribute) singleVal);
                    if (!valueProperties.isEmpty()) {
                        clientPropsMappings.putAll(valueProperties);
                    }
                }
                if (!isNestedFeature) {
                    if (singleVal instanceof Attribute) {
                        singleVal = ((Attribute) singleVal).getValue();
                    }
                    if (singleVal instanceof Collection) {
                        valueList.addAll((Collection) singleVal);
                    } else {
                        valueList.add(singleVal);
                    }
                } else {
                    valueList.add(singleVal);
                }
                instance = setAttributeContent(target, xpath, valueList, id, targetNodeType, false, sourceExpression, source, clientPropsMappings, ignoreXlinkHref);
            }
        } else {
            if (values instanceof Attribute) {
                // copy client properties from input features if they're complex features
                // wrapped in app-schema data access
                Map<Name, Expression> newClientProps = getClientProperties((Attribute) values);
                if (!newClientProps.isEmpty()) {
                    newClientProps.putAll(clientPropsMappings);
                    clientPropsMappings = newClientProps;
                }
                values = ((Attribute) values).getValue();
            }
            instance = setAttributeContent(target, xpath, values, id, targetNodeType, false, sourceExpression, source, clientPropsMappings, ignoreXlinkHref);

        }
        if (instance != null && attMapping.encodeIfEmpty()) {
            instance.getDescriptor().getUserData().put("encodeIfEmpty", attMapping.encodeIfEmpty());
        }
        return instance;
    }
View Full Code Here

    private Attribute setPolymorphicReference(String uri,
            Map<Name, Expression> clientPropsMappings, Attribute target, StepList xpath,
            AttributeType targetNodeType) {
       
        if (uri != null) {
            Attribute instance = xpathAttributeBuilder.set(target, xpath, null, "", targetNodeType,
                    true, null);
            Map<Name, Expression> newClientProps = new HashMap<Name, Expression>();
            newClientProps.putAll(clientPropsMappings);
            newClientProps.put(XLINK_HREF_NAME, namespaceAwareFilterFactory.literal(uri));
            setClientProperties(instance, null, newClientProps);
View Full Code Here

TOP

Related Classes of org.opengis.feature.Attribute

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.