sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1753989 - in /sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/builder: FeatureTypeBuilder.java OperationWrapper.java
Date Mon, 25 Jul 2016 12:53:56 GMT
Author: desruisseaux
Date: Mon Jul 25 12:53:56 2016
New Revision: 1753989

URL: http://svn.apache.org/viewvc?rev=1753989&view=rev
Log:
Add a FeatureTypeBuilder.addOperation(...) method.

Added:
    sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/builder/OperationWrapper.java
  (with props)
Modified:
    sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/builder/FeatureTypeBuilder.java

Modified: sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/builder/FeatureTypeBuilder.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/builder/FeatureTypeBuilder.java?rev=1753989&r1=1753988&r2=1753989&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/builder/FeatureTypeBuilder.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/builder/FeatureTypeBuilder.java
[UTF-8] Mon Jul 25 12:53:56 2016
@@ -41,6 +41,7 @@ import org.opengis.feature.Feature;
 import org.opengis.feature.FeatureType;
 import org.opengis.feature.PropertyType;
 import org.opengis.feature.FeatureAssociationRole;
+import org.opengis.feature.Operation;
 
 
 /**
@@ -522,6 +523,23 @@ public class FeatureTypeBuilder extends
         properties.add(property);
         clearCache();
         return property;
+    }
+
+    /**
+     * Adds the given operation in the feature type properties. The given operation object
will be added verbatim
+     * in the {@code FeatureType}; this builder does not create new operations.
+     *
+     * @param  operation  the operation to add to the feature type.
+     * @return a read-only accessor on the operation properties.
+     *
+     * @see #properties()
+     */
+    public PropertyTypeBuilder addOperation(final Operation operation) {
+        ensureNonNull("operation", operation);
+        final PropertyTypeBuilder property = new OperationWrapper(this, operation);
+        properties.add(property);
+        clearCache();
+        return property;
     }
 
     /**

Added: sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/builder/OperationWrapper.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/builder/OperationWrapper.java?rev=1753989&view=auto
==============================================================================
--- sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/builder/OperationWrapper.java
(added)
+++ sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/builder/OperationWrapper.java
[UTF-8] Mon Jul 25 12:53:56 2016
@@ -0,0 +1,84 @@
+/*
+ * 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.feature.builder;
+
+import org.opengis.feature.Operation;
+import org.opengis.feature.PropertyType;
+import org.opengis.util.GenericName;
+import org.apache.sis.util.resources.Errors;
+
+
+/**
+ * Wraps an existing operation. This package can not create new operations, except for a
few special cases.
+ * The user need to specify fully formed objects.
+ *
+ * @author  Johann Sorel (Geomatys)
+ * @author  Martin Desruisseaux (Geomatys)
+ * @since   0.8
+ * @version 0.8
+ * @module
+ */
+final class OperationWrapper extends PropertyTypeBuilder {
+    /**
+     * The wrapped operation.
+     */
+    private final Operation operation;
+
+    /**
+     * Creates a new wrapper for the given operation.
+     */
+    OperationWrapper(final FeatureTypeBuilder owner, final Operation operation) {
+        super(owner, operation);
+        this.operation = operation;
+        minimumOccurs = 1;
+        maximumOccurs = 1;
+    }
+
+    /**
+     * Returns the wrapped operation.
+     */
+    @Override
+    PropertyType create() {
+        return operation;
+    }
+
+    /**
+     * Do not allow a change of cardinality.
+     */
+    @Override
+    public PropertyTypeBuilder setCardinality(final int minimumOccurs, final int maximumOccurs)
{
+        if (minimumOccurs != 1 || maximumOccurs != 1) {
+            throw readOnly();
+        }
+        return this;
+    }
+
+    /**
+     * Do not allow modifications.
+     */
+    @Override public TypeBuilder setName       (GenericName name)         {throw readOnly();}
+    @Override public TypeBuilder setDefinition (CharSequence definition)  {throw readOnly();}
+    @Override public TypeBuilder setDesignation(CharSequence designation) {throw readOnly();}
+    @Override public TypeBuilder setDescription(CharSequence description) {throw readOnly();}
+
+    /**
+     * Returns the exception to be thrown for read-only wrapper.
+     */
+    private UnsupportedOperationException readOnly() {
+        throw new UnsupportedOperationException(errors().getString(Errors.Keys.UnmodifiableObject_1,
PropertyTypeBuilder.class));
+    }
+}

Propchange: sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/builder/OperationWrapper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK8/core/sis-feature/src/main/java/org/apache/sis/feature/builder/OperationWrapper.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain;charset=UTF-8



Mime
View raw message