Commit 4ef4c11f authored by Matthias Betz's avatar Matthias Betz
Browse files

added type adapters

added validation tests
parent 5fe70e14
......@@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>de.hft.stuttgart</groupId>
<artifactId>citygml4j-quality-ade</artifactId>
<version>0.1.3</version>
<version>3.1.4</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
......
/*-
* Copyright 2022 Hochschule für Technik Stuttgart
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package de.hft.stuttgart.quality.adapter.properties;
import javax.xml.namespace.QName;
import org.xmlobjects.builder.ObjectBuildException;
import org.xmlobjects.gml.adapter.base.AbstractInlineOrByReferencePropertyAdapter;
import de.hft.stuttgart.quality.model.properties.ValidationResultProperty;
public class ValidationResultPropertyAdapter
extends AbstractInlineOrByReferencePropertyAdapter<ValidationResultProperty> {
@Override
public ValidationResultProperty createObject(QName name, Object parent) throws ObjectBuildException {
return new ValidationResultProperty();
}
}
package de.hft.stuttgart.quality.adapter.types;
import org.xmlobjects.builder.ObjectBuilder;
import org.xmlobjects.serializer.ObjectSerializer;
import de.hft.stuttgart.quality.model.types.AbstractError;
public abstract class AbstractErrorAdapter<T extends AbstractError> implements ObjectBuilder<T>, ObjectSerializer<T> {
}
package de.hft.stuttgart.quality.adapter.types;
import de.hft.stuttgart.quality.model.types.AbstractGeometryError;
public abstract class AbstractGeometryErrorAdapter<T extends AbstractGeometryError> extends AbstractErrorAdapter<T> {
}
package de.hft.stuttgart.quality.adapter.types;
import javax.xml.namespace.QName;
import org.xmlobjects.builder.ObjectBuildException;
import org.xmlobjects.serializer.ObjectSerializeException;
import org.xmlobjects.stream.XMLReadException;
import org.xmlobjects.stream.XMLReader;
import org.xmlobjects.stream.XMLWriteException;
import org.xmlobjects.stream.XMLWriter;
import org.xmlobjects.xml.Attributes;
import org.xmlobjects.xml.Element;
import org.xmlobjects.xml.Namespaces;
import de.hft.stuttgart.quality.QualityADEModule;
import de.hft.stuttgart.quality.model.types.AbstractPolygonError;
public abstract class AbstractPolygonErrorAdapter<T extends AbstractPolygonError> extends AbstractGeometryErrorAdapter<T> {
@Override
public void buildChildObject(AbstractPolygonError object, QName name, Attributes attributes, XMLReader reader) throws ObjectBuildException, XMLReadException {
if (!QualityADEModule.NAMESPACE_URI.equals(name.getNamespaceURI())) {
return;
}
switch (name.getLocalPart()) {
case "polygonId" -> reader.getTextContent().ifPresent(object::setPolygonId);
default -> throw new IllegalStateException("Cannot handle name " + name + " when building AbstractPolygonError element");
}
}
@Override
public void writeChildElements(AbstractPolygonError object, Namespaces namespaces, XMLWriter writer) throws ObjectSerializeException, XMLWriteException {
if (object.getPolygonId() != null) {
writer.writeElement(Element.of(QualityADEModule.NAMESPACE_URI, "polygonId").addTextContent(object.getPolygonId()));
}
}
}
package de.hft.stuttgart.quality.adapter.types;
import javax.xml.namespace.QName;
import org.xmlobjects.builder.ObjectBuildException;
import org.xmlobjects.serializer.ObjectSerializeException;
import org.xmlobjects.stream.XMLReadException;
import org.xmlobjects.stream.XMLReader;
import org.xmlobjects.stream.XMLWriteException;
import org.xmlobjects.stream.XMLWriter;
import org.xmlobjects.xml.Attributes;
import org.xmlobjects.xml.Element;
import org.xmlobjects.xml.Namespaces;
import de.hft.stuttgart.quality.QualityADEModule;
import de.hft.stuttgart.quality.model.types.AbstractRingError;
public abstract class AbstractRingErrorAdapter<T extends AbstractRingError> extends AbstractGeometryErrorAdapter<T> {
@Override
public void buildChildObject(AbstractRingError object, QName name, Attributes attributes, XMLReader reader) throws ObjectBuildException, XMLReadException {
if (!QualityADEModule.NAMESPACE_URI.equals(name.getNamespaceURI())) {
return;
}
switch (name.getLocalPart()) {
case "linearRingId" -> reader.getTextContent().ifPresent(object::setLinearRingId);
}
}
@Override
public void writeChildElements(AbstractRingError object, Namespaces namespaces, XMLWriter writer) throws ObjectSerializeException, XMLWriteException {
if (object.getLinearRingId() != null) {
writer.writeElement(Element.of(QualityADEModule.NAMESPACE_URI, "linearRingId").addTextContent(object.getLinearRingId()));
}
}
}
package de.hft.stuttgart.quality.adapter.types;
import de.hft.stuttgart.quality.model.types.AbstractSemanticError;
public abstract class AbstractSemanticErrorAdapter<T extends AbstractSemanticError> extends AbstractErrorAdapter<T> {
}
package de.hft.stuttgart.quality.adapter.types;
import javax.xml.namespace.QName;
import org.xmlobjects.builder.ObjectBuildException;
import org.xmlobjects.serializer.ObjectSerializeException;
import org.xmlobjects.stream.XMLReadException;
import org.xmlobjects.stream.XMLReader;
import org.xmlobjects.stream.XMLWriteException;
import org.xmlobjects.stream.XMLWriter;
import org.xmlobjects.xml.Attributes;
import org.xmlobjects.xml.Element;
import org.xmlobjects.xml.Namespaces;
import de.hft.stuttgart.quality.QualityADEModule;
import de.hft.stuttgart.quality.model.types.AbstractSolidError;
public abstract class AbstractSolidErrorAdapter<T extends AbstractSolidError> extends AbstractGeometryErrorAdapter<T> {
@Override
public void buildChildObject(AbstractSolidError object, QName name, Attributes attributes, XMLReader reader) throws ObjectBuildException, XMLReadException {
if (!QualityADEModule.NAMESPACE_URI.equals(name.getNamespaceURI())) {
return;
}
switch (name.getLocalPart()) {
case "geometryId" -> reader.getTextContent().ifPresent(object::setGeometryId);
default -> throw new IllegalStateException("Cannot handle name " + name + " when building AbstractSolidError element");
}
}
@Override
public void writeChildElements(AbstractSolidError object, Namespaces namespaces, XMLWriter writer) throws ObjectSerializeException, XMLWriteException {
if (object.getGeometryId() != null) {
writer.writeElement(Element.of(QualityADEModule.NAMESPACE_URI, "geometryId").addTextContent(object.getGeometryId()));
}
}
}
package de.hft.stuttgart.quality.adapter.types;
import javax.xml.namespace.QName;
import org.xmlobjects.annotation.XMLElement;
import org.xmlobjects.builder.ObjectBuildException;
import org.xmlobjects.serializer.ObjectSerializeException;
import org.xmlobjects.xml.Element;
import org.xmlobjects.xml.Namespaces;
import de.hft.stuttgart.quality.QualityADEModule;
import de.hft.stuttgart.quality.model.types.AllPolygonsOrientedWrongError;
@XMLElement(name = "GE_S_ALL_POLYGONS_WRONG_ORIENTATION", namespaceURI = QualityADEModule.NAMESPACE_URI)
public class AllPolygonsOrientedWrongErrorAdapter extends AbstractSolidErrorAdapter<AllPolygonsOrientedWrongError> {
@Override
public AllPolygonsOrientedWrongError createObject(QName name, Object parent) throws ObjectBuildException {
return new AllPolygonsOrientedWrongError();
}
@Override
public Element createElement(AllPolygonsOrientedWrongError object, Namespaces namespaces)
throws ObjectSerializeException {
return Element.of(QualityADEModule.NAMESPACE_URI, "GE_S_ALL_POLYGONS_WRONG_ORIENTATION");
}
}
package de.hft.stuttgart.quality.adapter.types;
import de.hft.stuttgart.quality.model.enums.TopLevelFeatureType;
import de.hft.stuttgart.quality.model.types.Checking;
import de.hft.stuttgart.quality.QualityADEModule;
import org.xmlobjects.annotation.XMLElement;
import org.xmlobjects.builder.ObjectBuildException;
import org.xmlobjects.builder.ObjectBuilder;
import org.xmlobjects.serializer.ObjectSerializeException;
import org.xmlobjects.serializer.ObjectSerializer;
import org.xmlobjects.stream.XMLReadException;
import org.xmlobjects.stream.XMLReader;
import org.xmlobjects.stream.XMLWriteException;
import org.xmlobjects.stream.XMLWriter;
import org.xmlobjects.xml.Attributes;
import org.xmlobjects.xml.Element;
import org.xmlobjects.xml.Namespaces;
import javax.xml.namespace.QName;
@XMLElement(name = "Checking", namespaceURI = QualityADEModule.NAMESPACE_URI)
public class CheckingAdapter implements ObjectBuilder<Checking>, ObjectSerializer<Checking> {
@Override
public Checking createObject(QName name, Object parent) throws ObjectBuildException {
return new Checking();
}
@Override
public void buildChildObject(Checking object, QName name, Attributes attributes, XMLReader reader)
throws ObjectBuildException, XMLReadException {
if (!QualityADEModule.NAMESPACE_URI.equals(name.getNamespaceURI())) {
return;
}
switch (name.getLocalPart()) {
case "featureType" -> reader.getTextContent()
.ifPresent(s -> object.setFeatureType(TopLevelFeatureType.valueOf(s)));
default -> throw new IllegalStateException("Cannot handle name " + name + " when building Checking element");
}
}
@Override
public Element createElement(Checking object, Namespaces namespaces) throws ObjectSerializeException {
return Element.of(QualityADEModule.NAMESPACE_URI, "Checking");
}
@Override
public void writeChildElements(Checking object, Namespaces namespaces, XMLWriter writer)
throws ObjectSerializeException, XMLWriteException {
if (object.getFeatureType() != null) {
writer.writeElement(Element.of(QualityADEModule.NAMESPACE_URI, "featureType")
.addTextContent(object.getFeatureType().toString()));
}
}
}
package de.hft.stuttgart.quality.adapter.types;
import javax.xml.namespace.QName;
import org.xmlobjects.annotation.XMLElement;
import org.xmlobjects.builder.ObjectBuildException;
import org.xmlobjects.builder.ObjectBuilder;
import org.xmlobjects.serializer.ObjectSerializeException;
import org.xmlobjects.serializer.ObjectSerializer;
import org.xmlobjects.stream.XMLReadException;
import org.xmlobjects.stream.XMLReader;
import org.xmlobjects.stream.XMLWriteException;
import org.xmlobjects.stream.XMLWriter;
import org.xmlobjects.xml.Attributes;
import org.xmlobjects.xml.Element;
import org.xmlobjects.xml.Namespaces;
import de.hft.stuttgart.quality.QualityADEModule;
import de.hft.stuttgart.quality.adapter.properties.ValidationResultPropertyAdapter;
import de.hft.stuttgart.quality.model.types.CityObjectProperties;
@XMLElement(name = "validationResult", namespaceURI = QualityADEModule.NAMESPACE_URI)
public class CityObjectPropertiesAdapter implements ObjectBuilder<CityObjectProperties>, ObjectSerializer<CityObjectProperties> {
@Override
public CityObjectProperties createObject(QName name, Object parent) throws ObjectBuildException {
return new CityObjectProperties();
}
@Override
public void buildChildObject(CityObjectProperties object, QName name, Attributes attributes, XMLReader reader) throws ObjectBuildException, XMLReadException {
if (!QualityADEModule.NAMESPACE_URI.equals(name.getNamespaceURI())) {
return;
}
switch (name.getLocalPart()) {
case "validationResult" -> object.setValidationResult(reader.getObjectUsingBuilder(ValidationResultPropertyAdapter.class));
default -> throw new IllegalStateException("Cannot handle name " + name + " when building CityObjectProperties element");
}
}
@Override
public void writeChildElements(CityObjectProperties object, Namespaces namespaces, XMLWriter writer) throws ObjectSerializeException, XMLWriteException {
if (object.getValidationResult() != null) {
writer.writeElementUsingSerializer(Element.of(QualityADEModule.NAMESPACE_URI, "validationResult"), object.getValidationResult(), ValidationResultPropertyAdapter.class, namespaces);
}
}
}
package de.hft.stuttgart.quality.adapter.types;
import javax.xml.namespace.QName;
import org.xmlobjects.annotation.XMLElement;
import org.xmlobjects.builder.ObjectBuildException;
import org.xmlobjects.builder.ObjectBuilder;
import org.xmlobjects.serializer.ObjectSerializeException;
import org.xmlobjects.serializer.ObjectSerializer;
import org.xmlobjects.stream.XMLReadException;
import org.xmlobjects.stream.XMLReader;
import org.xmlobjects.stream.XMLWriteException;
import org.xmlobjects.stream.XMLWriter;
import org.xmlobjects.xml.Attributes;
import org.xmlobjects.xml.Element;
import org.xmlobjects.xml.Namespaces;
import de.hft.stuttgart.quality.QualityADEModule;
import de.hft.stuttgart.quality.adapter.properties.PolygonIdListPropertyAdapter;
import de.hft.stuttgart.quality.model.properties.PolygonIdListProperty;
import de.hft.stuttgart.quality.model.types.ComponentList;
@XMLElement(name = "ComponentList", namespaceURI = QualityADEModule.NAMESPACE_URI)
public class ComponentListAdapter implements ObjectBuilder<ComponentList>, ObjectSerializer<ComponentList> {
@Override
public ComponentList createObject(QName name, Object parent) throws ObjectBuildException {
return new ComponentList();
}
@Override
public void buildChildObject(ComponentList object, QName name, Attributes attributes, XMLReader reader)
throws ObjectBuildException, XMLReadException {
if (!QualityADEModule.NAMESPACE_URI.equals(name.getNamespaceURI())) {
return;
}
switch (name.getLocalPart()) {
case "component" -> object.getComponents()
.add(reader.getObjectUsingBuilder(PolygonIdListPropertyAdapter.class));
default -> throw new IllegalStateException(
"Cannot handle name " + name + " when building ComponentList element");
}
}
@Override
public Element createElement(ComponentList object, Namespaces namespaces) throws ObjectSerializeException {
return Element.of(QualityADEModule.NAMESPACE_URI, "ComponentList");
}
@Override
public void writeChildElements(ComponentList object, Namespaces namespaces, XMLWriter writer)
throws ObjectSerializeException, XMLWriteException {
for (PolygonIdListProperty listProperty : object.getComponents()) {
writer.writeElementUsingSerializer(Element.of(QualityADEModule.NAMESPACE_URI, "component"), listProperty,
PolygonIdListPropertyAdapter.class, namespaces);
}
}
}
package de.hft.stuttgart.quality.adapter.types;
import javax.xml.namespace.QName;
import org.xmlobjects.annotation.XMLElement;
import org.xmlobjects.builder.ObjectBuildException;
import org.xmlobjects.gml.adapter.geometry.DirectPositionAdapter;
import org.xmlobjects.serializer.ObjectSerializeException;
import org.xmlobjects.stream.XMLReadException;
import org.xmlobjects.stream.XMLReader;
import org.xmlobjects.stream.XMLWriteException;
import org.xmlobjects.stream.XMLWriter;
import org.xmlobjects.xml.Attributes;
import org.xmlobjects.xml.Element;
import org.xmlobjects.xml.Namespaces;
import de.hft.stuttgart.quality.QualityADEModule;
import de.hft.stuttgart.quality.model.types.ConsecutivePointsSameError;
@XMLElement(name = "GE_R_CONSECUTIVE_POINTS_SAME", namespaceURI = QualityADEModule.NAMESPACE_URI)
public class ConsecutivePointsSameErrorAdapter extends AbstractRingErrorAdapter<ConsecutivePointsSameError> {
@Override
public ConsecutivePointsSameError createObject(QName name, Object parent) throws ObjectBuildException {
return new ConsecutivePointsSameError();
}
@Override
public void buildChildObject(ConsecutivePointsSameError object, QName name, Attributes attributes, XMLReader reader)
throws ObjectBuildException, XMLReadException {
if (!QualityADEModule.NAMESPACE_URI.equals(name.getNamespaceURI())) {
return;
}
switch (name.getLocalPart()) {
case "vertex1" -> object.setVertex1(reader.getObjectUsingBuilder(DirectPositionAdapter.class));
case "vertex2" -> object.setVertex2(reader.getObjectUsingBuilder(DirectPositionAdapter.class));
default -> super.buildChildObject(object, name, attributes, reader);
}
}
@Override
public Element createElement(ConsecutivePointsSameError object, Namespaces namespaces)
throws ObjectSerializeException {
return Element.of(QualityADEModule.NAMESPACE_URI, "GE_R_CONSECUTIVE_POINTS_SAME");
}
@Override
public void writeChildElements(ConsecutivePointsSameError object, Namespaces namespaces, XMLWriter writer)
throws ObjectSerializeException, XMLWriteException {
super.writeChildElements(object, namespaces, writer);
if (object.getVertex1() != null) {
writer.writeElementUsingSerializer(Element.of(QualityADEModule.NAMESPACE_URI, "vertex1"),
object.getVertex1(), DirectPositionAdapter.class, namespaces);
}
if (object.getVertex2() != null) {
writer.writeElementUsingSerializer(Element.of(QualityADEModule.NAMESPACE_URI, "vertex2"),
object.getVertex2(), DirectPositionAdapter.class, namespaces);
}
}
}
package de.hft.stuttgart.quality.adapter.types;
import javax.xml.namespace.QName;
import org.xmlobjects.annotation.XMLElement;
import org.xmlobjects.builder.ObjectBuildException;
import org.xmlobjects.builder.ObjectBuilder;
import org.xmlobjects.gml.adapter.geometry.DirectPositionAdapter;
import org.xmlobjects.serializer.ObjectSerializeException;
import org.xmlobjects.serializer.ObjectSerializer;
import org.xmlobjects.stream.XMLReadException;
import org.xmlobjects.stream.XMLReader;
import org.xmlobjects.stream.XMLWriteException;
import org.xmlobjects.stream.XMLWriter;
import org.xmlobjects.xml.Attributes;
import org.xmlobjects.xml.Element;
import org.xmlobjects.xml.Namespaces;
import de.hft.stuttgart.quality.QualityADEModule;
import de.hft.stuttgart.quality.model.types.Edge;
@XMLElement(name = "Edge", namespaceURI = QualityADEModule.NAMESPACE_URI)
public class EdgeAdapter implements ObjectBuilder<Edge>, ObjectSerializer<Edge> {
@Override
public Edge createObject(QName name, Object parent) throws ObjectBuildException {
return new Edge();
}
@Override
public void buildChildObject(Edge object, QName name, Attributes attributes, XMLReader reader) throws ObjectBuildException, XMLReadException {
if (!QualityADEModule.NAMESPACE_URI.equals(name.getNamespaceURI())) {
return;
}
switch (name.getLocalPart()) {
case "from" -> object.setFrom(reader.getObjectUsingBuilder(DirectPositionAdapter.class));
case "to" -> object.setTo(reader.getObjectUsingBuilder(DirectPositionAdapter.class));
default -> throw new IllegalStateException("Cannot handle name " + name + " when building Edge element");
}
}
@Override
public Element createElement(Edge object, Namespaces namespaces) throws ObjectSerializeException {
return Element.of(QualityADEModule.NAMESPACE_URI, "Edge");
}
@Override
public void writeChildElements(Edge object, Namespaces namespaces, XMLWriter writer) throws ObjectSerializeException, XMLWriteException {
if (object.getFrom() != null) {
writer.writeElementUsingSerializer(Element.of(QualityADEModule.NAMESPACE_URI, "from"), object.getFrom(), DirectPositionAdapter.class, namespaces);
}
if (object.getTo() != null) {
writer.writeElementUsingSerializer(Element.of(QualityADEModule.NAMESPACE_URI, "to"), object.getTo(), DirectPositionAdapter.class, namespaces);
}
}
}
package de.hft.stuttgart.quality.adapter.types;
import javax.xml.namespace.QName;
import org.xmlobjects.annotation.XMLElement;
import org.xmlobjects.builder.ObjectBuildException;
import org.xmlobjects.builder.ObjectBuilder;
import org.xmlobjects.serializer.ObjectSerializeException;
import org.xmlobjects.serializer.ObjectSerializer;
import org.xmlobjects.stream.XMLReadException;
import org.xmlobjects.stream.XMLReader;
import org.xmlobjects.stream.XMLWriteException;
import org.xmlobjects.stream.XMLWriter;
import org.xmlobjects.xml.Attributes;
import org.xmlobjects.xml.Element;
import org.xmlobjects.xml.Namespaces;
import de.hft.stuttgart.quality.QualityADEModule;
import de.hft.stuttgart.quality.adapter.properties.EdgePropertyAdapter;
import de.hft.stuttgart.quality.model.properties.EdgeProperty;
import de.hft.stuttgart.quality.model.types.EdgeList;
@XMLElement(name = "EdgeList", namespaceURI = QualityADEModule.NAMESPACE_URI)
public class EdgeListAdapter implements ObjectBuilder<EdgeList>, ObjectSerializer<EdgeList> {
@Override
public EdgeList createObject(QName name, Object parent) throws ObjectBuildException {
return new EdgeList();
}
@Override
public void buildChildObject(EdgeList object, QName name, Attributes attributes, XMLReader reader)
throws ObjectBuildException, XMLReadException {
if (!QualityADEModule.NAMESPACE_URI.equals(name.getNamespaceURI())) {
return;
}
switch (name.getLocalPart()) {
case "edge" -> object.getEdges().add(reader.getObjectUsingBuilder(EdgePropertyAdapter.class));
default -> throw new IllegalStateException("Cannot handle name " + name + " when building EdgeList element");
}