sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1450757 - in /sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata: KeyNamePolicy.java NullValuePolicy.java PropertyComparator.java TypeValuePolicy.java
Date Wed, 27 Feb 2013 12:30:20 GMT
Author: desruisseaux
Date: Wed Feb 27 12:30:20 2013
New Revision: 1450757

URL: http://svn.apache.org/r1450757
Log:
Ported enumerations which will be needed by AbstractMetadata, and an package-private class
which will be needed by the implementation.

Added:
    sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/KeyNamePolicy.java
  (with props)
    sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/NullValuePolicy.java
  (with props)
    sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/PropertyComparator.java
  (with props)
    sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/TypeValuePolicy.java
  (with props)

Added: sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/KeyNamePolicy.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/KeyNamePolicy.java?rev=1450757&view=auto
==============================================================================
--- sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/KeyNamePolicy.java
(added)
+++ sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/KeyNamePolicy.java
[UTF-8] Wed Feb 27 12:30:20 2013
@@ -0,0 +1,69 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sis.metadata;
+
+import org.opengis.annotation.UML;
+
+
+/**
+ * The name of the keys included in a {@link java.util.Map} of metadata. Those maps are created
+ * by the {@link AbstractMetadata#asMap()} method. The keys in those map are {@link String}s
which
+ * can be inferred from the {@linkplain UML#identifier() UML identifier}, the name of the
Javabeans
+ * property, or the {@linkplain java.lang.reflect.Method#getName() method name}.
+ *
+ * <p>In GeoAPI implementation of ISO 19115, {@code UML_IDENTIFIER} and {@code JAVA_PROPERTY}
+ * names are usually identical except for {@linkplain java.util.Collection collections}:
+ * {@code JAVA_PROPERTY} names are plural when the property is a collection while
+ * {@code UML_IDENTIFIER} usually stay singular no matter the property cardinality.</p>
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @since   0.3 (derived from geotk-3.03)
+ * @version 0.3
+ * @module
+ *
+ * @see MetadataStandard#asMap(Object, KeyNamePolicy, NullValuePolicy)
+ */
+public enum KeyNamePolicy {
+    /**
+     * The keys in the map are the {@linkplain UML#identifier() UML identifier} of the metadata
+     * properties. If a property has no UML annotation, then the Javabeans property name
is used
+     * as a fallback.
+     */
+    UML_IDENTIFIER,
+
+    /**
+     * The keys in the map are the Javabeans property names. This is the method name with
+     * the {@code get} or {@code is} prefix removed, and the first letter made lower-case.
+     *
+     * <p>This is the default type of names returned by {@link AbstractMetadata#asMap()}.</p>
+     */
+    JAVABEANS_PROPERTY,
+
+    /**
+     * The keys in the map are the plain {@linkplain java.lang.reflect.Method#getName() method
names}.
+     */
+    METHOD_NAME,
+
+    /**
+     * The keys in the map are sentences inferred from the UML identifiers. This policy starts
+     * with the same names than {@link #UML_IDENTIFIER}, searches for word boundaries (defined
+     * as a lower case letter followed by a upper case letter) and inserts a space between
the
+     * words found. The first letter in the sentence is made upper-case. The first letters
of
+     * following words are made lower-case.
+     */
+    SENTENCE
+}

Propchange: sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/KeyNamePolicy.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/KeyNamePolicy.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain;charset=UTF-8

Added: sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/NullValuePolicy.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/NullValuePolicy.java?rev=1450757&view=auto
==============================================================================
--- sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/NullValuePolicy.java
(added)
+++ sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/NullValuePolicy.java
[UTF-8] Wed Feb 27 12:30:20 2013
@@ -0,0 +1,53 @@
+/*
+ * 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.metadata;
+
+
+/**
+ * Whatever {@link MetadataStandard#asMap MetadataStandard.asMap(…)} shall contain entries
+ * for null values or empty collections. By default the map does not provide
+ * {@linkplain java.util.Map.Entry entries} for {@code null} metadata attributes or
+ * {@linkplain java.util.Collection#isEmpty() empty} collections.
+ * This enumeration allows control on this behavior.
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @since   0.3 (derived from geotk-3.03)
+ * @version 0.3
+ * @module
+ *
+ * @see MetadataStandard#asMap(Object, KeyNamePolicy, NullValuePolicy)
+ */
+public enum NullValuePolicy {
+    /**
+     * Includes all entries in the map, including those having a null value or an
+     * empty collection.
+     */
+    ALL,
+
+    /**
+     * Includes only the non-null attributes.
+     * Collections are included no matter if they are empty or not.
+     */
+    NON_NULL,
+
+    /**
+     * Includes only the attributes that are non-null and, in the case of collections,
+     * non-{@linkplain java.util.Collection#isEmpty() empty}.
+     * This is the default behavior of {@link AbstractMetadata#asMap()}.
+     */
+    NON_EMPTY
+}

Propchange: sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/NullValuePolicy.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/NullValuePolicy.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain;charset=UTF-8

