sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jso...@apache.org
Subject svn commit: r1823451 - in /sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/storage: Aggregate.java Capability.java FeatureSet.java Resource.java
Date Wed, 07 Feb 2018 10:36:42 GMT
Author: jsorel
Date: Wed Feb  7 10:36:42 2018
New Revision: 1823451

URL: http://svn.apache.org/viewvc?rev=1823451&view=rev
Log:
DataStore : add Capability API on Resources

Added:
    sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/storage/Capability.java
Modified:
    sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/storage/Aggregate.java
    sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/storage/FeatureSet.java
    sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/storage/Resource.java

Modified: sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/storage/Aggregate.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/storage/Aggregate.java?rev=1823451&r1=1823450&r2=1823451&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/storage/Aggregate.java
[UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/storage/Aggregate.java
[UTF-8] Wed Feb  7 10:36:42 2018
@@ -109,6 +109,9 @@ public interface Aggregate extends Resou
      * then this {@code Aggregate} may throw an exception.
      * </div>
      *
+     * <p>The {@link Capability#WRITABLE} flag if present in the {@link Resource#getCapabilities()
} set
+     * indicate this method should be implemented</p>
+     *
      * <p>The default implementation throws {@link ReadOnlyStorageException}.</p>
      *
      * @param  resource  the resource to copy in this {@code Aggregate}.
@@ -124,6 +127,9 @@ public interface Aggregate extends Resou
      * Removes a {@code Resource} from this {@code Aggregate}.
      * This operation is destructive: the {@link Resource} and it's related data will be
removed.
      *
+     * <p>The {@link Capability#WRITABLE} flag if present in the {@link Resource#getCapabilities()
} set
+     * indicate this method should be implemented</p>
+     *
      * <p>The default implementation throws {@link ReadOnlyStorageException}.</p>
      *
      * @param  resource  child resource to remove, should not be null.

Added: sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/storage/Capability.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/storage/Capability.java?rev=1823451&view=auto
==============================================================================
--- sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/storage/Capability.java
(added)
+++ sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/storage/Capability.java
Wed Feb  7 10:36:42 2018
@@ -0,0 +1,103 @@
+/*
+ * 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.storage;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.opengis.util.CodeList;
+import static org.opengis.util.CodeList.valueOf;
+
+/**
+ * A capability indicate a special behavior or information for a {@link Resource}.
+ * Capabilities are used as flags returned by the {@link Resource#getCapabilities() } method.
+ *
+ * A common {@link Capability} is {@link Capability#WRITABLE} which should be declared
+ * accordingly by {@link Resource}s.
+ *
+ * @author Johann Sorel (Geomatys)
+ * @version 1.0
+ * @since   1.0
+ * @module
+ */
+public class Capability extends CodeList<Capability> {
+    /**
+     * Serial number for compatibility with different versions.
+     */
+    private static final long serialVersionUID = -741484716063556569L;
+
+    /**
+     * List of all enumerations of this type.
+     * Must be declared before any enum declaration.
+     */
+    private static final List<Capability> VALUES = new ArrayList<>();
+
+    /**
+     * The resource support writing operations.
+     * The methods related to writing such as {@link FeatureSet#add(java.util.Iterator) }
+     * should not throw any unsupported exception if this capability is set.
+     */
+    public static final Capability WRITABLE = new Capability("WRITABLE");
+
+    /**
+     * Constructs an element of the given name. The new element is
+     * automatically added to the list returned by {@link #values()}.
+     *
+     * @param  name  the name of the new element.
+     *         This name must not be in use by an other element of this type.
+     */
+    private Capability(final String name) {
+        super(name, VALUES);
+    }
+
+    /**
+     * Returns the list of {@code Capability}s.
+     *
+     * @return the list of codes declared in the current JVM.
+     */
+    public static Capability[] values() {
+        synchronized (VALUES) {
+            return VALUES.toArray(new Capability[VALUES.size()]);
+        }
+    }
+
+    /**
+     * Returns the list of codes of the same kind than this code list element.
+     * Invoking this method is equivalent to invoking {@link #values()}, except that
+     * this method can be invoked on an instance of the parent {@code CodeList} class.
+     *
+     * @return all code {@linkplain #values() values} for this code list.
+     */
+    @Override
+    public Capability[] family() {
+        return values();
+    }
+
+    /**
+     * Returns the capability that matches the given string, or returns a
+     * new one if none match it. More specifically, this methods returns the first instance
for
+     * which <code>{@linkplain #name() name()}.{@linkplain String#equals equals}(code)</code>
+     * returns {@code true}. If no existing instance is found, then a new one is created
for
+     * the given name.
+     *
+     * @param  code  the name of the code to fetch or to create.
+     * @return a code matching the given name.
+     */
+    public static Capability valueOf(String code) {
+        return valueOf(Capability.class, code);
+    }
+}
+

Modified: sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/storage/FeatureSet.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/storage/FeatureSet.java?rev=1823451&r1=1823450&r2=1823451&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/storage/FeatureSet.java
[UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/storage/FeatureSet.java
[UTF-8] Wed Feb  7 10:36:42 2018
@@ -151,6 +151,9 @@ public interface FeatureSet extends Data
      * than implementing a {@link Stream}. On the other side if the user has a {@link Stream},
      * obtaining an {@link Iterator} can be done by a call to {@link Stream#iterator()}.</div>
      *
+     * <p>The {@link Capability#WRITABLE} flag if present in the {@link Resource#getCapabilities()
} set
+     * indicate this method should be implemented</p>
+     *
      * <p>The default implementation throws {@link ReadOnlyStorageException}.</p>
      *
      * @param  features features to insert in this {@code FeatureSet}.
@@ -164,6 +167,9 @@ public interface FeatureSet extends Data
     /**
      * Removes all features from this {@code FeatureSet} which matches the given predicate.
      *
+     * <p>The {@link Capability#WRITABLE} flag if present in the {@link Resource#getCapabilities()
} set
+     * indicate this method should be implemented</p>
+     *
      * <p>The default implementation throws {@link ReadOnlyStorageException}.</p>
      *
      * @param  filter  a predicate which returns true for resources to be removed.
@@ -187,6 +193,9 @@ public interface FeatureSet extends Data
      *   <li>If the operator returns {@code null}, then the feature will be removed
from the {@code FeatureSet}.</li>
      * </ul>
      *
+     * <p>The {@link Capability#WRITABLE} flag if present in the {@link Resource#getCapabilities()
} set
+     * indicate this method should be implemented</p>
+     *
      * <p>The default implementation throws {@link ReadOnlyStorageException}.</p>
      *
      * @param  filter   a predicate which returns true for resources to be updated.

Modified: sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/storage/Resource.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/storage/Resource.java?rev=1823451&r1=1823450&r2=1823451&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/storage/Resource.java
[UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/storage/Resource.java
[UTF-8] Wed Feb  7 10:36:42 2018
@@ -16,6 +16,8 @@
  */
 package org.apache.sis.storage;
 
+import java.util.Collections;
+import java.util.Set;
 import org.opengis.metadata.Metadata;
 
 
@@ -103,4 +105,19 @@ public interface Resource {
      * @see DataStore#getMetadata()
      */
     Metadata getMetadata() throws DataStoreException;
+
+    /**
+     * Returns the capabilities of this resource.
+     * Resources may have different capabilites based on the type and context.<br>
+     * Example : {@link Capability#WRITABLE} can be found on {@link Aggregate} or
+     * {@link FeatureSet} to indicate the resource support writing operations.
+     *
+     * <p>The default implementation returns an empty Set.</p>
+     *
+     * @return Set of {@link Capability}, never null, unmodifiable, can be empty.
+     */
+    default Set<Capability> getCapabilities() {
+        return Collections.EMPTY_SET;
+    }
+
 }



Mime
View raw message