Package org.opengis.feature

Examples of org.opengis.feature.ComplexAttribute


    @SuppressWarnings("unchecked")   
    public Object getImmediateNode() {
       
        //first try regular way
        if (feature instanceof ComplexAttribute) {
            ComplexAttribute ca = (ComplexAttribute) feature;
            Property p = ca.getProperty("@" + name.getLocalPart());
            if (p != null) {
                return p;
            }
        }
       
View Full Code Here


     *      javax.xml.namespace.QName)
     */
    @Override
    public Object getProperty(Object object, QName name) throws Exception {
        if (object instanceof ComplexAttribute) {
            ComplexAttribute complex = (ComplexAttribute) object;
            Property property = complex.getProperty(toTypeName(name));
            if (property != null && !(property instanceof ComplexAttribute)) {
                return property.getValue();
            }
            if ("id".equals(name.getLocalPart())) {
                return complex.getIdentifier();
            }
        }
        return null;
    }
View Full Code Here

                }
            }
            return properties;
        }
        if (object instanceof ComplexAttribute) {
            ComplexAttribute complex = (ComplexAttribute) object;
            for (XSDParticle childParticle : (List<XSDParticle>) Schemas.getChildElementParticles(
                    element.getTypeDefinition(), true)) {
                XSDElementDeclaration childElement = (XSDElementDeclaration) childParticle
                        .getContent();
                if (childElement.isElementDeclarationReference()) {
                    childElement = childElement.getResolvedElementDeclaration();
                }
                for (XSDElementDeclaration e : (List<XSDElementDeclaration>) childElement
                        .getSubstitutionGroup()) {
                    Name name = new NameImpl(e.getTargetNamespace(), e.getName());
                    Collection<Property> nameProperties = complex.getProperties(name);
                    if (!nameProperties.isEmpty()) {
                        // Particle creation stolen from BindingPropertyExtractor.
                        // I do not know why a wrapper is required; monkey see, monkey do.
                        // Without the wrapper, get an NPE in BindingPropertyExtractor.
                        XSDParticle substitutedChildParticle = XSDFactory.eINSTANCE
                                .createXSDParticle();
                        substitutedChildParticle.setMaxOccurs(childParticle.getMaxOccurs());
                        substitutedChildParticle.setMinOccurs(childParticle.getMinOccurs());
                        XSDElementDeclaration wrapper = XSDFactory.eINSTANCE
                                .createXSDElementDeclaration();
                        wrapper.setResolvedElementDeclaration(e);
                        substitutedChildParticle.setContent(wrapper);
                        for (Property property : nameProperties) {
                            /*
                             * Note : Returning simple feature value is not necessary as it has been
                             * taken care in the 1st For Loop of BindingPropertyExtractor.java -
                             * List properties(Object, XSDElementDeclaration) method
                             */
                            if (property instanceof ComplexAttribute) {
                                properties.add(new Object[] { substitutedChildParticle, property });
                            } else if (property instanceof GeometryAttribute) {
                                Object attType = complex.getType().getUserData()
                                        .get(XSDTypeDefinition.class);
                                boolean duplicate = false;
                                // handle substitution group for geometries too, but make sure
                                // it's not already handled in BindingPropertyExtractor
                                // otherwise it would be encoded as xlink:href as the id has already
                                // been seen
                                if (attType != null && attType instanceof XSDTypeDefinition) {
                                    XSDTypeDefinition attTypeDef = (XSDTypeDefinition) attType;
                                    for (XSDParticle attChild : (List<XSDParticle>) Schemas
                                            .getChildElementParticles(attTypeDef, true)) {
                                        XSDElementDeclaration childEl = (XSDElementDeclaration) attChild
                                                .getContent();
                                        if (childEl.isElementDeclarationReference()) {
                                            childEl = childEl.getResolvedElementDeclaration();
                                        }
                                        if (childEl.equals(e)) {
                                            duplicate = true;
                                            break;
                                        }
                                    }
                                }
                                if (!duplicate) {
                                    properties.add(new Object[] { substitutedChildParticle,
                                            property.getValue() });
                                }
                            }
                        }
                    }
                }
            }
        }

        List<XSDParticle> anyElementParticles = new ArrayList<XSDParticle>(Schemas
                .getAnyElementParticles(element.getTypeDefinition()));
        if (anyElementParticles.size() > 0) {
            Collection complexAtts = null;
            if (object instanceof Collection) {
                // collection of features
                complexAtts = (Collection) object;
            } else if (object instanceof ComplexAttribute) {
                // get collection of features from this attribute
                complexAtts = ((ComplexAttribute) object).getProperties();
            }

            // If child elements can't be retrieved from
            // Schemas.getChildElementParticles(element.getTypeDefinition(), true)),
            // properties list is empty. In this case, add all the complex
            // attributes in the object to the properties list.
            if (properties.isEmpty()) {
                for (Object complex : complexAtts) {
                    // only process complex attributes
                    if (complex instanceof ComplexAttribute) {
                        ComplexAttribute newComplexAtt = (ComplexAttribute) complex;
                        PropertyDescriptor descriptor = newComplexAtt.getDescriptor();
                        if (descriptor.getUserData() != null) {
                            Object propertyElement = descriptor.getUserData().get(
                                    XSDElementDeclaration.class);
                            if (propertyElement != null
                                    && propertyElement instanceof XSDElementDeclaration) {
                                XSDParticle substitutedChildParticle = XSDFactory.eINSTANCE
                                        .createXSDParticle();
                                substitutedChildParticle.setMaxOccurs(descriptor.getMaxOccurs());
                                substitutedChildParticle.setMinOccurs(descriptor.getMinOccurs());
                                XSDElementDeclaration wrapper = XSDFactory.eINSTANCE
                                        .createXSDElementDeclaration();
                                wrapper
                                        .setResolvedElementDeclaration((XSDElementDeclaration) propertyElement);
                                substitutedChildParticle.setContent(wrapper);
                                properties.add(new Object[] { substitutedChildParticle,
                                        newComplexAtt });
                            }
                        }
                    }
                }
            }

            /*
             * properties list is not empty.
             *
             * It's possible <any> and <element> co-exist in the same type. For example,
             *
             * <sequence>
             *     <any/>
             *     <element name="..." type="...">
             * </sequence>
             *
             * In this case, only add <any> complex attributes to the properties list. The following
             * code is not covered in unit test, as app-schema, doesn't support <any> as a
             * targetAttribute in a mapping file.
             */
            else {
                List<XSDParticle> elementParticles = new ArrayList<XSDParticle>(Schemas
                        .getChildElementParticles(element.getTypeDefinition(), false));
                for (Object complex : complexAtts) {
                    if (complex instanceof ComplexAttribute) {
                        ComplexAttribute newComplexAtt = (ComplexAttribute) complex;
                        PropertyDescriptor descriptor = ((Attribute) complex).getDescriptor();
                        if (descriptor.getUserData() != null) {
                            Object propertyElement = descriptor.getUserData().get(
                                    XSDElementDeclaration.class);
                            if (propertyElement != null
                                    && propertyElement instanceof XSDElementDeclaration) {
                                XSDParticle substitutedChildParticle = XSDFactory.eINSTANCE
                                        .createXSDParticle();
                                substitutedChildParticle.setMaxOccurs(descriptor.getMaxOccurs());
                                substitutedChildParticle.setMinOccurs(descriptor.getMinOccurs());
                                XSDElementDeclaration wrapper = XSDFactory.eINSTANCE
                                        .createXSDElementDeclaration();
                                wrapper
                                        .setResolvedElementDeclaration((XSDElementDeclaration) propertyElement);
                                substitutedChildParticle.setContent(wrapper);
                                boolean propertyExist = false;
                                for (XSDParticle childParticle : elementParticles) {
                                    XSDElementDeclaration childElement = (XSDElementDeclaration) childParticle
                                            .getContent();
                                    if (childElement.isElementDeclarationReference()) {
                                        childElement = childElement.getResolvedElementDeclaration();
                                    }
                                    String existingName = childElement.getName();
                                    String newName = newComplexAtt.getDescriptor().getName()
                                            .getLocalPart();
                                    if (existingName.equals(newName)) {
                                        propertyExist = true;
                                        break;
                                    }
View Full Code Here

     * @param att
     *            The complex attribute itself
     */
    private void checkXlinkHref(Object value, ComplexAttribute att) {
        if (value != null && value instanceof ComplexAttribute) {
            ComplexAttribute object = (ComplexAttribute) value;
            // Only worry about features for now, as non feature types don't get ids encoded yet.
            // See GEOS-3738. To encode xlink:href to an id that doesn't exist in the doc is wrong
            if (!(object.getType() instanceof FeatureTypeImpl)) {
                // we are checking the type, not the object as FeatureImpl, because they could still
                // be non-features that are constructed as features for the purpose of feature
                // chaining.
                return;
            }
            Identifier ident = object.getIdentifier();
            if (ident == null) {
                return;
            }
            String id = Converters.convert(ident.getID(), String.class);
            if (idSet.idExists(id)) {
View Full Code Here

     *      org.w3c.dom.Element)
     */
    @Override
    public Element encode(Object object, Document document, Element value) throws Exception {
        if (object instanceof ComplexAttribute) {
            ComplexAttribute complex = (ComplexAttribute) object;
            if (complex.getProperties().size() == 1) {
                Property prop = complex.getProperties().iterator().next();
                checkXlinkHref(prop, complex);
            }
            GML3EncodingUtils.encodeClientProperties(complex, value);
            GML3EncodingUtils.encodeSimpleContent(complex, document, value);
        }
View Full Code Here

        assertEquals(1234, measure.doubleValue(), 0.1);
        assertEquals("http://someuri", ((BaseUnit) measure.getUnit()).getSymbol());
    }

    public void testEncode() throws Exception {
        ComplexAttribute myCode = gmlMeasureType(GML.measure, "12", "m");
        Document dom = encode(myCode, GML.measure);
        print(dom);
        assertEquals("gml:measure", dom.getDocumentElement().getNodeName());
        assertEquals("12", dom.getDocumentElement().getFirstChild().getNodeValue());
        assertNotNull(dom.getDocumentElement().getAttribute("uom"));
View Full Code Here

    private static String TEST_NAME_VALUE = "Test name";

    private static String TEST_NAME_CODESPACE = "urn:x-test:SomeNamingAuthority";

    public void testEncode() throws Exception {
        ComplexAttribute myCode = gmlCodeType(GML.name, TEST_NAME_VALUE, TEST_NAME_CODESPACE);
        Document dom = encode(myCode, GML.name);
        print(dom);
        assertEquals("gml:name", dom.getDocumentElement().getNodeName());
        assertEquals(TEST_NAME_VALUE, dom.getDocumentElement().getFirstChild().getNodeValue());
        assertNotNull(dom.getDocumentElement().getAttribute("codeSpace"));
View Full Code Here

            fi.close();
        }
    }

    private String getSimpleLiteralValue(Feature f, String name) {
        ComplexAttribute ca = (ComplexAttribute) f.getProperty(name);
        return (String) ca.getProperty("value").getValue();
    }
View Full Code Here

        ComplexAttribute ca = (ComplexAttribute) f.getProperty(name);
        return (String) ca.getProperty("value").getValue();
    }
   
    private String getSimpleLiteralScheme(Feature f, String name) {
        ComplexAttribute ca = (ComplexAttribute) f.getProperty(name);
        return (String) ca.getProperty("scheme").getValue();
    }
View Full Code Here

        final List<String> values = new ArrayList<String>();
        records.accepts(new FeatureVisitor() {
           
            @Override
            public void visit(Feature feature) {
                ComplexAttribute ca = (ComplexAttribute) feature.getProperty(property);
                String value = (String) ca.getProperty("value").getValue();
                values.add(value);
               
            }
        }, null);
        return values;
View Full Code Here

TOP

Related Classes of org.opengis.feature.ComplexAttribute

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.