This is an automated email from the ASF dual-hosted git repository. desruisseaux pushed a commit to branch geoapi-3.1 in repository https://gitbox.apache.org/repos/asf/sis.git
commit 776a5fd686ade2c8e3ed4d2f0840cb59f4432de2 Author: Martin Desruisseaux <martin.desruisse...@geomatys.com> AuthorDate: Thu May 9 15:24:28 2024 +0200 Port the `TM_PeriodDuration` class from the main branch. It is still needed for the `geoapi-3.1` branch. --- .../sis/metadata/iso/maintenance/package-info.java | 4 +- .../pending/temporal/DefaultPeriodDuration.java | 69 ++++++++++++++ .../org/apache/sis/xml/bind/gts/TM_Duration.java | 19 ++-- .../apache/sis/xml/bind/gts/TM_PeriodDuration.java | 100 +++++++++++++++++++++ .../apache/sis/io/wkt/GeodeticObjectParser.java | 2 - 5 files changed, 183 insertions(+), 11 deletions(-) diff --git a/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/metadata/iso/maintenance/package-info.java b/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/metadata/iso/maintenance/package-info.java index 21fee06f10..3e90c57f02 100644 --- a/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/metadata/iso/maintenance/package-info.java +++ b/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/metadata/iso/maintenance/package-info.java @@ -83,7 +83,7 @@ @XmlJavaTypeAdapter(MD_Scope.class), @XmlJavaTypeAdapter(MD_ScopeCode.class), @XmlJavaTypeAdapter(MD_ScopeDescription.class), - @XmlJavaTypeAdapter(TM_Duration.class), + @XmlJavaTypeAdapter(TM_PeriodDuration.class), // Java types, primitive types and basic OGC types handling @XmlJavaTypeAdapter(FeatureTypeAdapter.class), @@ -106,4 +106,4 @@ import org.apache.sis.xml.privy.LegacyNamespaces; import org.apache.sis.xml.bind.gco.*; import org.apache.sis.xml.bind.metadata.*; import org.apache.sis.xml.bind.metadata.code.*; -import org.apache.sis.xml.bind.gts.TM_Duration; +import org.apache.sis.xml.bind.gts.TM_PeriodDuration; diff --git a/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/pending/temporal/DefaultPeriodDuration.java b/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/pending/temporal/DefaultPeriodDuration.java new file mode 100644 index 0000000000..d513bc6608 --- /dev/null +++ b/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/pending/temporal/DefaultPeriodDuration.java @@ -0,0 +1,69 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.apache.sis.pending.temporal; + +import java.util.List; +import java.io.Serializable; +import java.time.temporal.Temporal; +import java.time.temporal.TemporalAmount; +import java.time.temporal.TemporalUnit; +import org.opengis.temporal.PeriodDuration; + + +/** + * Default implementation of GeoAPI period duration. This is a temporary class; + * GeoAPI temporal interfaces are expected to change a lot in a future revision. + * + * @author Martin Desruisseaux (Geomatys) + */ +@SuppressWarnings("serial") +public final class DefaultPeriodDuration implements PeriodDuration, Serializable { + /** + * The temporal object providing the duration value. + */ + public final TemporalAmount duration; + + /** + * Creates a new duration. + */ + public DefaultPeriodDuration(final TemporalAmount duration) { + this.duration = duration; + } + + @Override public List<TemporalUnit> getUnits() {return duration.getUnits();} + @Override public long get (TemporalUnit unit) {return duration.get(unit);} + @Override public Temporal addTo (Temporal temporal) {return duration.addTo(temporal);} + @Override public Temporal subtractFrom(Temporal temporal) {return duration.subtractFrom(temporal);} + + /** String representation. */ + @Override public String toString() { + return duration.toString(); + } + + /** Hash code value of the time position. */ + @Override public int hashCode() { + return duration.hashCode() ^ 879337943; + } + + /** Compares with given object for equality. */ + @Override public boolean equals(final Object obj) { + if (obj instanceof DefaultPeriodDuration) { + duration.equals(((DefaultPeriodDuration) obj).duration); + } + return false; + } +} diff --git a/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/xml/bind/gts/TM_Duration.java b/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/xml/bind/gts/TM_Duration.java index 945dca99d8..1673c6bd7d 100644 --- a/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/xml/bind/gts/TM_Duration.java +++ b/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/xml/bind/gts/TM_Duration.java @@ -18,6 +18,10 @@ package org.apache.sis.xml.bind.gts; import java.math.BigDecimal; import java.math.BigInteger; +import java.time.Period; +import java.time.temporal.ChronoUnit; +import java.time.temporal.TemporalAmount; +import java.time.temporal.TemporalUnit; import javax.xml.datatype.Duration; import javax.xml.datatype.DatatypeConfigurationException; import jakarta.xml.bind.annotation.XmlElement; @@ -26,12 +30,6 @@ import org.apache.sis.xml.privy.XmlUtilities; import org.apache.sis.xml.bind.gco.PropertyType; import org.apache.sis.util.resources.Errors; -// Specific to the geoapi-3.1 and geoapi-4.0 branches: -import java.time.Period; -import java.time.temporal.ChronoUnit; -import java.time.temporal.TemporalAmount; -import java.time.temporal.TemporalUnit; - /** * Wraps a {@code gts:TM_Duration} element. @@ -52,7 +50,7 @@ public class TM_Duration extends PropertyType<TM_Duration, TemporalAmount> { * * @param metadata the metadata value to marshal. */ - private TM_Duration(final TemporalAmount metadata) { + TM_Duration(final TemporalAmount metadata) { super(metadata); } @@ -77,6 +75,13 @@ public class TM_Duration extends PropertyType<TM_Duration, TemporalAmount> { return TemporalAmount.class; } + /** + * Returns the wrapped metadata value. + */ + final TemporalAmount get() { + return metadata; + } + /** * Returns the {@code Duration} generated from the metadata value. * This method is systematically called at marshalling time by JAXB. diff --git a/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/xml/bind/gts/TM_PeriodDuration.java b/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/xml/bind/gts/TM_PeriodDuration.java new file mode 100644 index 0000000000..472c346555 --- /dev/null +++ b/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/xml/bind/gts/TM_PeriodDuration.java @@ -0,0 +1,100 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.apache.sis.xml.bind.gts; + +import java.time.temporal.TemporalAmount; +import javax.xml.datatype.Duration; +import jakarta.xml.bind.annotation.XmlElement; +import org.opengis.temporal.PeriodDuration; +import org.apache.sis.pending.temporal.DefaultPeriodDuration; +import org.apache.sis.xml.bind.gco.PropertyType; + + +/** + * Wraps a {@code gts:TM_PeriodDuration} element. + * + * @author Guilhem Legal (Geomatys) + * @author Martin Desruisseaux (Geomatys) + */ +public final class TM_PeriodDuration extends PropertyType<TM_PeriodDuration, PeriodDuration> { + /** + * Empty constructor for JAXB. + */ + public TM_PeriodDuration() { + } + + /** + * Wraps a Temporal Period Duration value at marshalling-time. + * + * @param metadata the metadata value to marshal. + */ + private TM_PeriodDuration(final PeriodDuration metadata) { + super(metadata); + } + + /** + * Returns the Period Duration value wrapped by a {@code gts:TM_PeriodDuration} element. + * + * @param value the value to marshal. + * @return the adapter which wraps the metadata value. + */ + @Override + protected TM_PeriodDuration wrap(final PeriodDuration value) { + return new TM_PeriodDuration(value); + } + + /** + * Returns the GeoAPI interface which is bound by this adapter. + * + * @return {@code PeriodDuration.class} + */ + @Override + protected final Class<PeriodDuration> getBoundType() { + return PeriodDuration.class; + } + + /** + * Returns the {@link Duration} generated from the metadata value. + * This method is systematically called at marshalling time by JAXB. + * + * @return the time period, or {@code null}. + */ + @XmlElement(name = "TM_PeriodDuration") + public final Duration getElement() { + if (metadata instanceof TemporalAmount) { + return new TM_Duration((TemporalAmount) metadata).getElement(); + } + return null; + } + + /** + * Sets the value from the {@link Duration}. + * This method is called at unmarshalling time by JAXB. + * + * @param duration the adapter to set. + */ + public final void setElement(final Duration duration) { + var p = new TM_Duration(); + p.setElement(duration); + TemporalAmount t = p.get(); + if (t == null || t instanceof PeriodDuration) { + metadata = (PeriodDuration) t; + } else { + metadata = new DefaultPeriodDuration(t); + } + } +} diff --git a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/io/wkt/GeodeticObjectParser.java b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/io/wkt/GeodeticObjectParser.java index 643d8ceb56..a62ad813c1 100644 --- a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/io/wkt/GeodeticObjectParser.java +++ b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/io/wkt/GeodeticObjectParser.java @@ -1446,7 +1446,6 @@ class GeodeticObjectParser extends MathTransformParser implements Comparator<Coo return null; } final String name = element.pullString("name"); - @SuppressWarnings("deprecation") RealizationMethod method = null; if (isWKT1) { method = VerticalDatumTypes.fromLegacy(element.pullInteger("datum")); @@ -1884,7 +1883,6 @@ class GeodeticObjectParser extends MathTransformParser implements Comparator<Coo * @return the {@code "VerticalCRS"} element as a {@link VerticalCRS} object. * @throws ParseException if the {@code "VerticalCRS"} element cannot be parsed. */ - @SuppressWarnings("deprecation") private SingleCRS parseVerticalCRS(final int mode, final Element parent, final boolean isBaseCRS) throws ParseException {