sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1406200 - in /sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis: internal/util/ util/resources/
Date Tue, 06 Nov 2012 16:10:55 GMT
Author: desruisseaux
Date: Tue Nov  6 16:10:55 2012
New Revision: 1406200

URL: http://svn.apache.org/viewvc?rev=1406200&view=rev
Log:
Added pre-defined TableColumn constants for internal usage (more will be added later).

Added:
    sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/util/ColumnConstant.java
  (with props)
    sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Vocabulary.java
  (with props)
    sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Vocabulary.properties
  (with props)
    sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Vocabulary_fr.properties
  (with props)
Modified:
    sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/util/package-info.java

Added: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/util/ColumnConstant.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/util/ColumnConstant.java?rev=1406200&view=auto
==============================================================================
--- sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/util/ColumnConstant.java
(added)
+++ sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/util/ColumnConstant.java
Tue Nov  6 16:10:55 2012
@@ -0,0 +1,118 @@
+/*
+ * 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.internal.util;
+
+import java.io.Serializable;
+import java.io.InvalidObjectException;
+import org.opengis.util.InternationalString;
+import org.apache.sis.util.resources.Vocabulary;
+import org.apache.sis.util.collection.TableColumn;
+
+
+/**
+ * {@link TableColumn} constants used in the SIS library.
+ *
+ * @param <T> Base type of all values in the column identified by this instance.
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @since   0.3
+ * @version 0.3
+ * @module
+ */
+public final class ColumnConstant<T> implements TableColumn<T>, Serializable
{
+    /**
+     * For cross-version compatibility.
+     */
+    private static final long serialVersionUID = -8638750288322500203L;
+
+    /**
+     * Frequently-used constant for a column of object names.
+     * The values are typically instances of {@link String} or
+     * {@link org.opengis.util.InternationalString}, depending
+     * if the data provide localization support or not.
+     */
+    public static final TableColumn<CharSequence> NAME = new ColumnConstant<>("NAME",
+            CharSequence.class, Vocabulary.Keys.Name);
+
+    /**
+     * Frequently-used constant for a column of object types.
+     * The values are instances of {@link Class}.
+     */
+    @SuppressWarnings("unchecked")
+    public static final TableColumn<Class<?>> TYPE = new ColumnConstant<>("TYPE",
+            (Class) Class.class, Vocabulary.Keys.Type);
+
+    /**
+     * The programmatic name of the static final field holding this constant.
+     */
+    private final String name;
+
+    /**
+     * Base type of all values in the column identified by this {@code ColumnConstant} instance.
+     */
+    private final transient Class<T> type;
+
+    /**
+     * The resource key for the column header.
+     */
+    private final transient int resourceKey;
+
+    /**
+     * Creates a new instance for the given type of values.
+     *
+     * @param name The programmatic name of the static final field holding this constant.
+     * @param type Base type of all values in the column identified by this instance.
+     * @param resourceKey The resource key for the column header.
+     */
+    private ColumnConstant(final String name, final Class<T> type, final int resourceKey)
{
+        this.name        = name;
+        this.type        = type;
+        this.resourceKey = resourceKey;
+    }
+
+    /**
+     * Returns the text to display as column header.
+     */
+    @Override
+    public InternationalString getHeader() {
+        return Vocabulary.formatInternational(resourceKey);
+    }
+
+    /**
+     * Returns the base type of all values in any column identified by this {@code TableConstant}.
+     */
+    @Override
+    public final Class<T> getElementType() {
+        return type;
+    }
+
+    /**
+     * Invoked on deserialization for resolving this instance to one of the predefined constants.
+     *
+     * @return One of the predefined constants.
+     * @throws InvalidObjectException If this instance can not be resolved.
+     */
+    protected Object readResolve() throws InvalidObjectException {
+        try {
+            return getClass().getField(name).get(null);
+        } catch (Exception cause) { // Many exceptions, including unchecked ones.
+            InvalidObjectException e = new InvalidObjectException(cause.toString());
+            e.initCause(cause);
+            throw e;
+        }
+    }
+}

Propchange: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/util/ColumnConstant.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/util/ColumnConstant.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/util/package-info.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/util/package-info.java?rev=1406200&r1=1406199&r2=1406200&view=diff
==============================================================================
--- sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/util/package-info.java
(original)
+++ sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/util/package-info.java
Tue Nov  6 16:10:55 2012
@@ -23,6 +23,12 @@
  * This package is for internal use by SIS only. Classes in this package
  * may change in incompatible ways in any future version without notice.
  *
