This is an automated email from the ASF dual-hosted git repository. asf-gitbox-commits pushed a commit to branch geoapi-4.0 in repository https://gitbox.apache.org/repos/asf/sis.git
commit 1d69ca30e831409b74706896d113681c70d51456 Author: jsorel <[email protected]> AuthorDate: Mon Nov 9 11:38:57 2026 +0100 feat(SLD): add OGC SLD classes --- .../apache/sis/style/sld1/CoverageConstraint.java | 128 ++++++++++++ .../org/apache/sis/style/sld1/CoverageExtent.java | 122 ++++++++++++ .../main/org/apache/sis/style/sld1/Extent.java | 121 +++++++++++ .../sis/style/sld1/FeatureTypeConstraint.java | 152 ++++++++++++++ .../org/apache/sis/style/sld1/InlineFeature.java | 93 +++++++++ .../main/org/apache/sis/style/sld1/Layer.java | 123 ++++++++++++ .../apache/sis/style/sld1/LayerConstraints.java | 59 ++++++ .../sis/style/sld1/LayerCoverageConstraints.java | 92 +++++++++ .../sis/style/sld1/LayerFeatureConstraints.java | 92 +++++++++ .../org/apache/sis/style/sld1/LayerSource.java | 43 ++++ .../main/org/apache/sis/style/sld1/NamedLayer.java | 155 +++++++++++++++ .../main/org/apache/sis/style/sld1/NamedStyle.java | 130 ++++++++++++ .../main/org/apache/sis/style/sld1/RangeAxis.java | 121 +++++++++++ .../main/org/apache/sis/style/sld1/RemoteOWS.java | 126 ++++++++++++ .../main/org/apache/sis/style/sld1/SLDElement.java | 85 ++++++++ .../sis/style/sld1/StyledLayerDescriptor.java | 221 +++++++++++++++++++++ .../org/apache/sis/style/sld1/UseSLDLibrary.java | 93 +++++++++ .../main/org/apache/sis/style/sld1/UserLayer.java | 170 ++++++++++++++++ .../org/apache/sis/style/sld1/package-info.java | 39 ++++ .../sis/style/sld1/CoverageConstraintTest.java | 150 ++++++++++++++ .../sis/style/sld1/FeatureTypeConstraintTest.java | 148 ++++++++++++++ .../apache/sis/style/sld1/InlineFeatureTest.java | 88 ++++++++ .../sis/style/sld1/LayerConstraintsTest.java | 93 +++++++++ .../org/apache/sis/style/sld1/NamedLayerTest.java | 131 ++++++++++++ .../org/apache/sis/style/sld1/NamedStyleTest.java | 94 +++++++++ .../org/apache/sis/style/sld1/RemoteOWSTest.java | 83 ++++++++ .../org/apache/sis/style/sld1/SLDTestCase.java | 113 +++++++++++ .../sis/style/sld1/StyledLayerDescriptorTest.java | 169 ++++++++++++++++ .../apache/sis/style/sld1/UseSLDLibraryTest.java | 66 ++++++ .../org/apache/sis/style/sld1/UserLayerTest.java | 163 +++++++++++++++ 30 files changed, 3463 insertions(+) diff --git a/endorsed/src/org.apache.sis.portrayal/main/org/apache/sis/style/sld1/CoverageConstraint.java b/endorsed/src/org.apache.sis.portrayal/main/org/apache/sis/style/sld1/CoverageConstraint.java new file mode 100644 index 0000000000..c17514d0b6 --- /dev/null +++ b/endorsed/src/org.apache.sis.portrayal/main/org/apache/sis/style/sld1/CoverageConstraint.java @@ -0,0 +1,128 @@ +/* + * 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.style.sld1; + +import java.util.Optional; + + +/** + * Restricts the layer's data to a specific coverage, + * optionally further restricted to some time or range axis values. + * + * @author Johann Sorel (Geomatys) + */ +public class CoverageConstraint extends SLDElement { + /** + * Name of the coverage to which this constraint applies, or {@code null} if none. + * + * @see #getCoverageName() + * @see #setCoverageName(String) + */ + protected String coverageName; + + /** + * Restriction on the time or range axis values of the coverage, or {@code null} if none. + * + * @see #getCoverageExtent() + * @see #setCoverageExtent(CoverageExtent) + */ + protected CoverageExtent coverageExtent; + + /** + * Creates an initially empty coverage constraint. + * Callers should set the {@linkplain #setCoverageName(String) coverage name} + * after construction, since this property is mandatory. + */ + public CoverageConstraint() { + } + + /** + * Creates a shallow copy of the given object. + * For a deep copy, see {@link #clone()} instead. + * + * @param source the object to copy. + */ + public CoverageConstraint(final CoverageConstraint source) { + coverageName = source.coverageName; + coverageExtent = source.coverageExtent; + } + + /** + * Returns the name of the coverage to which this constraint applies. + * + * @return name of the coverage to which this constraint applies. + */ + public Optional<String> getCoverageName() { + return Optional.ofNullable(coverageName); + } + + /** + * Sets the name of the coverage to which this constraint applies. + * If this method is never invoked, then the default value is absence. + * + * @param value new name of the coverage, or {@code null} if none. + */ + public void setCoverageName(final String value) { + coverageName = value; + } + + /** + * Returns the restriction on the time or range axis values of the coverage. + * If absent, the whole coverage is shown. + * The returned object is <em>live</em>: + * changes in the returned instance will be reflected in this constraint, and conversely. + * + * @return restriction on the time or range axis values of the coverage. + */ + public Optional<CoverageExtent> getCoverageExtent() { + return Optional.ofNullable(coverageExtent); + } + + /** + * Sets the restriction on the time or range axis values of the coverage. + * The given instance is stored by reference, it is not cloned. + * If this method is never invoked, then the default value is absence. + * + * @param value new restriction on the coverage extent, or {@code null} if none. + */ + public void setCoverageExtent(final CoverageExtent value) { + coverageExtent = value; + } + + /** + * Returns all properties contained in this class. + * This is used for {@link #equals(Object)} and {@link #hashCode()} implementations. + */ + @Override + final Object[] properties() { + return new Object[] {coverageName, coverageExtent}; + } + + /** + * Returns a deep clone of this object. + * + * @return deep clone of all style elements. + */ + @Override + public CoverageConstraint clone() { + final var clone = (CoverageConstraint) super.clone(); + if (clone.coverageExtent != null) { + clone.coverageExtent = clone.coverageExtent.clone(); + } + return clone; + } +} diff --git a/endorsed/src/org.apache.sis.portrayal/main/org/apache/sis/style/sld1/CoverageExtent.java b/endorsed/src/org.apache.sis.portrayal/main/org/apache/sis/style/sld1/CoverageExtent.java new file mode 100644 index 0000000000..3b6df792c7 --- /dev/null +++ b/endorsed/src/org.apache.sis.portrayal/main/org/apache/sis/style/sld1/CoverageExtent.java @@ -0,0 +1,122 @@ +/* + * 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.style.sld1; + +import java.util.List; +import java.util.ArrayList; +import java.util.Optional; + + +/** + * Restriction on the values of a coverage shown by a {@link CoverageConstraint}. + * The restriction is expressed either by values along some range axes, or by a time period. + * The XML schema allows only one of those two alternatives in the same element. + * This class does not enforce that rule; it is caller's responsibility to set only one of them. + * + * @author Johann Sorel (Geomatys) + */ +public class CoverageExtent extends SLDElement { + /** + * Values along some range axes, as a live list. + * + * @see #rangeAxes() + */ + private List<RangeAxis> rangeAxes; + + /** + * Time period of the coverage values to show, or {@code null} if none. + * + * @see #getTimePeriod() + * @see #setTimePeriod(String) + */ + protected String timePeriod; + + /** + * Creates an initially empty coverage extent. + */ + public CoverageExtent() { + rangeAxes = new ArrayList<>(); + } + + /** + * Creates a shallow copy of the given object. + * For a deep copy, see {@link #clone()} instead. + * + * @param source the object to copy. + */ + public CoverageExtent(final CoverageExtent source) { + rangeAxes = new ArrayList<>(source.rangeAxes); + timePeriod = source.timePeriod; + } + + /** + * Returns the values along some range axes. + * Should be empty if a {@linkplain #getTimePeriod() time period} is specified. + * + * <p>The returned collection is <em>live</em>: + * changes in that collection are reflected into this object, and conversely.</p> + * + * @return values along some range axes, as a live collection. + */ + @SuppressWarnings("ReturnOfCollectionOrArrayField") + public List<RangeAxis> rangeAxes() { + return rangeAxes; + } + + /** + * Returns the time period of the coverage values to show. + * This is a string such as {@code "2005-05-17T00:00:00Z/2005-05-23T00:00:00Z"}. + * Should be absent if some {@linkplain #rangeAxes() range axes} are specified. + * + * @return time period of the coverage values to show. + */ + public Optional<String> getTimePeriod() { + return Optional.ofNullable(timePeriod); + } + + /** + * Sets the time period of the coverage values to show. + * If this method is never invoked, then the default value is absence. + * + * @param value new time period, or {@code null} if none. + */ + public void setTimePeriod(final String value) { + timePeriod = value; + } + + /** + * Returns all properties contained in this class. + * This is used for {@link #equals(Object)} and {@link #hashCode()} implementations. + */ + @Override + final Object[] properties() { + return new Object[] {rangeAxes, timePeriod}; + } + + /** + * Returns a deep clone of this object. + * + * @return deep clone of all style elements. + */ + @Override + public CoverageExtent clone() { + final var clone = (CoverageExtent) super.clone(); + clone.rangeAxes = new ArrayList<>(rangeAxes); + clone.rangeAxes.replaceAll(RangeAxis::clone); + return clone; + } +} diff --git a/endorsed/src/org.apache.sis.portrayal/main/org/apache/sis/style/sld1/Extent.java b/endorsed/src/org.apache.sis.portrayal/main/org/apache/sis/style/sld1/Extent.java new file mode 100644 index 0000000000..620dea1f51 --- /dev/null +++ b/endorsed/src/org.apache.sis.portrayal/main/org/apache/sis/style/sld1/Extent.java @@ -0,0 +1,121 @@ +/* + * 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.style.sld1; + +import java.util.Optional; + + +/** + * A range or enumerated list of values for a feature attribute, used to restrict + * the features shown by a {@link FeatureTypeConstraint} to some specific range or set of values. + * + * @author Johann Sorel (Geomatys) + */ +public class Extent extends SLDElement { + /** + * Name of the feature attribute constrained by this extent, or {@code null} if none. + * + * @see #getName() + * @see #setName(String) + */ + protected String name; + + /** + * Range or enumerated list of values, or {@code null} if none. + * + * @see #getValue() + * @see #setValue(String) + */ + protected String value; + + /** + * Creates an initially empty extent. + * Callers should set the {@linkplain #setName(String) name} and + * the {@linkplain #setValue(String) value} after construction, + * since those properties are mandatory. + */ + public Extent() { + } + + /** + * Creates a shallow copy of the given object. + * For a deep copy, see {@link #clone()} instead. + * + * @param source the object to copy. + */ + public Extent(final Extent source) { + name = source.name; + value = source.value; + } + + /** + * Returns the name of the feature attribute constrained by this extent. + * + * @return name of the feature attribute constrained by this extent. + */ + public Optional<String> getName() { + return Optional.ofNullable(name); + } + + /** + * Sets the name of the feature attribute constrained by this extent. + * If this method is never invoked, then the default value is absence. + * + * @param value new name of the feature attribute, or {@code null} if none. + */ + public void setName(final String value) { + name = value; + } + + /** + * Returns the range or enumerated list of values. + * + * @return range or enumerated list of values. + */ + public Optional<String> getValue() { + return Optional.ofNullable(value); + } + + /** + * Sets the range or enumerated list of values. + * If this method is never invoked, then the default value is absence. + * + * @param value new range or enumerated list of values, or {@code null} if none. + */ + public void setValue(final String value) { + this.value = value; + } + + /** + * Returns all properties contained in this class. + * This is used for {@link #equals(Object)} and {@link #hashCode()} implementations. + */ + @Override + final Object[] properties() { + return new Object[] {name, value}; + } + + /** + * Returns a clone of this object. + * + * @return a clone of this element. + */ + @Override + public Extent clone() { + return (Extent) super.clone(); + } +} diff --git a/endorsed/src/org.apache.sis.portrayal/main/org/apache/sis/style/sld1/FeatureTypeConstraint.java b/endorsed/src/org.apache.sis.portrayal/main/org/apache/sis/style/sld1/FeatureTypeConstraint.java new file mode 100644 index 0000000000..4960dfeb6c --- /dev/null +++ b/endorsed/src/org.apache.sis.portrayal/main/org/apache/sis/style/sld1/FeatureTypeConstraint.java @@ -0,0 +1,152 @@ +/* + * 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.style.sld1; + +import java.util.List; +import java.util.ArrayList; +import java.util.Optional; +import org.opengis.util.GenericName; + +// Specific to the geoapi-3.1 and geoapi-4.0 branches: +import org.opengis.feature.Feature; +import org.opengis.filter.Filter; + + +/** + * Restricts the layer's feature instances to a specific feature type, + * optionally further restricted by a filter and by value extents on some attributes. + * + * @author Johann Sorel (Geomatys) + */ +public class FeatureTypeConstraint extends SLDElement { + /** + * Name of the feature type to which this constraint applies, or {@code null} if none. + * + * @see #getFeatureTypeName() + * @see #setFeatureTypeName(GenericName) + */ + protected GenericName featureTypeName; + + /** + * Filter restricting the feature instances shown, or {@code null} if none. + * + * @see #getFilter() + * @see #setFilter(Filter) + */ + protected Filter<? super Feature> filter; + + /** + * Value extents on some feature attributes, as a live list. + * + * @see #extents() + */ + private List<Extent> extents; + + /** + * Creates an initially empty feature type constraint. + */ + public FeatureTypeConstraint() { + extents = new ArrayList<>(); + } + + /** + * Creates a shallow copy of the given object. + * For a deep copy, see {@link #clone()} instead. + * + * @param source the object to copy. + */ + public FeatureTypeConstraint(final FeatureTypeConstraint source) { + featureTypeName = source.featureTypeName; + filter = source.filter; + extents = new ArrayList<>(source.extents); + } + + /** + * Returns the name of the feature type to which this constraint applies. + * + * @return name of the feature type to which this constraint applies. + */ + public Optional<GenericName> getFeatureTypeName() { + return Optional.ofNullable(featureTypeName); + } + + /** + * Sets the name of the feature type to which this constraint applies. + * If this method is never invoked, then the default value is absence. + * + * @param value new name of the feature type, or {@code null} if none. + */ + public void setFeatureTypeName(final GenericName value) { + featureTypeName = value; + } + + /** + * Returns the filter restricting the feature instances shown. + * If absent, all instances of the feature type are shown. + * + * @return filter restricting the feature instances shown. + */ + public Optional<Filter<? super Feature>> getFilter() { + return Optional.ofNullable(filter); + } + + /** + * Sets the filter restricting the feature instances shown. + * If this method is never invoked, then the default value is absence. + * + * @param value new filter restricting the feature instances, or {@code null} if none. + */ + public void setFilter(final Filter<? super Feature> value) { + filter = value; + } + + /** + * Returns the value extents on some feature attributes. + * + * <p>The returned collection is <em>live</em>: + * changes in that collection are reflected into this object, and conversely.</p> + * + * @return value extents on some feature attributes, as a live collection. + */ + @SuppressWarnings("ReturnOfCollectionOrArrayField") + public List<Extent> extents() { + return extents; + } + + /** + * Returns all properties contained in this class. + * This is used for {@link #equals(Object)} and {@link #hashCode()} implementations. + */ + @Override + final Object[] properties() { + return new Object[] {featureTypeName, filter, extents}; + } + + /** + * Returns a deep clone of this object. All style elements are cloned, + * but the filter is not on the assumption that it is immutable. + * + * @return deep clone of all style elements. + */ + @Override + public FeatureTypeConstraint clone() { + final var clone = (FeatureTypeConstraint) super.clone(); + clone.extents = new ArrayList<>(extents); + clone.extents.replaceAll(Extent::clone); + return clone; + } +} diff --git a/endorsed/src/org.apache.sis.portrayal/main/org/apache/sis/style/sld1/InlineFeature.java b/endorsed/src/org.apache.sis.portrayal/main/org/apache/sis/style/sld1/InlineFeature.java new file mode 100644 index 0000000000..1f993ace74 --- /dev/null +++ b/endorsed/src/org.apache.sis.portrayal/main/org/apache/sis/style/sld1/InlineFeature.java @@ -0,0 +1,93 @@ +/* + * 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.style.sld1; + +import java.util.List; +import java.util.ArrayList; + +// Specific to the geoapi-3.1 and geoapi-4.0 branches: +import org.opengis.feature.Feature; + + +/** + * Features embedded in the styled layer descriptor, to be styled by a {@link UserLayer}. + * In a XML document, the features are encoded as one or many GML feature collections. + * This class merges the members of all those collections into a single list. + * + * @author Johann Sorel (Geomatys) + */ +public class InlineFeature extends LayerSource { + /** + * The embedded features, as a live list. + * + * @see #features() + */ + private List<Feature> features; + + /** + * Creates an initially empty list of inline features. + */ + public InlineFeature() { + features = new ArrayList<>(); + } + + /** + * Creates a shallow copy of the given object. + * For a deep copy, see {@link #clone()} instead. + * + * @param source the object to copy. + */ + public InlineFeature(final InlineFeature source) { + features = new ArrayList<>(source.features); + } + + /** + * Returns the features embedded in the styled layer descriptor. + * The features may be instances of different feature types. + * + * <p>The returned collection is <em>live</em>: + * changes in that collection are reflected into this object, and conversely.</p> + * + * @return the embedded features, as a live collection. + */ + @SuppressWarnings("ReturnOfCollectionOrArrayField") + public List<Feature> features() { + return features; + } + + /** + * Returns all properties contained in this class. + * This is used for {@link #equals(Object)} and {@link #hashCode()} implementations. + */ + @Override + final Object[] properties() { + return new Object[] {features}; + } + + /** + * Returns a clone of this object. + * The list is copied, but the features themselves are not cloned. + * + * @return a clone of this element. + */ + @Override + public InlineFeature clone() { + final var clone = (InlineFeature) super.clone(); + clone.features = new ArrayList<>(features); + return clone; + } +} diff --git a/endorsed/src/org.apache.sis.portrayal/main/org/apache/sis/style/sld1/Layer.java b/endorsed/src/org.apache.sis.portrayal/main/org/apache/sis/style/sld1/Layer.java new file mode 100644 index 0000000000..e21e0874aa --- /dev/null +++ b/endorsed/src/org.apache.sis.portrayal/main/org/apache/sis/style/sld1/Layer.java @@ -0,0 +1,123 @@ +/* + * 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.style.sld1; + +import java.util.Optional; +import org.apache.sis.style.se1.Description; + + +/** + * A layer of a map described by a {@link StyledLayerDescriptor}. + * A layer is either a {@link NamedLayer}, which references styles known to the map server, + * or a {@link UserLayer}, for which the styling is provided inline. + * + * @author Johann Sorel (Geomatys) + */ +public abstract class Layer extends SLDElement { + /** + * Name for this layer, or {@code null} if none. + * + * @see #getName() + * @see #setName(String) + */ + protected String name; + + /** + * Information for user interfaces, or {@code null} if none. + * + * @see #getDescription() + * @see #setDescription(Description) + */ + protected Description<?> description; + + /** + * Creates an initially empty layer. + */ + Layer() { + } + + /** + * Creates a shallow copy of the given object. + * For a deep copy, see {@link #clone()} instead. + * + * @param source the object to copy. + */ + Layer(final Layer source) { + name = source.name; + description = source.description; + } + + /** + * Returns the name for this layer. + * For a {@link NamedLayer}, this is the name of a layer known to the map server. + * For a {@link UserLayer}, this can be any string that identifies the layer. + * It is not meant to be human-friendly. For a human-friendly label, + * see the {@linkplain Description#getTitle() title} instead. + * + * @return a name for this layer. + */ + public Optional<String> getName() { + return Optional.ofNullable(name); + } + + /** + * Sets a name for this layer. + * If this method is never invoked, then the default value is absence. + * + * @param value new name for this layer, or {@code null} if none. + */ + public void setName(final String value) { + name = value; + } + + /** + * Returns the description of this layer. + * The returned object is <em>live</em>: + * changes in the returned instance will be reflected in this layer, and conversely. + * + * @return information for user interfaces. + */ + public Optional<Description<?>> getDescription() { + return Optional.ofNullable(description); + } + + /** + * Sets a description of this layer. + * The given instance is stored by reference, it is not cloned. + * If this method is never invoked, then the default value is absence. + * + * @param value new information for user interfaces, or {@code null} if none. + */ + public void setDescription(final Description<?> value) { + description = value; + } + + /** + * Returns a deep clone of this object. All style elements are cloned, + * but filters, features and online resources are not. + * + * @return deep clone of all style elements. + */ + @Override + public Layer clone() { + final var clone = (Layer) super.clone(); + if (clone.description != null) { + clone.description = clone.description.clone(); + } + return clone; + } +} diff --git a/endorsed/src/org.apache.sis.portrayal/main/org/apache/sis/style/sld1/LayerConstraints.java b/endorsed/src/org.apache.sis.portrayal/main/org/apache/sis/style/sld1/LayerConstraints.java new file mode 100644 index 0000000000..2b00f8ffa8 --- /dev/null +++ b/endorsed/src/org.apache.sis.portrayal/main/org/apache/sis/style/sld1/LayerConstraints.java @@ -0,0 +1,59 @@ +/* + * 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.style.sld1; + +import java.util.List; + + +/** + * A list of constraints restricting the data shown for a layer. + * The constraints are either on feature types ({@link LayerFeatureConstraints}) + * or on coverages ({@link LayerCoverageConstraints}). + * + * @author Johann Sorel (Geomatys) + * + * @param <C> the type of constraints in the list. + */ +public abstract class LayerConstraints<C> extends SLDElement { + /** + * Creates a new list of constraints. + */ + LayerConstraints() { + } + + /** + * Returns the constraints restricting the data shown for a layer. + * A layer constraints element should contain at least one constraint. + * + * <p>The returned collection is <em>live</em>: + * changes in that collection are reflected into this object, and conversely.</p> + * + * @return the constraints, as a live collection. + */ + public abstract List<C> constraints(); + + /** + * Returns a deep clone of this object. + * + * @return deep clone of all constraints. + */ + @Override + @SuppressWarnings("unchecked") + public LayerConstraints<C> clone() { + return (LayerConstraints<C>) super.clone(); + } +} diff --git a/endorsed/src/org.apache.sis.portrayal/main/org/apache/sis/style/sld1/LayerCoverageConstraints.java b/endorsed/src/org.apache.sis.portrayal/main/org/apache/sis/style/sld1/LayerCoverageConstraints.java new file mode 100644 index 0000000000..42152caa5b --- /dev/null +++ b/endorsed/src/org.apache.sis.portrayal/main/org/apache/sis/style/sld1/LayerCoverageConstraints.java @@ -0,0 +1,92 @@ +/* + * 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.style.sld1; + +import java.util.List; +import java.util.ArrayList; + + +/** + * A list of constraints restricting the coverages and coverage extents + * that are shown for a {@link UserLayer}. + * + * @author Johann Sorel (Geomatys) + */ +public class LayerCoverageConstraints extends LayerConstraints<CoverageConstraint> { + /** + * The coverage constraints, as a live list. + * + * @see #constraints() + */ + private List<CoverageConstraint> constraints; + + /** + * Creates an initially empty list of coverage constraints. + * Callers should add at least one {@linkplain #constraints() constraint} after construction. + */ + public LayerCoverageConstraints() { + constraints = new ArrayList<>(); + } + + /** + * Creates a shallow copy of the given object. + * For a deep copy, see {@link #clone()} instead. + * + * @param source the object to copy. + */ + public LayerCoverageConstraints(final LayerCoverageConstraints source) { + constraints = new ArrayList<>(source.constraints); + } + + /** + * Returns the coverage constraints. + * Each constraint restricts the layer to a coverage, + * optionally with a restriction on the coverage extent. + * + * <p>The returned collection is <em>live</em>: + * changes in that collection are reflected into this object, and conversely.</p> + * + * @return the coverage constraints, as a live collection. + */ + @Override + @SuppressWarnings("ReturnOfCollectionOrArrayField") + public List<CoverageConstraint> constraints() { + return constraints; + } + + /** + * Returns all properties contained in this class. + * This is used for {@link #equals(Object)} and {@link #hashCode()} implementations. + */ + @Override + final Object[] properties() { + return new Object[] {constraints}; + } + + /** + * Returns a deep clone of this object. + * + * @return deep clone of all constraints. + */ + @Override + public LayerCoverageConstraints clone() { + final var clone = (LayerCoverageConstraints) super.clone(); + clone.constraints = new ArrayList<>(constraints); + clone.constraints.replaceAll(CoverageConstraint::clone); + return clone; + } +} diff --git a/endorsed/src/org.apache.sis.portrayal/main/org/apache/sis/style/sld1/LayerFeatureConstraints.java b/endorsed/src/org.apache.sis.portrayal/main/org/apache/sis/style/sld1/LayerFeatureConstraints.java new file mode 100644 index 0000000000..2939744a96 --- /dev/null +++ b/endorsed/src/org.apache.sis.portrayal/main/org/apache/sis/style/sld1/LayerFeatureConstraints.java @@ -0,0 +1,92 @@ +/* + * 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.style.sld1; + +import java.util.List; +import java.util.ArrayList; + + +/** + * A list of constraints restricting the feature types and feature instances + * that are shown for a {@link NamedLayer} or {@link UserLayer}. + * + * @author Johann Sorel (Geomatys) + */ +public class LayerFeatureConstraints extends LayerConstraints<FeatureTypeConstraint> { + /** + * The feature type constraints, as a live list. + * + * @see #constraints() + */ + private List<FeatureTypeConstraint> constraints; + + /** + * Creates an initially empty list of feature type constraints. + * Callers should add at least one {@linkplain #constraints() constraint} after construction. + */ + public LayerFeatureConstraints() { + constraints = new ArrayList<>(); + } + + /** + * Creates a shallow copy of the given object. + * For a deep copy, see {@link #clone()} instead. + * + * @param source the object to copy. + */ + public LayerFeatureConstraints(final LayerFeatureConstraints source) { + constraints = new ArrayList<>(source.constraints); + } + + /** + * Returns the feature type constraints. + * Each constraint restricts the layer to a feature type, + * optionally with a filter on the feature instances. + * + * <p>The returned collection is <em>live</em>: + * changes in that collection are reflected into this object, and conversely.</p> + * + * @return the feature type constraints, as a live collection. + */ + @Override + @SuppressWarnings("ReturnOfCollectionOrArrayField") + public List<FeatureTypeConstraint> constraints() { + return constraints; + } + + /** + * Returns all properties contained in this class. + * This is used for {@link #equals(Object)} and {@link #hashCode()} implementations. + */ + @Override + final Object[] properties() { + return new Object[] {constraints}; + } + + /** + * Returns a deep clone of this object. + * + * @return deep clone of all constraints. + */ + @Override + public LayerFeatureConstraints clone() { + final var clone = (LayerFeatureConstraints) super.clone(); + clone.constraints = new ArrayList<>(constraints); + clone.constraints.replaceAll(FeatureTypeConstraint::clone); + return clone; + } +} diff --git a/endorsed/src/org.apache.sis.portrayal/main/org/apache/sis/style/sld1/LayerSource.java b/endorsed/src/org.apache.sis.portrayal/main/org/apache/sis/style/sld1/LayerSource.java new file mode 100644 index 0000000000..e2a3d4a520 --- /dev/null +++ b/endorsed/src/org.apache.sis.portrayal/main/org/apache/sis/style/sld1/LayerSource.java @@ -0,0 +1,43 @@ +/* + * 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.style.sld1; + + +/** + * Source of the data to be styled by a {@link UserLayer}. + * The data are either provided by a remote service ({@link RemoteOWS}) + * or embedded in the styled layer descriptor ({@link InlineFeature}). + * + * @author Johann Sorel (Geomatys) + */ +public abstract class LayerSource extends SLDElement { + /** + * Creates a new layer source. + */ + LayerSource() { + } + + /** + * Returns a deep clone of this object. + * + * @return a clone of this element. + */ + @Override + public LayerSource clone() { + return (LayerSource) super.clone(); + } +} diff --git a/endorsed/src/org.apache.sis.portrayal/main/org/apache/sis/style/sld1/NamedLayer.java b/endorsed/src/org.apache.sis.portrayal/main/org/apache/sis/style/sld1/NamedLayer.java new file mode 100644 index 0000000000..bbb0f9147c --- /dev/null +++ b/endorsed/src/org.apache.sis.portrayal/main/org/apache/sis/style/sld1/NamedLayer.java @@ -0,0 +1,155 @@ +/* + * 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.style.sld1; + +import java.util.List; +import java.util.ArrayList; +import java.util.Optional; +import org.apache.sis.style.Style; +import org.apache.sis.style.se1.Symbology; + + +/** + * A layer of a map, identified by referencing a layer known to a map server, + * together with optional feature type constraints and the styles to apply. + * The styles can be references to styles known to the map server ({@link NamedStyle}) + * or styles defined inline ({@link Symbology}). + * + * @author Johann Sorel (Geomatys) + */ +public class NamedLayer extends Layer { + /** + * Constraints on the feature types available for this layer, or {@code null} if none. + * + * @see #getConstraints() + * @see #setConstraints(LayerFeatureConstraints) + */ + protected LayerFeatureConstraints constraints; + + /** + * The named or user styles applicable to this layer, as a live list. + * Elements are either {@link NamedStyle} or {@link Symbology} instances. + * + * @see #styles() + */ + private List<Style> styles; + + /** + * Creates an initially empty named layer. + * Callers should set the {@linkplain #setName(String) name} after construction, + * since this property is mandatory for named layers. + */ + public NamedLayer() { + styles = new ArrayList<>(); + } + + /** + * Creates a shallow copy of the given object. + * For a deep copy, see {@link #clone()} instead. + * + * @param source the object to copy. + */ + public NamedLayer(final NamedLayer source) { + super(source); + constraints = source.constraints; + styles = new ArrayList<>(source.styles); + } + + /** + * Returns the constraints on the feature types available for this layer. + * The returned object is <em>live</em>: + * changes in the returned instance will be reflected in this layer, and conversely. + * + * @return constraints on the feature types available for this layer. + */ + public Optional<LayerFeatureConstraints> getConstraints() { + return Optional.ofNullable(constraints); + } + + /** + * Sets the constraints on the feature types available for this layer. + * The given instance is stored by reference, it is not cloned. + * If this method is never invoked, then the default value is absence. + * + * @param value new constraints on the feature types, or {@code null} if none. + */ + public void setConstraints(final LayerFeatureConstraints value) { + constraints = value; + } + + /** + * Returns the styles applicable to this layer. + * Elements should be {@link NamedStyle} or {@link Symbology} instances. + * Other implementations of {@link Style} are not supported by the XML encoding. + * + * <p>The returned collection is <em>live</em>: + * changes in that collection are reflected into this object, and conversely.</p> + * + * @return styles applicable to this layer, as a live collection. + */ + @SuppressWarnings("ReturnOfCollectionOrArrayField") + public List<Style> styles() { + return styles; + } + + /** + * Returns all properties contained in this class. + * This is used for {@link #equals(Object)} and {@link #hashCode()} implementations. + */ + @Override + final Object[] properties() { + return new Object[] {name, description, constraints, styles}; + } + + /** + * Returns a deep clone of this object. All style elements are cloned, + * but filters, features and online resources are not. + * + * @return deep clone of all style elements. + */ + @Override + public NamedLayer clone() { + final var clone = (NamedLayer) super.clone(); + clone.selfClone(); + return clone; + } + + /** + * Clones the mutable style fields of this element. + */ + private void selfClone() { + if (constraints != null) constraints = constraints.clone(); + styles = new ArrayList<>(styles); + styles.replaceAll(NamedLayer::cloneStyle); + } + + /** + * Returns a clone of the given style if its class is known, or the style itself otherwise. + * + * @param style the style to clone. + * @return a clone of the given style, or {@code style} if it cannot be cloned. + */ + private static Style cloneStyle(final Style style) { + if (style instanceof NamedStyle) { + return ((NamedStyle) style).clone(); + } + if (style instanceof Symbology) { + return ((Symbology) style).clone(); + } + return style; + } +} diff --git a/endorsed/src/org.apache.sis.portrayal/main/org/apache/sis/style/sld1/NamedStyle.java b/endorsed/src/org.apache.sis.portrayal/main/org/apache/sis/style/sld1/NamedStyle.java new file mode 100644 index 0000000000..de1d6c0e36 --- /dev/null +++ b/endorsed/src/org.apache.sis.portrayal/main/org/apache/sis/style/sld1/NamedStyle.java @@ -0,0 +1,130 @@ +/* + * 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.style.sld1; + +import java.util.Optional; +import org.apache.sis.style.Style; +import org.apache.sis.style.se1.Description; + + +/** + * Reference, by name, to a style known to the map server. + * Named styles can be used only in {@link NamedLayer}. + * + * @author Johann Sorel (Geomatys) + */ +public class NamedStyle extends SLDElement implements Style { + /** + * Name of the referenced style, or {@code null} if none. + * + * @see #getName() + * @see #setName(String) + */ + protected String name; + + /** + * Information for user interfaces, or {@code null} if none. + * + * @see #getDescription() + * @see #setDescription(Description) + */ + protected Description<?> description; + + /** + * Creates an initially empty named style. + * Callers should set the {@linkplain #setName(String) name} after construction, + * since this property is mandatory. + */ + public NamedStyle() { + } + + /** + * Creates a shallow copy of the given object. + * For a deep copy, see {@link #clone()} instead. + * + * @param source the object to copy. + */ + public NamedStyle(final NamedStyle source) { + name = source.name; + description = source.description; + } + + /** + * Returns the name of the referenced style. + * This is the name of a style known to the map server. + * + * @return name of the referenced style. + */ + public Optional<String> getName() { + return Optional.ofNullable(name); + } + + /** + * Sets the name of the referenced style. + * If this method is never invoked, then the default value is absence. + * + * @param value new name of the referenced style, or {@code null} if none. + */ + public void setName(final String value) { + name = value; + } + + /** + * Returns the description of this style. + * The returned object is <em>live</em>: + * changes in the returned instance will be reflected in this style, and conversely. + * + * @return information for user interfaces. + */ + public Optional<Description<?>> getDescription() { + return Optional.ofNullable(description); + } + + /** + * Sets a description of this style. + * The given instance is stored by reference, it is not cloned. + * If this method is never invoked, then the default value is absence. + * + * @param value new information for user interfaces, or {@code null} if none. + */ + public void setDescription(final Description<?> value) { + description = value; + } + + /** + * Returns all properties contained in this class. + * This is used for {@link #equals(Object)} and {@link #hashCode()} implementations. + */ + @Override + final Object[] properties() { + return new Object[] {name, description}; + } + + /** + * Returns a deep clone of this object. + * + * @return deep clone of all style elements. + */ + @Override + public NamedStyle clone() { + final var clone = (NamedStyle) super.clone(); + if (clone.description != null) { + clone.description = clone.description.clone(); + } + return clone; + } +} diff --git a/endorsed/src/org.apache.sis.portrayal/main/org/apache/sis/style/sld1/RangeAxis.java b/endorsed/src/org.apache.sis.portrayal/main/org/apache/sis/style/sld1/RangeAxis.java new file mode 100644 index 0000000000..58f6babf16 --- /dev/null +++ b/endorsed/src/org.apache.sis.portrayal/main/org/apache/sis/style/sld1/RangeAxis.java @@ -0,0 +1,121 @@ +/* + * 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.style.sld1; + +import java.util.Optional; + + +/** + * A value along a coverage range axis, used to restrict the coverage values shown + * by a {@link CoverageExtent}. Examples of range axes are bands or time. + * + * @author Johann Sorel (Geomatys) + */ +public class RangeAxis extends SLDElement { + /** + * Name of the range axis, or {@code null} if none. + * + * @see #getName() + * @see #setName(String) + */ + protected String name; + + /** + * Value along the range axis, or {@code null} if none. + * + * @see #getValue() + * @see #setValue(String) + */ + protected String value; + + /** + * Creates an initially empty range axis. + * Callers should set the {@linkplain #setName(String) name} and + * the {@linkplain #setValue(String) value} after construction, + * since those properties are mandatory. + */ + public RangeAxis() { + } + + /** + * Creates a shallow copy of the given object. + * For a deep copy, see {@link #clone()} instead. + * + * @param source the object to copy. + */ + public RangeAxis(final RangeAxis source) { + name = source.name; + value = source.value; + } + + /** + * Returns the name of the range axis. + * + * @return name of the range axis. + */ + public Optional<String> getName() { + return Optional.ofNullable(name); + } + + /** + * Sets the name of the range axis. + * If this method is never invoked, then the default value is absence. + * + * @param value new name of the range axis, or {@code null} if none. + */ + public void setName(final String value) { + name = value; + } + + /** + * Returns the value along the range axis. + * + * @return value along the range axis. + */ + public Optional<String> getValue() { + return Optional.ofNullable(value); + } + + /** + * Sets the value along the range axis. + * If this method is never invoked, then the default value is absence. + * + * @param value new value along the range axis, or {@code null} if none. + */ + public void setValue(final String value) { + this.value = value; + } + + /** + * Returns all properties contained in this class. + * This is used for {@link #equals(Object)} and {@link #hashCode()} implementations. + */ + @Override + final Object[] properties() { + return new Object[] {name, value}; + } + + /** + * Returns a clone of this object. + * + * @return a clone of this element. + */ + @Override + public RangeAxis clone() { + return (RangeAxis) super.clone(); + } +} diff --git a/endorsed/src/org.apache.sis.portrayal/main/org/apache/sis/style/sld1/RemoteOWS.java b/endorsed/src/org.apache.sis.portrayal/main/org/apache/sis/style/sld1/RemoteOWS.java new file mode 100644 index 0000000000..7a9e63a09b --- /dev/null +++ b/endorsed/src/org.apache.sis.portrayal/main/org/apache/sis/style/sld1/RemoteOWS.java @@ -0,0 +1,126 @@ +/* + * 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.style.sld1; + +import java.util.Optional; +import org.opengis.metadata.citation.OnlineResource; + + +/** + * Reference to a remote Web Feature Service or Web Coverage Service providing + * the data to be styled by a {@link UserLayer}. + * + * @author Johann Sorel (Geomatys) + */ +public class RemoteOWS extends LayerSource { + /** + * Type of the remote service, such as {@code "WFS"} or {@code "WCS"}, or {@code null} if none. + * + * @see #getService() + * @see #setService(String) + */ + protected String service; + + /** + * Location of the remote service, or {@code null} if none. + * + * @see #getOnlineResource() + * @see #setOnlineResource(OnlineResource) + */ + protected OnlineResource onlineResource; + + /** + * Creates an initially empty remote service reference. + * Callers should set the {@linkplain #setService(String) service type} + * and the {@linkplain #setOnlineResource(OnlineResource) online resource} + * after construction, since those properties are mandatory. + */ + public RemoteOWS() { + } + + /** + * Creates a shallow copy of the given object. + * For a deep copy, see {@link #clone()} instead. + * + * @param source the object to copy. + */ + public RemoteOWS(final RemoteOWS source) { + service = source.service; + onlineResource = source.onlineResource; + } + + /** + * Returns the type of the remote service. + * The values allowed by the Styled Layer Descriptor standard are + * {@code "WFS"} (Web Feature Service) and {@code "WCS"} (Web Coverage Service). + * + * @return type of the remote service. + */ + public Optional<String> getService() { + return Optional.ofNullable(service); + } + + /** + * Sets the type of the remote service. + * The values allowed by the Styled Layer Descriptor standard are {@code "WFS"} and {@code "WCS"}. + * If this method is never invoked, then the default value is absence. + * + * @param value new type of the remote service, or {@code null} if none. + */ + public void setService(final String value) { + service = value; + } + + /** + * Returns the location of the remote service. + * + * @return location of the remote service. + */ + public Optional<OnlineResource> getOnlineResource() { + return Optional.ofNullable(onlineResource); + } + + /** + * Sets the location of the remote service. + * If this method is never invoked, then the default value is absence. + * + * @param value new location of the remote service, or {@code null} if none. + */ + public void setOnlineResource(final OnlineResource value) { + onlineResource = value; + } + + /** + * Returns all properties contained in this class. + * This is used for {@link #equals(Object)} and {@link #hashCode()} implementations. + */ + @Override + final Object[] properties() { + return new Object[] {service, onlineResource}; + } + + /** + * Returns a clone of this object. + * The online resource is not cloned. + * + * @return a clone of this element. + */ + @Override + public RemoteOWS clone() { + return (RemoteOWS) super.clone(); + } +} diff --git a/endorsed/src/org.apache.sis.portrayal/main/org/apache/sis/style/sld1/SLDElement.java b/endorsed/src/org.apache.sis.portrayal/main/org/apache/sis/style/sld1/SLDElement.java new file mode 100644 index 0000000000..ae3c5dfb48 --- /dev/null +++ b/endorsed/src/org.apache.sis.portrayal/main/org/apache/sis/style/sld1/SLDElement.java @@ -0,0 +1,85 @@ +/* + * 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.style.sld1; + +import java.util.Arrays; + + +/** + * Base class of all Styled Layer Descriptor elements. + * This base class cannot be extended directly. + * Instead, one of the subclasses can be extended. + * + * @author Johann Sorel (Geomatys) + */ +public abstract class SLDElement implements Cloneable { + /** + * Creates a new element. + * Intentionally restricted to this package because {@link #properties()} is package-private. + */ + SLDElement() { + } + + /** + * Returns all properties contained in the subclasses. + * This is used for {@link #equals(Object)} and {@link #hashCode()} implementations. + * + * @return all properties. + */ + abstract Object[] properties(); + + /** + * Returns a hash code value for this object. + * + * @return a hash code value for this object. + */ + @Override + public int hashCode() { + return getClass().hashCode() + Arrays.hashCode(properties()); + } + + /** + * Compares this element with the given object for equality. + * + * @param obj the other object to compare with this. + * @return whether the other object is equal to this. + */ + @Override + public boolean equals(final Object obj) { + if (obj == this) { + return true; + } + return (obj != null) && (obj.getClass() == getClass()) && + Arrays.equals(properties(), ((SLDElement) obj).properties()); + } + + /** + * Returns a deep clone of this object. All style elements are cloned, + * but filters, features and online resources are not on the assumption + * that they are immutable or external. + * + * @return a clone of this element. + */ + @Override + public SLDElement clone() { + try { + return (SLDElement) super.clone(); + } catch (CloneNotSupportedException e) { + throw new AssertionError(e); // Should never happen since we are cloneable. + } + } +} diff --git a/endorsed/src/org.apache.sis.portrayal/main/org/apache/sis/style/sld1/StyledLayerDescriptor.java b/endorsed/src/org.apache.sis.portrayal/main/org/apache/sis/style/sld1/StyledLayerDescriptor.java new file mode 100644 index 0000000000..45444afcf1 --- /dev/null +++ b/endorsed/src/org.apache.sis.portrayal/main/org/apache/sis/style/sld1/StyledLayerDescriptor.java @@ -0,0 +1,221 @@ +/* + * 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.style.sld1; + +import java.util.List; +import java.util.ArrayList; +import java.util.Optional; +import org.apache.sis.style.se1.Description; + + +/** + * Root element of a Styled Layer Descriptor document. + * A {@code StyledLayerDescriptor} describes the rendering of one or several layers, + * either by reference to a named style ({@link NamedLayer}) or by providing the styling + * inline ({@link UserLayer}). + * + * @author Johann Sorel (Geomatys) + */ +public class StyledLayerDescriptor extends SLDElement { + /** + * Version number of the Styled Layer Descriptor Implementation Specification standard currently implemented. + * This version number may change in future Apache SIS releases if new standards are published. + * The current value is {@value}. + */ + public static final String VERSION = "1.1.0"; + + /** + * Version number of the Styled Layer Descriptor standard used. + * This value should not be changed, unless this descriptor has been unmarshalled + * from a XML document that specifies a different version number. + * + * @see #getVersion() + */ + protected String version; + + /** + * Name for this styled layer descriptor, or {@code null} if none. + * + * @see #getName() + * @see #setName(String) + */ + protected String name; + + /** + * Information for user interfaces, or {@code null} if none. + * + * @see #getDescription() + * @see #setDescription(Description) + */ + protected Description<?> description; + + /** + * References to external SLD documents to import, as a live list. + * + * @see #libraries() + */ + private List<UseSLDLibrary> libraries; + + /** + * The named or user layers described by this document, as a live list. + * + * @see #layers() + */ + private List<Layer> layers; + + /** + * Creates an initially empty styled layer descriptor. + */ + public StyledLayerDescriptor() { + version = VERSION; + libraries = new ArrayList<>(); + layers = new ArrayList<>(); + } + + /** + * Creates a shallow copy of the given object. + * For a deep copy, see {@link #clone()} instead. + * + * @param source the object to copy. + */ + public StyledLayerDescriptor(final StyledLayerDescriptor source) { + version = source.version; + name = source.name; + description = source.description; + libraries = new ArrayList<>(source.libraries); + layers = new ArrayList<>(source.layers); + } + + /** + * Returns the version number of the Styled Layer Descriptor standard used. + * This is fixed to {@value #VERSION} in current Apache SIS release. + * This value cannot be changed, unless this descriptor has been unmarshalled + * from a XML document that specifies a different version number. + * + * @return version number of the Styled Layer Descriptor standard used. + */ + public String getVersion() { + return version; + } + + /** + * Returns the name for this styled layer descriptor. + * This can be any string that uniquely identifies this descriptor. + * It is not meant to be human-friendly. For a human-friendly label, + * see the {@linkplain Description#getTitle() title} instead. + * + * @return a name for this styled layer descriptor. + */ + public Optional<String> getName() { + return Optional.ofNullable(name); + } + + /** + * Sets a name for this styled layer descriptor. + * If this method is never invoked, then the default value is absence. + * + * @param value new name for this descriptor, or {@code null} if none. + */ + public void setName(final String value) { + name = value; + } + + /** + * Returns the description of this styled layer descriptor. + * The returned object is <em>live</em>: + * changes in the returned instance will be reflected in this descriptor, and conversely. + * + * @return information for user interfaces. + */ + public Optional<Description<?>> getDescription() { + return Optional.ofNullable(description); + } + + /** + * Sets a description of this styled layer descriptor. + * The given instance is stored by reference, it is not cloned. + * If this method is never invoked, then the default value is absence. + * + * @param value new information for user interfaces, or {@code null} if none. + */ + public void setDescription(final Description<?> value) { + description = value; + } + + /** + * Returns the references to external SLD documents to import. + * Libraries are used for resolving named layers and named styles + * which are not known to the map server. + * + * <p>The returned collection is <em>live</em>: + * changes in that collection are reflected into this object, and conversely.</p> + * + * @return references to external SLD documents, as a live collection. + */ + @SuppressWarnings("ReturnOfCollectionOrArrayField") + public List<UseSLDLibrary> libraries() { + return libraries; + } + + /** + * Returns the named or user layers described by this document. + * Order matter: the first item in a list will be the + * first item plotted and hence appears on the bottom. + * + * <p>The returned collection is <em>live</em>: + * changes in that collection are reflected into this object, and conversely.</p> + * + * @return ordered list of layers, as a live collection. + */ + @SuppressWarnings("ReturnOfCollectionOrArrayField") + public List<Layer> layers() { + return layers; + } + + /** + * Returns all properties contained in this class. + * This is used for {@link #equals(Object)} and {@link #hashCode()} implementations. + */ + @Override + final Object[] properties() { + return new Object[] {version, name, description, libraries, layers}; + } + + /** + * Returns a deep clone of this object. All style elements are cloned, + * but filters, features and online resources are not. + * + * @return deep clone of all style elements. + */ + @Override + public StyledLayerDescriptor clone() { + final var clone = (StyledLayerDescriptor) super.clone(); + clone.selfClone(); + return clone; + } + + /** + * Clones the mutable style fields of this element. + */ + private void selfClone() { + if (description != null) description = description.clone(); + libraries = new ArrayList<>(libraries); + libraries.replaceAll(UseSLDLibrary::clone); + layers = new ArrayList<>(layers); + layers.replaceAll(Layer::clone); + } +} diff --git a/endorsed/src/org.apache.sis.portrayal/main/org/apache/sis/style/sld1/UseSLDLibrary.java b/endorsed/src/org.apache.sis.portrayal/main/org/apache/sis/style/sld1/UseSLDLibrary.java new file mode 100644 index 0000000000..d7a91156c2 --- /dev/null +++ b/endorsed/src/org.apache.sis.portrayal/main/org/apache/sis/style/sld1/UseSLDLibrary.java @@ -0,0 +1,93 @@ +/* + * 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.style.sld1; + +import java.util.Optional; +import org.opengis.metadata.citation.OnlineResource; + + +/** + * Reference to an external SLD document to import into a {@link StyledLayerDescriptor}. + * The library is used for resolving named layers and named styles which are not known + * to the map server. This element was introduced in SLD 1.1; it has no equivalent in SLD 1.0. + * + * @author Johann Sorel (Geomatys) + */ +public class UseSLDLibrary extends SLDElement { + /** + * Location of the external SLD document, or {@code null} if none. + * + * @see #getOnlineResource() + * @see #setOnlineResource(OnlineResource) + */ + protected OnlineResource onlineResource; + + /** + * Creates an initially empty library reference. + */ + public UseSLDLibrary() { + } + + /** + * Creates a shallow copy of the given object. + * For a deep copy, see {@link #clone()} instead. + * + * @param source the object to copy. + */ + public UseSLDLibrary(final UseSLDLibrary source) { + onlineResource = source.onlineResource; + } + + /** + * Returns the location of the external SLD document. + * + * @return location of the external SLD document. + */ + public Optional<OnlineResource> getOnlineResource() { + return Optional.ofNullable(onlineResource); + } + + /** + * Sets the location of the external SLD document. + * If this method is never invoked, then the default value is absence. + * + * @param value new location of the external SLD document, or {@code null} if none. + */ + public void setOnlineResource(final OnlineResource value) { + onlineResource = value; + } + + /** + * Returns all properties contained in this class. + * This is used for {@link #equals(Object)} and {@link #hashCode()} implementations. + */ + @Override + final Object[] properties() { + return new Object[] {onlineResource}; + } + + /** + * Returns a clone of this object. + * The online resource is not cloned. + * + * @return a clone of this element. + */ + @Override + public UseSLDLibrary clone() { + return (UseSLDLibrary) super.clone(); + } +} diff --git a/endorsed/src/org.apache.sis.portrayal/main/org/apache/sis/style/sld1/UserLayer.java b/endorsed/src/org.apache.sis.portrayal/main/org/apache/sis/style/sld1/UserLayer.java new file mode 100644 index 0000000000..8543be3669 --- /dev/null +++ b/endorsed/src/org.apache.sis.portrayal/main/org/apache/sis/style/sld1/UserLayer.java @@ -0,0 +1,170 @@ +/* + * 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.style.sld1; + +import java.util.List; +import java.util.ArrayList; +import java.util.Optional; +import org.apache.sis.style.se1.Symbology; + + +/** + * A layer of a map for which the styling is provided inline. + * A user layer may also specify the source of the data to be styled + * (either a remote service or inline features), and constraints on the + * feature types or coverages available for this layer. + * + * @author Johann Sorel (Geomatys) + */ +public class UserLayer extends Layer { + /** + * Source of the data to be styled, or {@code null} if none. + * + * @see #getSource() + * @see #setSource(LayerSource) + */ + protected LayerSource source; + + /** + * Constraints on the feature types or coverages available for this layer, or {@code null} if none. + * + * @see #getConstraints() + * @see #setConstraints(LayerConstraints) + */ + protected LayerConstraints<?> constraints; + + /** + * The user styles applicable to this layer, as a live list. + * + * @see #styles() + */ + private List<Symbology> styles; + + /** + * Creates an initially empty user layer. + * Callers should add at least one {@linkplain #styles() style} after construction. + */ + public UserLayer() { + styles = new ArrayList<>(); + } + + /** + * Creates a shallow copy of the given object. + * For a deep copy, see {@link #clone()} instead. + * + * @param source the object to copy. + */ + public UserLayer(final UserLayer source) { + super(source); + this.source = source.source; + constraints = source.constraints; + styles = new ArrayList<>(source.styles); + } + + /** + * Returns the source of the data to be styled. + * This is either a {@link RemoteOWS} or an {@link InlineFeature}. + * If absent, the data source is determined by the context. + * The returned object is <em>live</em>: + * changes in the returned instance will be reflected in this layer, and conversely. + * + * @return source of the data to be styled. + */ + public Optional<LayerSource> getSource() { + return Optional.ofNullable(source); + } + + /** + * Sets the source of the data to be styled. + * The given instance is stored by reference, it is not cloned. + * If this method is never invoked, then the default value is absence. + * + * @param value new source of the data to be styled, or {@code null} if none. + */ + public void setSource(final LayerSource value) { + source = value; + } + + /** + * Returns the constraints on the feature types or coverages available for this layer. + * This is either a {@link LayerFeatureConstraints} or a {@link LayerCoverageConstraints}. + * The returned object is <em>live</em>: + * changes in the returned instance will be reflected in this layer, and conversely. + * + * @return constraints on the feature types or coverages available for this layer. + */ + public Optional<LayerConstraints<?>> getConstraints() { + return Optional.ofNullable(constraints); + } + + /** + * Sets the constraints on the feature types or coverages available for this layer. + * The given instance is stored by reference, it is not cloned. + * If this method is never invoked, then the default value is absence. + * + * @param value new constraints on the feature types or coverages, or {@code null} if none. + */ + public void setConstraints(final LayerConstraints<?> value) { + constraints = value; + } + + /** + * Returns the user styles applicable to this layer. + * A user layer should contain at least one style. + * + * <p>The returned collection is <em>live</em>: + * changes in that collection are reflected into this object, and conversely.</p> + * + * @return styles applicable to this layer, as a live collection. + */ + @SuppressWarnings("ReturnOfCollectionOrArrayField") + public List<Symbology> styles() { + return styles; + } + + /** + * Returns all properties contained in this class. + * This is used for {@link #equals(Object)} and {@link #hashCode()} implementations. + */ + @Override + final Object[] properties() { + return new Object[] {name, description, source, constraints, styles}; + } + + /** + * Returns a deep clone of this object. All style elements are cloned, + * but filters, features and online resources are not. + * + * @return deep clone of all style elements. + */ + @Override + public UserLayer clone() { + final var clone = (UserLayer) super.clone(); + clone.selfClone(); + return clone; + } + + /** + * Clones the mutable style fields of this element. + */ + private void selfClone() { + if (source != null) source = source.clone(); + if (constraints != null) constraints = constraints.clone(); + styles = new ArrayList<>(styles); + styles.replaceAll(Symbology::clone); + } +} diff --git a/endorsed/src/org.apache.sis.portrayal/main/org/apache/sis/style/sld1/package-info.java b/endorsed/src/org.apache.sis.portrayal/main/org/apache/sis/style/sld1/package-info.java new file mode 100644 index 0000000000..776ebf0254 --- /dev/null +++ b/endorsed/src/org.apache.sis.portrayal/main/org/apache/sis/style/sld1/package-info.java @@ -0,0 +1,39 @@ +/* + * 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. + */ + + +/** + * Styled Layer Descriptor document model, for describing which styles apply to which layers. + * The classes in this package are derived from + * OGC 05-078r4 — <a href="https://www.ogc.org/standard/sld/">Styled Layer Descriptor</a> Implementation Specification 1.1.0. + * That document defines the {@code <StyledLayerDescriptor>} root element and its children, + * which reference or embed the Symbology Encoding elements defined in the + * {@link org.apache.sis.style.se1} package. + * The root element is {@link org.apache.sis.style.sld1.StyledLayerDescriptor}. + * The {@code <UserStyle>} element is represented by {@link org.apache.sis.style.se1.Symbology}. + * + * <h2>Future evolution</h2> + * This package defines an XML encoding. It is not an abstract model for sophisticated styling. + * More generic styling API may be provided in a future Apache SIS version in the {@code org.apache.sis.style} package. + * + * <h2>Synchronization</h2> + * Unless otherwise specified in the Javadoc, classes in this package are not thread-safe. + * Synchronization, if desired, must be done by the caller. + * + * @author Johann Sorel (Geomatys) + */ +package org.apache.sis.style.sld1; diff --git a/endorsed/src/org.apache.sis.portrayal/test/org/apache/sis/style/sld1/CoverageConstraintTest.java b/endorsed/src/org.apache.sis.portrayal/test/org/apache/sis/style/sld1/CoverageConstraintTest.java new file mode 100644 index 0000000000..ecf79c1555 --- /dev/null +++ b/endorsed/src/org.apache.sis.portrayal/test/org/apache/sis/style/sld1/CoverageConstraintTest.java @@ -0,0 +1,150 @@ +/* + * 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.style.sld1; + +// Test dependencies +import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.*; + + +/** + * Tests for {@link CoverageConstraint}, {@link CoverageExtent} and {@link RangeAxis}. + * + * @author Johann Sorel (Geomatys) + */ +public final class CoverageConstraintTest extends SLDTestCase { + /** + * Creates a new test case. + */ + public CoverageConstraintTest() { + } + + /** + * Creates a range axis with the given name and value. + */ + private static RangeAxis rangeAxis(final String name, final String value) { + final var axis = new RangeAxis(); + axis.setName(name); + axis.setValue(value); + return axis; + } + + /** + * Test of {@code CoverageName} property. + */ + @Test + public void testCoverageName() { + final var cdt = new CoverageConstraint(); + + // Check defaults + assertEmpty(cdt.getCoverageName()); + + // Check get/set + cdt.setCoverageName("the_coverage_name"); + assertOptionalEquals("the_coverage_name", cdt.getCoverageName()); + } + + /** + * Test of {@code CoverageExtent} property. + */ + @Test + public void testCoverageExtent() { + final var cdt = new CoverageConstraint(); + + // Check defaults + assertEmpty(cdt.getCoverageExtent()); + + // Check get/set + var value = new CoverageExtent(); + value.setTimePeriod("2005-05-17T00:00:00Z/2005-05-23T00:00:00Z"); + cdt.setCoverageExtent(value); + assertOptionalEquals(value, cdt.getCoverageExtent()); + } + + /** + * Test of {@code RangeAxis} and {@code TimePeriod} properties of {@link CoverageExtent}. + */ + @Test + public void testExtentProperties() { + final var cdt = new CoverageExtent(); + + // Check defaults + assertTrue(cdt.rangeAxes().isEmpty()); + assertEmpty(cdt.getTimePeriod()); + + // Check get/set + var band = rangeAxis("Band", "band_1"); + var time = rangeAxis("Time", "2005-05-19T09:28:40Z"); + cdt.rangeAxes().add(band); + cdt.rangeAxes().add(time); + assertEquals(2, cdt.rangeAxes().size()); + assertSame(band, cdt.rangeAxes().get(0)); + assertSame(time, cdt.rangeAxes().get(1)); + + final var period = new CoverageExtent(); + period.setTimePeriod("2005-05-17T00:00:00Z/2005-05-23T00:00:00Z"); + assertOptionalEquals("2005-05-17T00:00:00Z/2005-05-23T00:00:00Z", period.getTimePeriod()); + } + + /** + * Test of {@code Name} and {@code Value} properties of {@link RangeAxis}. + */ + @Test + public void testRangeAxis() { + final var cdt = new RangeAxis(); + + // Check defaults + assertEmpty(cdt.getName()); + assertEmpty(cdt.getValue()); + + // Check get/set + cdt.setName("Band"); + cdt.setValue("band_1"); + assertOptionalEquals("Band", cdt.getName()); + assertOptionalEquals("band_1", cdt.getValue()); + + final var clone = cdt.clone(); + assertCloneEquals(cdt, clone); + clone.setValue("band_2"); + assertNotEquals(cdt, clone); + } + + /** + * Tests {@code equals}, {@code hashCode} and deep {@code clone}. + */ + @Test + public void testClone() { + final var extent = new CoverageExtent(); + final var axis = rangeAxis("Band", "band_1"); + extent.rangeAxes().add(axis); + final var cdt = new CoverageConstraint(); + cdt.setCoverageName("the_coverage_name"); + cdt.setCoverageExtent(extent); + + final var clone = cdt.clone(); + assertCloneEquals(cdt, clone); + final var clonedExtent = clone.getCoverageExtent().orElseThrow(); + assertNotSame(extent, clonedExtent); + assertNotSame(extent.rangeAxes(), clonedExtent.rangeAxes()); + assertNotSame(axis, clonedExtent.rangeAxes().get(0)); + assertEquals (axis, clonedExtent.rangeAxes().get(0)); + + clonedExtent.rangeAxes().clear(); + assertNotEquals(cdt, clone); + assertEquals(1, extent.rangeAxes().size()); + } +} diff --git a/endorsed/src/org.apache.sis.portrayal/test/org/apache/sis/style/sld1/FeatureTypeConstraintTest.java b/endorsed/src/org.apache.sis.portrayal/test/org/apache/sis/style/sld1/FeatureTypeConstraintTest.java new file mode 100644 index 0000000000..491f481b6f --- /dev/null +++ b/endorsed/src/org.apache.sis.portrayal/test/org/apache/sis/style/sld1/FeatureTypeConstraintTest.java @@ -0,0 +1,148 @@ +/* + * 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.style.sld1; + +import org.apache.sis.filter.DefaultFilterFactory; +import org.apache.sis.util.iso.Names; + +// Test dependencies +import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.*; + +// Specific to the geoapi-3.1 and geoapi-4.0 branches: +import org.opengis.feature.Feature; +import org.opengis.filter.Filter; + + +/** + * Tests for {@link FeatureTypeConstraint} and {@link Extent}. + * + * @author Johann Sorel (Geomatys) + */ +public final class FeatureTypeConstraintTest extends SLDTestCase { + /** + * Creates a new test case. + */ + public FeatureTypeConstraintTest() { + } + + /** + * Creates an arbitrary filter on a feature property. + */ + private static Filter<Feature> anyFilter() { + final var ff = DefaultFilterFactory.forFeatures(); + return ff.greaterOrEqual(ff.property("num_lanes"), ff.literal(4)); + } + + /** + * Test of {@code FeatureTypeName} property. + */ + @Test + public void testFeatureTypeName() { + final var cdt = new FeatureTypeConstraint(); + + // Check defaults + assertEmpty(cdt.getFeatureTypeName()); + + // Check get/set + var value = Names.createLocalName(null, null, "the_feature_type_name"); + cdt.setFeatureTypeName(value); + assertOptionalEquals(value, cdt.getFeatureTypeName()); + } + + /** + * Test of {@code Filter} property. + */ + @Test + public void testFilter() { + final var cdt = new FeatureTypeConstraint(); + + // Check defaults + assertEmpty(cdt.getFilter()); + + // Check get/set + var value = anyFilter(); + cdt.setFilter(value); + assertOptionalEquals(value, cdt.getFilter()); + } + + /** + * Test of {@code Extent} property. + */ + @Test + public void testExtents() { + final var cdt = new FeatureTypeConstraint(); + + // Check defaults + assertTrue(cdt.extents().isEmpty()); + + // Check get/set + var value = new Extent(); + cdt.extents().add(value); + assertEquals(1, cdt.extents().size()); + assertSame(value, cdt.extents().get(0)); + } + + /** + * Test of {@code Name} and {@code Value} properties of {@link Extent}. + */ + @Test + public void testExtent() { + final var cdt = new Extent(); + + // Check defaults + assertEmpty(cdt.getName()); + assertEmpty(cdt.getValue()); + + // Check get/set + cdt.setName("extent_name"); + cdt.setValue("extent_value"); + assertOptionalEquals("extent_name", cdt.getName()); + assertOptionalEquals("extent_value", cdt.getValue()); + + final var clone = cdt.clone(); + assertCloneEquals(cdt, clone); + clone.setValue("other"); + assertNotEquals(cdt, clone); + } + + /** + * Tests {@code equals}, {@code hashCode} and deep {@code clone}. + * The filter shall be shared, not cloned. + */ + @Test + public void testClone() { + final var cdt = new FeatureTypeConstraint(); + cdt.setFeatureTypeName(Names.createLocalName(null, null, "the_feature_type_name")); + cdt.setFilter(anyFilter()); + final var extent = new Extent(); + extent.setName("extent_name"); + extent.setValue("extent_value"); + cdt.extents().add(extent); + + final var clone = cdt.clone(); + assertCloneEquals(cdt, clone); + assertSame(cdt.getFilter().orElseThrow(), clone.getFilter().orElseThrow()); + assertNotSame(cdt.extents(), clone.extents()); + assertNotSame(extent, clone.extents().get(0)); + assertEquals (extent, clone.extents().get(0)); + + final var copy = new FeatureTypeConstraint(cdt); + assertEquals(cdt, copy); + assertSame(extent, copy.extents().get(0)); + } +} diff --git a/endorsed/src/org.apache.sis.portrayal/test/org/apache/sis/style/sld1/InlineFeatureTest.java b/endorsed/src/org.apache.sis.portrayal/test/org/apache/sis/style/sld1/InlineFeatureTest.java new file mode 100644 index 0000000000..221e5a27ae --- /dev/null +++ b/endorsed/src/org.apache.sis.portrayal/test/org/apache/sis/style/sld1/InlineFeatureTest.java @@ -0,0 +1,88 @@ +/* + * 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.style.sld1; + +import org.apache.sis.feature.builder.FeatureTypeBuilder; + +// Test dependencies +import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.*; + +// Specific to the geoapi-3.1 and geoapi-4.0 branches: +import org.opengis.feature.Feature; + + +/** + * Tests for {@link InlineFeature}. + * + * @author Johann Sorel (Geomatys) + */ +public final class InlineFeatureTest extends SLDTestCase { + /** + * Creates a new test case. + */ + public InlineFeatureTest() { + } + + /** + * Creates a feature instance of an arbitrary type. + */ + private static Feature anyFeature() { + final var builder = new FeatureTypeBuilder().setName("test"); + builder.addAttribute(String.class).setName("name"); + final Feature feature = builder.build().newInstance(); + feature.setPropertyValue("name", "A random name"); + return feature; + } + + /** + * Test of {@code features} property. + */ + @Test + public void testFeatures() { + final var cdt = new InlineFeature(); + + // Check defaults + assertTrue(cdt.features().isEmpty()); + + // Check get/set + var value = anyFeature(); + cdt.features().add(value); + assertEquals(1, cdt.features().size()); + assertSame(value, cdt.features().get(0)); + } + + /** + * Tests {@code equals}, {@code hashCode} and {@code clone}. + * The list shall be copied, but not the features. + */ + @Test + public void testClone() { + final var cdt = new InlineFeature(); + final var feature = anyFeature(); + cdt.features().add(feature); + + final var clone = cdt.clone(); + assertCloneEquals(cdt, clone); + assertNotSame(cdt.features(), clone.features()); + assertSame(feature, clone.features().get(0)); + + clone.features().clear(); + assertNotEquals(cdt, clone); + assertEquals(1, cdt.features().size()); + } +} diff --git a/endorsed/src/org.apache.sis.portrayal/test/org/apache/sis/style/sld1/LayerConstraintsTest.java b/endorsed/src/org.apache.sis.portrayal/test/org/apache/sis/style/sld1/LayerConstraintsTest.java new file mode 100644 index 0000000000..ef995fef2a --- /dev/null +++ b/endorsed/src/org.apache.sis.portrayal/test/org/apache/sis/style/sld1/LayerConstraintsTest.java @@ -0,0 +1,93 @@ +/* + * 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.style.sld1; + +// Test dependencies +import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.*; + + +/** + * Tests for {@link LayerFeatureConstraints} and {@link LayerCoverageConstraints}. + * + * @author Johann Sorel (Geomatys) + */ +public final class LayerConstraintsTest extends SLDTestCase { + /** + * Creates a new test case. + */ + public LayerConstraintsTest() { + } + + /** + * Test of {@code FeatureTypeConstraint} property. + */ + @Test + public void testFeatureConstraints() { + final var cdt = new LayerFeatureConstraints(); + + // Check defaults + assertTrue(cdt.constraints().isEmpty()); + + // Check get/set + var value = new FeatureTypeConstraint(); + cdt.constraints().add(value); + assertEquals(1, cdt.constraints().size()); + assertSame(value, cdt.constraints().get(0)); + + // Deep clone + final LayerConstraints<FeatureTypeConstraint> clone = cdt.clone(); + assertCloneEquals(cdt, clone); + assertNotSame(cdt.constraints(), clone.constraints()); + assertNotSame(value, clone.constraints().get(0)); + assertEquals (value, clone.constraints().get(0)); + } + + /** + * Test of {@code CoverageConstraint} property. + */ + @Test + public void testCoverageConstraints() { + final var cdt = new LayerCoverageConstraints(); + + // Check defaults + assertTrue(cdt.constraints().isEmpty()); + + // Check get/set + var value = new CoverageConstraint(); + value.setCoverageName("the_coverage_name"); + cdt.constraints().add(value); + assertEquals(1, cdt.constraints().size()); + assertSame(value, cdt.constraints().get(0)); + + // Deep clone + final LayerConstraints<CoverageConstraint> clone = cdt.clone(); + assertCloneEquals(cdt, clone); + assertNotSame(cdt.constraints(), clone.constraints()); + assertNotSame(value, clone.constraints().get(0)); + assertEquals (value, clone.constraints().get(0)); + } + + /** + * Verifies that feature and coverage constraints are not equal even when both are empty. + */ + @Test + public void testNotEquals() { + assertNotEquals(new LayerFeatureConstraints(), new LayerCoverageConstraints()); + assertEquals(new LayerFeatureConstraints(), new LayerFeatureConstraints()); + } +} diff --git a/endorsed/src/org.apache.sis.portrayal/test/org/apache/sis/style/sld1/NamedLayerTest.java b/endorsed/src/org.apache.sis.portrayal/test/org/apache/sis/style/sld1/NamedLayerTest.java new file mode 100644 index 0000000000..10b4b1a759 --- /dev/null +++ b/endorsed/src/org.apache.sis.portrayal/test/org/apache/sis/style/sld1/NamedLayerTest.java @@ -0,0 +1,131 @@ +/* + * 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.style.sld1; + +// Test dependencies +import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.*; + + +/** + * Tests for {@link NamedLayer}. + * + * @author Johann Sorel (Geomatys) + */ +public final class NamedLayerTest extends SLDTestCase { + /** + * Creates a new test case. + */ + public NamedLayerTest() { + } + + /** + * Test of {@code Name} property. + */ + @Test + public void testName() { + final var cdt = new NamedLayer(); + + // Check defaults + assertEmpty(cdt.getName()); + + // Check get/set + String value = "A random name"; + cdt.setName(value); + assertOptionalEquals(value, cdt.getName()); + } + + /** + * Test of {@code Description} property. + */ + @Test + public void testDescription() { + final var cdt = new NamedLayer(); + + // Check defaults + assertEmpty(cdt.getDescription()); + + // Check get/set + var desc = anyDescription(); + cdt.setDescription(desc); + assertOptionalEquals(desc, cdt.getDescription()); + } + + /** + * Test of {@code LayerFeatureConstraints} property. + */ + @Test + public void testConstraints() { + final var cdt = new NamedLayer(); + + // Check defaults + assertEmpty(cdt.getConstraints()); + + // Check get/set + var value = new LayerFeatureConstraints(); + value.constraints().add(new FeatureTypeConstraint()); + cdt.setConstraints(value); + assertOptionalEquals(value, cdt.getConstraints()); + } + + /** + * Test of {@code NamedStyle} and {@code UserStyle} properties. + */ + @Test + public void testStyles() { + final var cdt = new NamedLayer(); + + // Check defaults + assertTrue(cdt.styles().isEmpty()); + + // Check get/set + var named = new NamedStyle(); + var user = anyUserStyle("user_style"); + cdt.styles().add(named); + cdt.styles().add(user); + assertEquals(2, cdt.styles().size()); + assertSame(named, cdt.styles().get(0)); + assertSame(user, cdt.styles().get(1)); + } + + /** + * Tests {@code equals}, {@code hashCode} and deep {@code clone}. + */ + @Test + public void testClone() { + final var cdt = new NamedLayer(); + cdt.setName("named_layer"); + cdt.setDescription(anyDescription()); + final var constraints = new LayerFeatureConstraints(); + constraints.constraints().add(new FeatureTypeConstraint()); + cdt.setConstraints(constraints); + final var style = new NamedStyle(); + style.setName("named_style"); + cdt.styles().add(style); + + final var clone = cdt.clone(); + assertCloneEquals(cdt, clone); + assertNotSame(cdt.getDescription().orElseThrow(), clone.getDescription().orElseThrow()); + assertNotSame(constraints, clone.getConstraints().orElseThrow()); + assertNotSame(style, clone.styles().get(0)); + assertEquals (style, clone.styles().get(0)); + + clone.styles().clear(); + assertNotEquals(cdt, clone); + assertEquals(1, cdt.styles().size()); + } +} diff --git a/endorsed/src/org.apache.sis.portrayal/test/org/apache/sis/style/sld1/NamedStyleTest.java b/endorsed/src/org.apache.sis.portrayal/test/org/apache/sis/style/sld1/NamedStyleTest.java new file mode 100644 index 0000000000..c1dd3878c6 --- /dev/null +++ b/endorsed/src/org.apache.sis.portrayal/test/org/apache/sis/style/sld1/NamedStyleTest.java @@ -0,0 +1,94 @@ +/* + * 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.style.sld1; + +import org.apache.sis.style.Style; + +// Test dependencies +import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.*; + + +/** + * Tests for {@link NamedStyle}. + * + * @author Johann Sorel (Geomatys) + */ +public final class NamedStyleTest extends SLDTestCase { + /** + * Creates a new test case. + */ + public NamedStyleTest() { + } + + /** + * Verifies that a named style is a {@link Style}. + */ + @Test + public void testIsStyle() { + assertInstanceOf(Style.class, new NamedStyle()); + } + + /** + * Test of {@code Name} property. + */ + @Test + public void testName() { + final var cdt = new NamedStyle(); + + // Check defaults + assertEmpty(cdt.getName()); + + // Check get/set + String value = "A random name"; + cdt.setName(value); + assertOptionalEquals(value, cdt.getName()); + } + + /** + * Test of {@code Description} property. + */ + @Test + public void testDescription() { + final var cdt = new NamedStyle(); + + // Check defaults + assertEmpty(cdt.getDescription()); + + // Check get/set + var desc = anyDescription(); + cdt.setDescription(desc); + assertOptionalEquals(desc, cdt.getDescription()); + } + + /** + * Tests {@code equals}, {@code hashCode} and deep {@code clone}. + */ + @Test + public void testClone() { + final var cdt = new NamedStyle(); + cdt.setName("named_style"); + cdt.setDescription(anyDescription()); + + final var clone = cdt.clone(); + assertCloneEquals(cdt, clone); + assertNotSame(cdt.getDescription().orElseThrow(), clone.getDescription().orElseThrow()); + + clone.setName("other"); + assertNotEquals(cdt, clone); + } +} diff --git a/endorsed/src/org.apache.sis.portrayal/test/org/apache/sis/style/sld1/RemoteOWSTest.java b/endorsed/src/org.apache.sis.portrayal/test/org/apache/sis/style/sld1/RemoteOWSTest.java new file mode 100644 index 0000000000..5737c8b13a --- /dev/null +++ b/endorsed/src/org.apache.sis.portrayal/test/org/apache/sis/style/sld1/RemoteOWSTest.java @@ -0,0 +1,83 @@ +/* + * 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.style.sld1; + +// Test dependencies +import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.*; + + +/** + * Tests for {@link RemoteOWS}. + * + * @author Johann Sorel (Geomatys) + */ +public final class RemoteOWSTest extends SLDTestCase { + /** + * Creates a new test case. + */ + public RemoteOWSTest() { + } + + /** + * Test of {@code Service} property. + */ + @Test + public void testService() { + final var cdt = new RemoteOWS(); + + // Check defaults + assertEmpty(cdt.getService()); + + // Check get/set + cdt.setService("WCS"); + assertOptionalEquals("WCS", cdt.getService()); + } + + /** + * Test of {@code OnlineResource} property. + */ + @Test + public void testOnlineResource() { + final var cdt = new RemoteOWS(); + + // Check defaults + assertEmpty(cdt.getOnlineResource()); + + // Check get/set + var value = anyOnlineResource(); + cdt.setOnlineResource(value); + assertOptionalEquals(value, cdt.getOnlineResource()); + } + + /** + * Tests {@code equals}, {@code hashCode} and {@code clone}. + */ + @Test + public void testClone() { + final var cdt = new RemoteOWS(); + cdt.setService("WFS"); + cdt.setOnlineResource(anyOnlineResource()); + + final var clone = cdt.clone(); + assertCloneEquals(cdt, clone); + assertSame(cdt.getOnlineResource().orElseThrow(), clone.getOnlineResource().orElseThrow()); + + clone.setService("WCS"); + assertNotEquals(cdt, clone); + } +} diff --git a/endorsed/src/org.apache.sis.portrayal/test/org/apache/sis/style/sld1/SLDTestCase.java b/endorsed/src/org.apache.sis.portrayal/test/org/apache/sis/style/sld1/SLDTestCase.java new file mode 100644 index 0000000000..cf0717476c --- /dev/null +++ b/endorsed/src/org.apache.sis.portrayal/test/org/apache/sis/style/sld1/SLDTestCase.java @@ -0,0 +1,113 @@ +/* + * 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.style.sld1; + +import java.net.URI; +import java.util.Optional; +import org.opengis.metadata.citation.OnlineResource; +import org.apache.sis.metadata.iso.citation.DefaultOnlineResource; +import org.apache.sis.style.se1.Description; +import org.apache.sis.style.se1.FeatureTypeStyle; +import org.apache.sis.style.se1.Symbology; +import org.apache.sis.util.SimpleInternationalString; + +// Test dependencies +import static org.junit.jupiter.api.Assertions.*; +import org.apache.sis.test.TestCase; + +// Specific to the geoapi-3.1 and geoapi-4.0 branches: +import org.opengis.feature.Feature; + + +/** + * Base class of all tests of Styled Layer Descriptor elements. + * + * @author Johann Sorel (Geomatys) + */ +abstract class SLDTestCase extends TestCase { + /** + * Creates a new test case. + */ + SLDTestCase() { + } + + /** + * Creates a dummy description with arbitrary title and abstract. + * + * @return a new description. + */ + static Description<Feature> anyDescription() { + final var value = FeatureTypeStyle.FACTORY.createDescription(); + value.setTitle(new SimpleInternationalString("A random title")); + value.setAbstract(new SimpleInternationalString("A random abstract")); + return value; + } + + /** + * Creates a dummy online resource. + * + * @return a new online resource. + */ + static OnlineResource anyOnlineResource() { + return new DefaultOnlineResource(URI.create("http://example.org/resource.xml")); + } + + /** + * Creates a dummy user style containing one feature type style. + * + * @param name name of the user style. + * @return a new user style. + */ + static Symbology anyUserStyle(final String name) { + final var style = new Symbology(); + style.setName(name); + style.featureTypeStyles().add(new FeatureTypeStyle()); + return style; + } + + /** + * Asserts that the given optional is empty. + * + * @param opt the optional to check. + */ + static void assertEmpty(final Optional<?> opt) { + assertTrue(opt.isEmpty()); + } + + /** + * Asserts that the value of the given optional is equal to the expected value. + * + * @param <E> type of object to compare. + * @param expected the expected value. + * @param opt the actual value in an optional. + */ + static <E> void assertOptionalEquals(final E expected, final Optional<E> opt) { + assertEquals(expected, opt.orElseThrow()); + } + + /** + * Asserts that the given clone is equal to the original but is a distinct instance. + * + * @param original the original object. + * @param clone the clone of the original object. + */ + static void assertCloneEquals(final Object original, final Object clone) { + assertNotSame(original, clone); + assertEquals(original, clone); + assertEquals(original.hashCode(), clone.hashCode()); + } +} diff --git a/endorsed/src/org.apache.sis.portrayal/test/org/apache/sis/style/sld1/StyledLayerDescriptorTest.java b/endorsed/src/org.apache.sis.portrayal/test/org/apache/sis/style/sld1/StyledLayerDescriptorTest.java new file mode 100644 index 0000000000..ab3697651f --- /dev/null +++ b/endorsed/src/org.apache.sis.portrayal/test/org/apache/sis/style/sld1/StyledLayerDescriptorTest.java @@ -0,0 +1,169 @@ +/* + * 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.style.sld1; + +// Test dependencies +import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.*; + + +/** + * Tests for {@link StyledLayerDescriptor}. + * + * @author Johann Sorel (Geomatys) + */ +public final class StyledLayerDescriptorTest extends SLDTestCase { + /** + * Creates a new test case. + */ + public StyledLayerDescriptorTest() { + } + + /** + * Test of {@code version} property. + */ + @Test + public void testVersion() { + final var cdt = new StyledLayerDescriptor(); + assertEquals(StyledLayerDescriptor.VERSION, cdt.getVersion()); + assertEquals("1.1.0", cdt.getVersion()); + } + + /** + * Test of {@code Name} property. + */ + @Test + public void testName() { + final var cdt = new StyledLayerDescriptor(); + + // Check defaults + assertEmpty(cdt.getName()); + + // Check get/set + String value = "A random name"; + cdt.setName(value); + assertOptionalEquals(value, cdt.getName()); + } + + /** + * Test of {@code Description} property. + */ + @Test + public void testDescription() { + final var cdt = new StyledLayerDescriptor(); + + // Check defaults + assertEmpty(cdt.getDescription()); + + // Check get/set + var desc = anyDescription(); + cdt.setDescription(desc); + assertOptionalEquals(desc, cdt.getDescription()); + } + + /** + * Test of {@code UseSLDLibrary} property. + */ + @Test + public void testLibraries() { + final var cdt = new StyledLayerDescriptor(); + + // Check defaults + assertTrue(cdt.libraries().isEmpty()); + + // Check get/set + var value = new UseSLDLibrary(); + value.setOnlineResource(anyOnlineResource()); + cdt.libraries().add(value); + assertEquals(1, cdt.libraries().size()); + assertSame(value, cdt.libraries().get(0)); + } + + /** + * Test of {@code NamedLayer} and {@code UserLayer} properties. + */ + @Test + public void testLayers() { + final var cdt = new StyledLayerDescriptor(); + + // Check defaults + assertTrue(cdt.layers().isEmpty()); + + // Check get/set + var named = new NamedLayer(); + var user = new UserLayer(); + cdt.layers().add(named); + cdt.layers().add(user); + assertEquals(2, cdt.layers().size()); + assertSame(named, cdt.layers().get(0)); + assertSame(user, cdt.layers().get(1)); + } + + /** + * Tests {@code equals}, {@code hashCode} and deep {@code clone} on a filled descriptor. + */ + @Test + public void testEqualsAndClone() { + final var cdt = new StyledLayerDescriptor(); + cdt.setName("sld"); + cdt.setDescription(anyDescription()); + final var library = new UseSLDLibrary(); + library.setOnlineResource(anyOnlineResource()); + cdt.libraries().add(library); + + final var named = new NamedLayer(); + named.setName("named_layer"); + final var namedStyle = new NamedStyle(); + namedStyle.setName("named_style"); + named.styles().add(namedStyle); + named.styles().add(anyUserStyle("user_style")); + cdt.layers().add(named); + + final var user = new UserLayer(); + user.setName("user_layer"); + user.setSource(new RemoteOWS()); + user.styles().add(anyUserStyle("user_style")); + cdt.layers().add(user); + + // Copy constructor is shallow. + final var copy = new StyledLayerDescriptor(cdt); + assertEquals(cdt, copy); + assertSame(cdt.layers().get(0), copy.layers().get(0)); + + // Clone is deep. + final var clone = cdt.clone(); + assertCloneEquals(cdt, clone); + assertNotSame(cdt.libraries(), clone.libraries()); + assertNotSame(cdt.layers(), clone.layers()); + assertNotSame(cdt.getDescription().orElseThrow(), clone.getDescription().orElseThrow()); + assertNotSame(cdt.libraries().get(0), clone.libraries().get(0)); + assertNotSame(cdt.layers().get(0), clone.layers().get(0)); + assertNotSame(cdt.layers().get(1), clone.layers().get(1)); + + final var clonedNamed = (NamedLayer) clone.layers().get(0); + assertNotSame(named.styles().get(0), clonedNamed.styles().get(0)); + assertNotSame(named.styles().get(1), clonedNamed.styles().get(1)); + assertEquals (named.styles().get(1), clonedNamed.styles().get(1)); + + // Changes in the clone do not impact the original. + clone.setName("other"); + clone.layers().clear(); + assertNotEquals(cdt, clone); + assertOptionalEquals("sld", cdt.getName()); + assertEquals(2, cdt.layers().size()); + } +} diff --git a/endorsed/src/org.apache.sis.portrayal/test/org/apache/sis/style/sld1/UseSLDLibraryTest.java b/endorsed/src/org.apache.sis.portrayal/test/org/apache/sis/style/sld1/UseSLDLibraryTest.java new file mode 100644 index 0000000000..9c5e411f9d --- /dev/null +++ b/endorsed/src/org.apache.sis.portrayal/test/org/apache/sis/style/sld1/UseSLDLibraryTest.java @@ -0,0 +1,66 @@ +/* + * 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.style.sld1; + +// Test dependencies +import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.*; + + +/** + * Tests for {@link UseSLDLibrary}. + * + * @author Johann Sorel (Geomatys) + */ +public final class UseSLDLibraryTest extends SLDTestCase { + /** + * Creates a new test case. + */ + public UseSLDLibraryTest() { + } + + /** + * Test of {@code OnlineResource} property. + */ + @Test + public void testOnlineResource() { + final var cdt = new UseSLDLibrary(); + + // Check defaults + assertEmpty(cdt.getOnlineResource()); + + // Check get/set + var value = anyOnlineResource(); + cdt.setOnlineResource(value); + assertOptionalEquals(value, cdt.getOnlineResource()); + } + + /** + * Tests {@code equals}, {@code hashCode} and {@code clone}. + */ + @Test + public void testClone() { + final var cdt = new UseSLDLibrary(); + cdt.setOnlineResource(anyOnlineResource()); + + final var clone = cdt.clone(); + assertCloneEquals(cdt, clone); + + clone.setOnlineResource(null); + assertNotEquals(cdt, clone); + } +} diff --git a/endorsed/src/org.apache.sis.portrayal/test/org/apache/sis/style/sld1/UserLayerTest.java b/endorsed/src/org.apache.sis.portrayal/test/org/apache/sis/style/sld1/UserLayerTest.java new file mode 100644 index 0000000000..688bd61f82 --- /dev/null +++ b/endorsed/src/org.apache.sis.portrayal/test/org/apache/sis/style/sld1/UserLayerTest.java @@ -0,0 +1,163 @@ +/* + * 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.style.sld1; + +// Test dependencies +import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.*; + + +/** + * Tests for {@link UserLayer}. + * + * @author Johann Sorel (Geomatys) + */ +public final class UserLayerTest extends SLDTestCase { + /** + * Creates a new test case. + */ + public UserLayerTest() { + } + + /** + * Test of {@code Name} property. + */ + @Test + public void testName() { + final var cdt = new UserLayer(); + + // Check defaults + assertEmpty(cdt.getName()); + + // Check get/set + String value = "A random name"; + cdt.setName(value); + assertOptionalEquals(value, cdt.getName()); + } + + /** + * Test of {@code Description} property. + */ + @Test + public void testDescription() { + final var cdt = new UserLayer(); + + // Check defaults + assertEmpty(cdt.getDescription()); + + // Check get/set + var desc = anyDescription(); + cdt.setDescription(desc); + assertOptionalEquals(desc, cdt.getDescription()); + } + + /** + * Test of {@code RemoteOWS} and {@code InlineFeature} properties. + */ + @Test + public void testSource() { + final var cdt = new UserLayer(); + + // Check defaults + assertEmpty(cdt.getSource()); + + // Check get/set + var remote = new RemoteOWS(); + remote.setService("WFS"); + cdt.setSource(remote); + assertOptionalEquals(remote, cdt.getSource()); + + var inline = new InlineFeature(); + cdt.setSource(inline); + assertOptionalEquals(inline, cdt.getSource()); + + cdt.setSource(null); + assertEmpty(cdt.getSource()); + } + + /** + * Test of {@code LayerFeatureConstraints} and {@code LayerCoverageConstraints} properties. + */ + @Test + public void testConstraints() { + final var cdt = new UserLayer(); + + // Check defaults + assertEmpty(cdt.getConstraints()); + + // Check get/set + var features = new LayerFeatureConstraints(); + features.constraints().add(new FeatureTypeConstraint()); + cdt.setConstraints(features); + assertOptionalEquals(features, cdt.getConstraints()); + + var coverages = new LayerCoverageConstraints(); + coverages.constraints().add(new CoverageConstraint()); + cdt.setConstraints(coverages); + assertOptionalEquals(coverages, cdt.getConstraints()); + } + + /** + * Test of {@code UserStyle} property. + */ + @Test + public void testStyles() { + final var cdt = new UserLayer(); + + // Check defaults + assertTrue(cdt.styles().isEmpty()); + + // Check get/set + var value = anyUserStyle("user_style"); + cdt.styles().add(value); + assertEquals(1, cdt.styles().size()); + assertSame(value, cdt.styles().get(0)); + } + + /** + * Tests {@code equals}, {@code hashCode} and deep {@code clone}. + */ + @Test + public void testClone() { + final var cdt = new UserLayer(); + cdt.setName("user_layer"); + final var remote = new RemoteOWS(); + remote.setService("WCS"); + remote.setOnlineResource(anyOnlineResource()); + cdt.setSource(remote); + final var coverages = new LayerCoverageConstraints(); + final var constraint = new CoverageConstraint(); + constraint.setCoverageName("the_coverage_name"); + coverages.constraints().add(constraint); + cdt.setConstraints(coverages); + final var style = anyUserStyle("user_style"); + cdt.styles().add(style); + + final var clone = cdt.clone(); + assertCloneEquals(cdt, clone); + assertNotSame(remote, clone.getSource().orElseThrow()); + assertNotSame(coverages, clone.getConstraints().orElseThrow()); + assertNotSame(style, clone.styles().get(0)); + assertEquals (style, clone.styles().get(0)); + assertSame(remote.getOnlineResource().orElseThrow(), + ((RemoteOWS) clone.getSource().orElseThrow()).getOnlineResource().orElseThrow()); + + final var copy = new UserLayer(cdt); + assertEquals(cdt, copy); + assertSame(remote, copy.getSource().orElseThrow()); + } +}
