From: <jde...@sv...> - 2007-11-23 01:08:02
|
Author: jdeolive Date: 2007-11-22 17:07:41 -0800 (Thu, 22 Nov 2007) New Revision: 28004 Added: geotools/trunk/gt/modules/extension/xsd/gml2/src/main/java/org/geotools/gml2/Reference.java Modified: geotools/trunk/gt/modules/extension/xsd/gml2/src/main/java/org/geotools/gml2/FeaturePropertyExtractor.java Log: handling references for xlink Modified: geotools/trunk/gt/modules/extension/xsd/gml2/src/main/java/org/geotools/gml2/FeaturePropertyExtractor.java =================================================================== --- geotools/trunk/gt/modules/extension/xsd/gml2/src/main/java/org/geotools/gml2/FeaturePropertyExtractor.java 2007-11-23 01:05:46 UTC (rev 28003) +++ geotools/trunk/gt/modules/extension/xsd/gml2/src/main/java/org/geotools/gml2/FeaturePropertyExtractor.java 2007-11-23 01:07:41 UTC (rev 28004) @@ -17,13 +17,18 @@ import org.eclipse.xsd.XSDElementDeclaration; import org.eclipse.xsd.XSDParticle; +import org.eclipse.xsd.XSDTypeDefinition; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import javax.xml.namespace.QName; +import org.opengis.feature.Attribute; +import org.opengis.feature.Property; import org.opengis.feature.simple.SimpleFeature; import org.opengis.feature.simple.SimpleFeatureType; import org.geotools.feature.FeatureCollection; +import org.geotools.feature.simple.SimpleFeatureBuilder; +import org.geotools.feature.simple.SimpleFeatureTypeBuilder; import org.geotools.xml.PropertyExtractor; import org.geotools.xml.SchemaIndex; import org.geotools.xml.Schemas; @@ -51,18 +56,33 @@ SimpleFeatureType featureType = feature.getFeatureType(); String namespace = featureType.getName().getNamespaceURI(); + + if (namespace == null) { + namespace = element.getTargetNamespace(); + } + String typeName = featureType.getTypeName(); //find the type in the schema - element = schemaIndex.getElementDeclaration(new QName(namespace, typeName)); + XSDTypeDefinition type = schemaIndex.getTypeDefinition(new QName(namespace, typeName)); - if (element == null) { + if (type == null) { + //type not found, do a check for an element, and use its type + XSDElementDeclaration e = schemaIndex.getElementDeclaration(new QName(namespace, + typeName)); + + if (e != null) { + type = e.getTypeDefinition(); + } + } + + if (type == null) { String msg = "Could not find element declaration: (" + namespace + ", " + typeName + " )"; throw new RuntimeException(msg); } - List particles = Schemas.getChildElementParticles(element.getType(), true); + List particles = Schemas.getChildElementParticles(type, true); List properties = new ArrayList(); for (Iterator p = particles.iterator(); p.hasNext();) { @@ -83,7 +103,30 @@ continue; } + //get the value Object attributeValue = feature.getAttribute(attribute.getName()); + + //special case for features + if (attributeValue == null) { + Property prop = feature.getProperty(attribute.getName()); + + if (SimpleFeature.class.equals(prop.getType().getBinding())) { + //if the value is null, check for userData specifying the id + if (prop.getValue() == null) { + String id = (String) prop.getUserData().get("gml:id"); + + if (id != null) { + //we have the id, so we can create a reference to + // object we dont have + Reference ref = new Reference(); + ref.setXlink("#" + id); + + attributeValue = ref; + } + } + } + } + properties.add(new Object[] { particle, attributeValue }); } Added: geotools/trunk/gt/modules/extension/xsd/gml2/src/main/java/org/geotools/gml2/Reference.java =================================================================== --- geotools/trunk/gt/modules/extension/xsd/gml2/src/main/java/org/geotools/gml2/Reference.java 2007-11-23 01:05:46 UTC (rev 28003) +++ geotools/trunk/gt/modules/extension/xsd/gml2/src/main/java/org/geotools/gml2/Reference.java 2007-11-23 01:07:41 UTC (rev 28004) @@ -0,0 +1,47 @@ +/* + * GeoTools - OpenSource mapping toolkit + * http://geotools.org + * (C) 2002-2006, GeoTools Project Managment Committee (PMC) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + */ +package org.geotools.gml2; + + +/** + * A gml reference. + * + * @author Justin Deoliveira, The Open Planning Project + * + */ +public class Reference { + /** the referenced object */ + Object object; + + /** xlink to the referenced object */ + String xlink; + + public Object getObject() { + return object; + } + + public void setObject(Object object) { + this.object = object; + } + + public String getXlink() { + return xlink; + } + + public void setXlink(String xlink) { + this.xlink = xlink; + } +} Property changes on: geotools/trunk/gt/modules/extension/xsd/gml2/src/main/java/org/geotools/gml2/Reference.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:keywords + Id Name: svn:eol-style + native |