Added: sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/PropertyComparator.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/PropertyComparator.java?rev=1450757&view=auto
==============================================================================
--- sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/PropertyComparator.java
(added)
+++ sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/PropertyComparator.java
[UTF-8] Wed Feb 27 12:30:20 2013
@@ -0,0 +1,86 @@
+/*
+ * 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.metadata;
+
+import java.util.Comparator;
+import java.lang.reflect.Method;
+import net.jcip.annotations.Immutable;
+
+import org.opengis.annotation.UML;
+import org.opengis.annotation.Obligation;
+
+
+/**
+ * The comparator for sorting method order. This comparator puts mandatory methods first,
+ * which is necessary for reducing the risk of ambiguity in {@link PropertyTree#parse}.
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @since   0.3 (derived from geotk-2.4)
+ * @version 0.3
+ * @module
+ */
+@Immutable
+final class PropertyComparator implements Comparator<Method> {
+    /**
+     * The singleton instance.
+     */
+    static final Comparator<Method> INSTANCE = new PropertyComparator();
+
+    /**
+     * Do not allow instantiation of this class, except for the singleton.
+     */
+    private PropertyComparator() {
+    }
+
+    /**
+     * Compares the given methods for order.
+     */
+    @Override
+    public int compare(final Method m1, final Method m2) {
+        final UML a1 = m1.getAnnotation(UML.class);
+        final UML a2 = m2.getAnnotation(UML.class);
+        if (a1 != null) {
+            if (a2 == null) return +1;       // Sort annotated elements first.
+            int c = order(a1) - order(a2);   // Mandatory elements must be first.
+            if (c == 0) {
+                // Fallback on alphabetical order.
+                c = a1.identifier().compareToIgnoreCase(a2.identifier());
+            }
+            return c;
+        } else if (a2 != null) {
+            return -1; // Sort annotated elements first.
+        }
+        // Fallback on alphabetical order.
+        return m1.getName().compareToIgnoreCase(m2.getName());
+    }
+
+    /**
+     * Returns a higher number for obligation which should be first.
+     */
+    private int order(final UML uml) {
+        final Obligation obligation = uml.obligation();
+        if (obligation != null) {
+            switch (obligation) {
+                case MANDATORY:   return 1;
+                case CONDITIONAL: return 2;
+                case OPTIONAL:    return 3;
+                case FORBIDDEN:   return 4;
+            }
+        }
+        return 5;
+    }
+}

Propchange: sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/PropertyComparator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/PropertyComparator.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain;charset=UTF-8

Added: sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/TypeValuePolicy.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/TypeValuePolicy.java?rev=1450757&view=auto
==============================================================================
--- sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/TypeValuePolicy.java
(added)
+++ sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/TypeValuePolicy.java
[UTF-8] Wed Feb 27 12:30:20 2013
@@ -0,0 +1,68 @@
+/*
+ * 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.metadata;
+
+
+/**
+ * Whatever {@link MetadataStandard#asTypeMap MetadataStandard.asTypeMap(…)} shall return
values
+ * for the property types, the element types (same as property types except for collections)
or
+ * the declaring classes.
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @since   0.3 (derived from geotk-3.03)
+ * @version 0.3
+ * @module
+ *
+ * @see MetadataStandard#asTypeMap(Class, KeyNamePolicy, TypeValuePolicy)
+ */
+public enum TypeValuePolicy {
+    /**
+     * The type of a property, as inferred from the
+     * {@linkplain java.lang.reflect.Method#getReturnType() return type} of the property
method.
+     * Collections are not handled in any special way; if the return type is a collection,
then
+     * the value is {@code Collection.class} (or a subclass).
+     */
+    PROPERTY_TYPE,
+
+    /**
+     * The type of a property, or type of elements if the property is a collection. This
is the
+     * same than {@link #PROPERTY_TYPE} except that collections are handled in a special
way:
+     * if the property is a collection, then the value is the type of <em>elements</em>
in that
+     * collection.
+     *
+     * {@note Current implementation has an additional slight difference: if the getter method
+     *        in the implementation class declares a more specific return value than the
getter
+     *        method in the interface, and if the setter method (if any) expects the same
specialized
+     *        type, then <code>ELEMENT_TYPE</code> will use that specialized
type. This is different
+     *        than <code>PROPERTY_TYPE</code> which always use the type declared
in the interface.}
+     */
+    ELEMENT_TYPE,
+
+    /**
+     * The type of the class that declares the method. A metadata implementation may have
+     * different declaring classes for its properties if some of them are declared in parent
+     * classes.
+     */
+    DECLARING_CLASS,
+
+    /**
+     * The type of the interface that declares the method. This is the same than
+     * {@link #DECLARING_CLASS}, except that the interface from the metadata standard
+     * is returned instead than the implementation class.
+     */
+    DECLARING_INTERFACE
+}

Propchange: sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/TypeValuePolicy.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/TypeValuePolicy.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain;charset=UTF-8



Mime
View raw message