
org.citygml4j.xml.adapter.deprecated.tunnel.AbstractTunnelAdapter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of citygml4j-xml Show documentation
Show all versions of citygml4j-xml Show documentation
The Open Source Java API for CityGML
/*
* citygml4j - The Open Source Java API for CityGML
* https://github.com/citygml4j
*
* Copyright 2013-2025 Claus Nagel
*
* 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 org.citygml4j.xml.adapter.deprecated.tunnel;
import org.citygml4j.core.model.ade.generic.GenericADEOfAbstractTunnel;
import org.citygml4j.core.model.construction.RelationToConstruction;
import org.citygml4j.core.model.core.AbstractSpaceBoundaryProperty;
import org.citygml4j.core.model.deprecated.tunnel.DeprecatedPropertiesOfAbstractTunnel;
import org.citygml4j.core.model.tunnel.*;
import org.citygml4j.core.util.CityGMLConstants;
import org.citygml4j.xml.adapter.CityGMLBuilderHelper;
import org.citygml4j.xml.adapter.CityGMLSerializerHelper;
import org.citygml4j.xml.adapter.ade.ADEBuilderHelper;
import org.citygml4j.xml.adapter.ade.ADESerializerHelper;
import org.citygml4j.xml.adapter.core.AbstractSpaceBoundaryPropertyAdapter;
import org.citygml4j.xml.adapter.deprecated.core.AbstractSiteAdapter;
import org.citygml4j.xml.adapter.tunnel.HollowSpacePropertyAdapter;
import org.citygml4j.xml.adapter.tunnel.TunnelInstallationPropertyAdapter;
import org.citygml4j.xml.adapter.tunnel.TunnelPartPropertyAdapter;
import org.xmlobjects.builder.ObjectBuildException;
import org.xmlobjects.gml.adapter.geometry.aggregates.MultiCurvePropertyAdapter;
import org.xmlobjects.gml.adapter.geometry.aggregates.MultiSurfacePropertyAdapter;
import org.xmlobjects.gml.adapter.geometry.primitives.SolidPropertyAdapter;
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 org.xmlobjects.xml.TextContent;
import javax.xml.namespace.QName;
import java.time.LocalTime;
import java.time.OffsetDateTime;
import java.time.ZoneOffset;
public abstract class AbstractTunnelAdapter extends AbstractSiteAdapter {
private final QName substitutionGroup = new QName(CityGMLConstants.CITYGML_2_0_TUNNEL_NAMESPACE, "_GenericApplicationPropertyOfAbstractTunnel");
@Override
public void buildChildObject(T object, QName name, Attributes attributes, XMLReader reader) throws ObjectBuildException, XMLReadException {
if (CityGMLBuilderHelper.isTunnelNamespace(name.getNamespaceURI())) {
if (CityGMLBuilderHelper.buildStandardObjectClassifier(object, name.getLocalPart(), reader))
return;
switch (name.getLocalPart()) {
case "yearOfConstruction":
reader.getTextContent().ifGYear(v -> object.setDateOfConstruction(v.toLocalDate()));
return;
case "yearOfDemolition":
reader.getTextContent().ifGYear(v -> object.setDateOfDemolition(v.toLocalDate()));
return;
case "lod1Solid":
object.setLod1Solid(reader.getObjectUsingBuilder(SolidPropertyAdapter.class));
return;
case "lod1MultiSurface":
object.getDeprecatedProperties().setLod1MultiSurface(reader.getObjectUsingBuilder(MultiSurfacePropertyAdapter.class));
return;
case "lod1TerrainIntersection":
object.setLod1TerrainIntersectionCurve(reader.getObjectUsingBuilder(MultiCurvePropertyAdapter.class));
return;
case "lod2Solid":
object.setLod2Solid(reader.getObjectUsingBuilder(SolidPropertyAdapter.class));
return;
case "lod2MultiSurface":
object.setLod2MultiSurface(reader.getObjectUsingBuilder(MultiSurfacePropertyAdapter.class));
return;
case "lod2MultiCurve":
object.setLod2MultiCurve(reader.getObjectUsingBuilder(MultiCurvePropertyAdapter.class));
return;
case "lod2TerrainIntersection":
object.setLod2TerrainIntersectionCurve(reader.getObjectUsingBuilder(MultiCurvePropertyAdapter.class));
return;
case "outerTunnelInstallation":
case "interiorTunnelInstallation":
object.getTunnelInstallations().add(reader.getObjectUsingBuilder(TunnelInstallationPropertyAdapter.class));
return;
case "boundedBy":
object.addBoundary(reader.getObjectUsingBuilder(AbstractSpaceBoundaryPropertyAdapter.class));
return;
case "lod3Solid":
object.setLod3Solid(reader.getObjectUsingBuilder(SolidPropertyAdapter.class));
return;
case "lod3MultiSurface":
object.setLod3MultiSurface(reader.getObjectUsingBuilder(MultiSurfacePropertyAdapter.class));
return;
case "lod3MultiCurve":
object.setLod3MultiCurve(reader.getObjectUsingBuilder(MultiCurvePropertyAdapter.class));
return;
case "lod3TerrainIntersection":
object.setLod3TerrainIntersectionCurve(reader.getObjectUsingBuilder(MultiCurvePropertyAdapter.class));
return;
case "lod4Solid":
object.getDeprecatedProperties().setLod4Solid(reader.getObjectUsingBuilder(SolidPropertyAdapter.class));
return;
case "lod4MultiSurface":
object.getDeprecatedProperties().setLod4MultiSurface(reader.getObjectUsingBuilder(MultiSurfacePropertyAdapter.class));
return;
case "lod4MultiCurve":
object.getDeprecatedProperties().setLod4MultiCurve(reader.getObjectUsingBuilder(MultiCurvePropertyAdapter.class));
return;
case "lod4TerrainIntersection":
object.getDeprecatedProperties().setLod4TerrainIntersectionCurve(reader.getObjectUsingBuilder(MultiCurvePropertyAdapter.class));
return;
case "interiorHollowSpace":
object.getHollowSpaces().add(reader.getObjectUsingBuilder(HollowSpacePropertyAdapter.class));
return;
case "consistsOfTunnelPart":
TunnelPartProperty consistsOfTunnelPart = reader.getObjectUsingBuilder(TunnelPartPropertyAdapter.class);
if ((consistsOfTunnelPart.getObject() != null || consistsOfTunnelPart.getGenericElement() != null)
&& object instanceof Tunnel tunnel)
tunnel.getTunnelParts().add(consistsOfTunnelPart);
else
object.getDeprecatedProperties().getConsistsOfTunnelParts().add(consistsOfTunnelPart);
return;
}
} else if (CityGMLBuilderHelper.isADENamespace(name.getNamespaceURI())) {
buildADEProperty(object, name, reader);
return;
}
super.buildChildObject(object, name, attributes, reader);
}
@Override
public void buildADEProperty(T object, QName name, XMLReader reader) throws ObjectBuildException, XMLReadException {
if (!ADEBuilderHelper.addADEProperty(object, name, GenericADEOfAbstractTunnel::of, reader, substitutionGroup))
super.buildADEProperty(object, name, reader);
}
@Override
public void writeChildElements(T object, Namespaces namespaces, XMLWriter writer) throws ObjectSerializeException, XMLWriteException {
super.writeChildElements(object, namespaces, writer);
String tunnelNamespace = CityGMLSerializerHelper.getTunnelNamespace(namespaces);
DeprecatedPropertiesOfAbstractTunnel properties = object.hasDeprecatedProperties() ?
object.getDeprecatedProperties() :
null;
CityGMLSerializerHelper.writeStandardObjectClassifier(object, tunnelNamespace, namespaces, writer);
if (object.getDateOfConstruction() != null)
writer.writeElement(Element.of(tunnelNamespace, "yearOfConstruction").addTextContent(TextContent.ofGYear(OffsetDateTime.of(object.getDateOfConstruction(), LocalTime.MIN, ZoneOffset.UTC))));
if (object.getDateOfDemolition() != null)
writer.writeElement(Element.of(tunnelNamespace, "yearOfDemolition").addTextContent(TextContent.ofGYear(OffsetDateTime.of(object.getDateOfDemolition(), LocalTime.MIN, ZoneOffset.UTC))));
if (object.getLod1Solid() != null)
writer.writeElementUsingSerializer(Element.of(tunnelNamespace, "lod1Solid"), object.getLod1Solid(), SolidPropertyAdapter.class, namespaces);
if (properties != null && properties.getLod1MultiSurface() != null)
writer.writeElementUsingSerializer(Element.of(tunnelNamespace, "lod1MultiSurface"), properties.getLod1MultiSurface(), MultiSurfacePropertyAdapter.class, namespaces);
if (object.getLod1TerrainIntersectionCurve() != null)
writer.writeElementUsingSerializer(Element.of(tunnelNamespace, "lod1TerrainIntersection"), object.getLod1TerrainIntersectionCurve(), MultiCurvePropertyAdapter.class, namespaces);
if (object.getLod2Solid() != null)
writer.writeElementUsingSerializer(Element.of(tunnelNamespace, "lod2Solid"), object.getLod2Solid(), SolidPropertyAdapter.class, namespaces);
if (object.getLod2MultiSurface() != null)
writer.writeElementUsingSerializer(Element.of(tunnelNamespace, "lod2MultiSurface"), object.getLod2MultiSurface(), MultiSurfacePropertyAdapter.class, namespaces);
if (object.getLod2MultiCurve() != null)
writer.writeElementUsingSerializer(Element.of(tunnelNamespace, "lod2MultiCurve"), object.getLod2MultiCurve(), MultiCurvePropertyAdapter.class, namespaces);
if (object.getLod2TerrainIntersectionCurve() != null)
writer.writeElementUsingSerializer(Element.of(tunnelNamespace, "lod2TerrainIntersection"), object.getLod2TerrainIntersectionCurve(), MultiCurvePropertyAdapter.class, namespaces);
if (object.isSetTunnelInstallations()) {
for (TunnelInstallationProperty property : object.getTunnelInstallations()) {
if (property.getObject() != null && property.getObject().getRelationToConstruction() != RelationToConstruction.INSIDE)
writer.writeElementUsingSerializer(Element.of(tunnelNamespace, "outerTunnelInstallation"), property, TunnelInstallationPropertyAdapter.class, namespaces);
else
writer.writeElementUsingSerializer(Element.of(tunnelNamespace, "interiorTunnelInstallation"), property, TunnelInstallationPropertyAdapter.class, namespaces);
}
}
if (object.isSetBoundaries()) {
for (AbstractSpaceBoundaryProperty property : object.getBoundaries())
writer.writeElementUsingSerializer(Element.of(tunnelNamespace, "boundedBy"), property, AbstractBoundarySurfacePropertyAdapter.class, namespaces);
}
if (object.getLod3Solid() != null)
writer.writeElementUsingSerializer(Element.of(tunnelNamespace, "lod3Solid"), object.getLod3Solid(), SolidPropertyAdapter.class, namespaces);
if (object.getLod3MultiSurface() != null)
writer.writeElementUsingSerializer(Element.of(tunnelNamespace, "lod3MultiSurface"), object.getLod3MultiSurface(), MultiSurfacePropertyAdapter.class, namespaces);
if (object.getLod3MultiCurve() != null)
writer.writeElementUsingSerializer(Element.of(tunnelNamespace, "lod3MultiCurve"), object.getLod3MultiCurve(), MultiCurvePropertyAdapter.class, namespaces);
if (object.getLod3TerrainIntersectionCurve() != null)
writer.writeElementUsingSerializer(Element.of(tunnelNamespace, "lod3TerrainIntersection"), object.getLod3TerrainIntersectionCurve(), MultiCurvePropertyAdapter.class, namespaces);
if (properties != null && properties.getLod4Solid() != null)
writer.writeElementUsingSerializer(Element.of(tunnelNamespace, "lod4Solid"), properties.getLod4Solid(), SolidPropertyAdapter.class, namespaces);
if (properties != null && properties.getLod4MultiSurface() != null)
writer.writeElementUsingSerializer(Element.of(tunnelNamespace, "lod4MultiSurface"), properties.getLod4MultiSurface(), MultiSurfacePropertyAdapter.class, namespaces);
if (properties != null && properties.getLod4MultiCurve() != null)
writer.writeElementUsingSerializer(Element.of(tunnelNamespace, "lod4MultiCurve"), properties.getLod4MultiCurve(), MultiCurvePropertyAdapter.class, namespaces);
if (properties != null && properties.getLod4TerrainIntersectionCurve() != null)
writer.writeElementUsingSerializer(Element.of(tunnelNamespace, "lod4TerrainIntersection"), properties.getLod4TerrainIntersectionCurve(), MultiCurvePropertyAdapter.class, namespaces);
if (object.isSetHollowSpaces()) {
for (HollowSpaceProperty property : object.getHollowSpaces())
writer.writeElementUsingSerializer(Element.of(tunnelNamespace, "interiorHollowSpace"), property, HollowSpacePropertyAdapter.class, namespaces);
}
if (object instanceof Tunnel tunnel) {
if (tunnel.isSetTunnelParts()) {
for (TunnelPartProperty property : tunnel.getTunnelParts())
writer.writeElementUsingSerializer(Element.of(tunnelNamespace, "consistsOfTunnelPart"), property, TunnelPartPropertyAdapter.class, namespaces);
}
}
if (properties != null && properties.isSetConsistsOfTunnelParts()) {
for (TunnelPartProperty property : properties.getConsistsOfTunnelParts())
writer.writeElementUsingSerializer(Element.of(tunnelNamespace, "consistsOfTunnelPart"), property, TunnelPartPropertyAdapter.class, namespaces);
}
for (ADEOfAbstractTunnel property : object.getADEProperties(ADEOfAbstractTunnel.class))
ADESerializerHelper.writeADEProperty(property, namespaces, writer);
}
}