Search in sources :

Example 1 with ObjectFactory

use of org.geotoolkit.internal.jaxb.ObjectFactory in project geotoolkit by Geomatys.

the class JTSGeometryBindingTest method setUp.

@Before
public void setUp() throws Exception {
    pool = JTSWrapperMarshallerPool.getInstance();
    factory = new ObjectFactory();
    un = pool.acquireUnmarshaller();
    m = pool.acquireMarshaller();
    File xsdDirectory = getDirectoryFromResource("org.geotoolkit.gml.311.base");
    SchemaFactory sf = SchemaFactory.newInstance(javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI);
    Schema schema = sf.newSchema(new File(xsdDirectory, "gml.xsd"));
    un.setSchema(schema);
// m.setSchema(schema);
}
Also used : SchemaFactory(javax.xml.validation.SchemaFactory) ObjectFactory(org.geotoolkit.internal.jaxb.ObjectFactory) Schema(javax.xml.validation.Schema) File(java.io.File)

Example 2 with ObjectFactory

use of org.geotoolkit.internal.jaxb.ObjectFactory in project geotoolkit by Geomatys.

the class JAXPStreamTransactionWriter method write.

// <xsd:element name="Update" type="wfs:UpdateElementType"/>
// <xsd:complexType name="UpdateElementType">
// <xsd:sequence>
// <xsd:element ref="wfs:Property" maxOccurs="unbounded"/>
// <xsd:element ref="ogc:Filter" minOccurs="0" maxOccurs="1"/>
// </xsd:sequence>
// <xsd:attribute name="handle" type="xsd:string" use="optional"/>
// <xsd:attribute name="typeName" type="xsd:QName" use="required"/>
// <xsd:attribute name="inputFormat" type="xsd:string"
// use="optional" default="text/xml; subversion=gml/3.1.1"/>
// <xsd:attribute name="srsName" type="xsd:anyURI" use="optional"/>
// </xsd:complexType>
// <xsd:element name="Property" type="wfs:PropertyType"/>
// <xsd:complexType name="PropertyType">
// <xsd:sequence>
// <xsd:element name="Name" type="xsd:QName"/>
// <xsd:element name="Value" minOccurs="0"/>
// </xsd:sequence>
// </xsd:complexType>
private void write(final XMLStreamWriter writer, final Update element) throws XMLStreamException, FactoryException, JAXBException {
    writer.writeStartElement(WFS_PREFIX, TAG_UPDATE, WFS_NAMESPACE);
    // write typename--------------------------------------------------------
    final GenericName typeName = element.getTypeName();
    final String ns = NamesExt.getNamespace(typeName);
    if (ns != null && !ns.isEmpty()) {
        final String prefix = "geons" + inc.incrementAndGet();
        writer.writeAttribute("xmlns:" + prefix, ns);
        writer.writeAttribute(PROP_TYPENAME, prefix + ':' + typeName.tip());
    } else {
        writer.writeAttribute(PROP_TYPENAME, typeName.tip().toString());
    }
    // write crs-------------------------------------------------------------
    final CoordinateReferenceSystem crs = element.getCoordinateReferenceSystem();
    if (crs != null) {
        final String id = ReferencingUtilities.lookupIdentifier(crs, true);
        writer.writeAttribute(WFS_PREFIX, WFS_NAMESPACE, PROP_SRSNAME, id);
    }
    // write format----------------------------------------------------------
    final String format = element.getInputFormat();
    if (format != null) {
        writer.writeAttribute(WFS_PREFIX, WFS_NAMESPACE, PROP_INPUTFORMAT, format);
    }
    // write handle----------------------------------------------------------
    final String handle = element.getHandle();
    if (handle != null) {
        writer.writeAttribute(WFS_PREFIX, WFS_NAMESPACE, PROP_HANDLE, handle);
    }
    // write filter ---------------------------------------------------------
    final Filter filter = element.getFilter();
    if (filter != null) {
        // TODO : parameterize version
        writeFilter(element.getFilter(), FilterVersion.V110, writer);
        writer.flush();
    }
    // write properties------------------------------------------------------
    for (final Entry<PropertyType, Object> entry : element.updates().entrySet()) {
        writer.writeStartElement(WFS_PREFIX, TAG_PROPERTY, WFS_NAMESPACE);
        // write namespace
        final GenericName name = entry.getKey().getName();
        final String ns2 = NamesExt.getNamespace(name);
        String pref = writer.getNamespaceContext().getPrefix(ns2);
        if (pref == null && ns2 != null && !ns2.isEmpty()) {
            pref = "geons" + inc.incrementAndGet();
            writer.writeAttribute("xmlns:" + pref, ns2);
        }
        // write name
        writer.writeStartElement(WFS_PREFIX, TAG_NAME, WFS_NAMESPACE);
        if (pref != null) {
            writer.writeCharacters(pref + ':' + name.tip());
        } else {
            writer.writeCharacters(name.tip().toString());
        }
        writer.writeEndElement();
        // write value
        final PropertyType propertyType = entry.getKey();
        Object value = entry.getValue();
        if (value != null) {
            if (value instanceof Geometry) {
                value = new GeometryPropertyType((AbstractGeometryType) JTStoGeometry.toGML("3.1.1", (Geometry) value));
                final Marshaller marshaller = GMLPOOL.acquireMarshaller();
                marshaller.setProperty(marshaller.JAXB_FRAGMENT, Boolean.TRUE);
                marshaller.marshal(new ObjectFactory().createValue(value), writer);
                GMLPOOL.recycle(marshaller);
            } else if (value instanceof org.opengis.geometry.Geometry) {
                final Marshaller marshaller = POOL.acquireMarshaller();
                marshaller.setProperty(marshaller.JAXB_FRAGMENT, Boolean.TRUE);
                marshaller.marshal(new ObjectFactory().createValue(value), writer);
                POOL.recycle(marshaller);
            } else {
                writer.writeStartElement(WFS_PREFIX, TAG_VALUE, WFS_NAMESPACE);
                QName qname = Utils.getQNameFromType(propertyType, "");
                writer.writeAttribute(XSI_PREFIX, XSI_NAMESPACE, PROP_TYPE, qname.getLocalPart());
                writer.writeCharacters(Utils.getStringValue(value));
                writer.writeEndElement();
            }
        }
        writer.writeEndElement();
    }
    writer.writeEndElement();
}
Also used : Marshaller(javax.xml.bind.Marshaller) AbstractGeometryType(org.geotoolkit.gml.xml.v311.AbstractGeometryType) QName(javax.xml.namespace.QName) GeometryPropertyType(org.geotoolkit.gml.xml.v311.GeometryPropertyType) PropertyType(org.opengis.feature.PropertyType) JTStoGeometry(org.geotoolkit.gml.JTStoGeometry) Geometry(org.locationtech.jts.geom.Geometry) GenericName(org.opengis.util.GenericName) ObjectFactory(org.geotoolkit.internal.jaxb.ObjectFactory) Filter(org.opengis.filter.Filter) XMLFilter(org.geotoolkit.ogc.xml.XMLFilter) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) GeometryPropertyType(org.geotoolkit.gml.xml.v311.GeometryPropertyType)

Aggregations

ObjectFactory (org.geotoolkit.internal.jaxb.ObjectFactory)2 File (java.io.File)1 Marshaller (javax.xml.bind.Marshaller)1 QName (javax.xml.namespace.QName)1 Schema (javax.xml.validation.Schema)1 SchemaFactory (javax.xml.validation.SchemaFactory)1 JTStoGeometry (org.geotoolkit.gml.JTStoGeometry)1 AbstractGeometryType (org.geotoolkit.gml.xml.v311.AbstractGeometryType)1 GeometryPropertyType (org.geotoolkit.gml.xml.v311.GeometryPropertyType)1 XMLFilter (org.geotoolkit.ogc.xml.XMLFilter)1 Geometry (org.locationtech.jts.geom.Geometry)1 PropertyType (org.opengis.feature.PropertyType)1 Filter (org.opengis.filter.Filter)1 CoordinateReferenceSystem (org.opengis.referencing.crs.CoordinateReferenceSystem)1 GenericName (org.opengis.util.GenericName)1