+ * {@section Note on serialization}
+ * Developers should avoid putting serializable classes in this package as much as possible,
+ * since the serialization forms may be considered as a kind of API contract (depending how
+ * much strict we want to be regarding compatibility). This is not always practical however,
+ * so some serialized classes still exist in this package.
+ *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.3 (derived from geotk-2.0)
  * @version 0.3

Added: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Vocabulary.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Vocabulary.java?rev=1406200&view=auto
==============================================================================
--- sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Vocabulary.java
(added)
+++ sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Vocabulary.java
Tue Nov  6 16:10:55 2012
@@ -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.util.resources;
+
+import java.util.Locale;
+import java.util.MissingResourceException;
+import org.opengis.util.InternationalString;
+
+
+/**
+ * Locale-dependent resources for single words or short sentences.
+ *
+ * @author  Martin Desruisseaux (IRD, Geomatys)
+ * @since   0.3 (derived from geotk-2.2)
+ * @version 0.3
+ * @module
+ */
+public final class Vocabulary extends IndexedResourceBundle {
+    /**
+     * Resource keys. This class is used when compiling sources, but no dependencies to
+     * {@code Keys} should appear in any resulting class files. Since the Java compiler
+     * inlines final integer values, using long identifiers will not bloat the constant
+     * pools of compiled classes.
+     *
+     * @author  Martin Desruisseaux (IRD, Geomatys)
+     * @since   0.3 (derived from geotk-2.2)
+     * @version 0.3
+     * @module
+     */
+    public static final class Keys {
+        private Keys() {
+        }
+
+        /**
+         * Name
+         */
+        public static final int Name = 0;
+
+        /**
+         * Type
+         */
+        public static final int Type = 1;
+    }
+
+    /**
+     * Constructs a new resource bundle loading data from the given UTF file.
+     *
+     * @param filename The file or the JAR entry containing resources.
+     */
+    Vocabulary(final String filename) {
+        super(filename);
+    }
+
+    /**
+     * Returns the {@code Keys} class.
+     */
+    @Override
+    final Class<?> getKeysClass() throws ClassNotFoundException {
+        assert super.getKeysClass() == Keys.class;
+        return Keys.class;
+    }
+
+    /**
+     * Returns resources in the given locale.
+     *
+     * @param  locale The locale, or {@code null} for the default locale.
+     * @return Resources in the given locale.
+     * @throws MissingResourceException if resources can't be found.
+     */
+    public static Messages getResources(final Locale locale) throws MissingResourceException
{
+        return getBundle(Messages.class, locale);
+    }
+
+    /**
+     * Gets a string for the given key from this resource bundle or one of its parents.
+     *
+     * @param  key The key for the desired string.
+     * @return The string for the given key.
+     * @throws MissingResourceException If no object for the given key can be found.
+     */
+    public static String format(final int key) throws MissingResourceException {
+        return getResources(null).getString(key);
+    }
+
+    /**
+     * The international string to be returned by {@link formatInternational}.
+     */
+    private static final class International extends ResourceInternationalString {
+        private static final long serialVersionUID = 8360132666298806838L;
+
+        International(int key)              {super(key);}
+        International(int key, Object args) {super(key, args);}
+        @Override IndexedResourceBundle getBundle(Locale locale) {
+            return getResources(locale);
+        }
+    }
+
+    /**
+     * Gets an international string for the given key. This method does not check for the
key
+     * validity. If the key is invalid, then a {@link MissingResourceException} may be thrown
+     * when a {@link InternationalString#toString(Locale)} method is invoked.
+     *
+     * @param  key The key for the desired string.
+     * @return An international string for the given key.
+     */
+    public static InternationalString formatInternational(final int key) {
+        return new International(key);
+    }
+}

Propchange: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Vocabulary.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Vocabulary.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Vocabulary.properties
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Vocabulary.properties?rev=1406200&view=auto
==============================================================================
--- sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Vocabulary.properties
(added)
+++ sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Vocabulary.properties
Tue Nov  6 16:10:55 2012
@@ -0,0 +1,18 @@
+#
+# 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.
+#
+Name        = Name
+Type        = Type

Propchange: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Vocabulary.properties
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Vocabulary.properties
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Vocabulary_fr.properties
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Vocabulary_fr.properties?rev=1406200&view=auto
==============================================================================
--- sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Vocabulary_fr.properties
(added)
+++ sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Vocabulary_fr.properties
Tue Nov  6 16:10:55 2012
@@ -0,0 +1,18 @@
+#
+# 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.
+#
+Name        = Nom
+Type        = Type

Propchange: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Vocabulary_fr.properties
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Vocabulary_fr.properties
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message