sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1528414 - in /sis/branches/JDK7/core: sis-metadata/src/main/java/org/apache/sis/internal/jaxb/gml/ sis-referencing/src/main/java/org/apache/sis/referencing/datum/ sis-utility/src/main/java/org/apache/sis/internal/jaxb/ sis-utility/src/main...
Date Wed, 02 Oct 2013 10:34:59 GMT
Author: desruisseaux
Date: Wed Oct  2 10:34:58 2013
New Revision: 1528414

URL: http://svn.apache.org/r1528414
Log:
Added a convenience 'warningOccured' internal method for a pattern which happen to occurs
often in practice.

Modified:
    sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/gml/SC_VerticalCRS.java
    sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/gml/TM_Primitive.java
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultEllipsoid.java
    sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/Context.java
    sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_CharacterString.java
    sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/Measure.java
    sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/ObjectReference.java
    sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/util/CheckedArrayList.java

Modified: sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/gml/SC_VerticalCRS.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/gml/SC_VerticalCRS.java?rev=1528414&r1=1528413&r2=1528414&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/gml/SC_VerticalCRS.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/gml/SC_VerticalCRS.java
[UTF-8] Wed Oct  2 10:34:58 2013
@@ -16,8 +16,6 @@
  */
 package org.apache.sis.internal.jaxb.gml;
 
-import java.util.logging.Level;
-import java.util.logging.LogRecord;
 import javax.xml.bind.annotation.XmlAnyElement;
 import org.opengis.referencing.crs.VerticalCRS;
 import org.apache.sis.internal.jaxb.gco.PropertyType;
@@ -116,12 +114,8 @@ public class SC_VerticalCRS extends Prop
      */
     @XmlAnyElement(lax = true)
     public Object getElement() {
-        final LogRecord record = Errors.getResources(null).getLogRecord(Level.WARNING,
-                Errors.Keys.MissingRequiredModule_1, "sis-referencing");
-        record.setSourceClassName(SC_VerticalCRS.class.getName());
-        record.setSourceMethodName("getElement");
-        final Context context = Context.current();
-        Context.warningOccured(context, metadata, record);
+        Context.warningOccured(Context.current(), metadata, SC_VerticalCRS.class, "getElement",
+                Errors.class, Errors.Keys.MissingRequiredModule_1, "sis-referencing");
         return null;
     }
 

Modified: sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/gml/TM_Primitive.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/gml/TM_Primitive.java?rev=1528414&r1=1528413&r2=1528414&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/gml/TM_Primitive.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/gml/TM_Primitive.java
[UTF-8] Wed Oct  2 10:34:58 2013
@@ -17,8 +17,6 @@
 package org.apache.sis.internal.jaxb.gml;
 
 import java.util.Date;
-import java.util.logging.Level;
-import java.util.logging.LogRecord;
 import javax.xml.bind.annotation.XmlElement;
 import org.opengis.temporal.Period;
 import org.opengis.temporal.Instant;
@@ -128,12 +126,8 @@ public final class TM_Primitive extends 
                      * TemporalPrimitive as the source class, since it is the closest we
can get
                      * to a public API.
                      */
-                    final Context context = Context.current();
-                    final LogRecord record = Errors.getResources(context != null ? context.getLocale()
: null)
-                            .getLogRecord(Level.WARNING, Errors.Keys.IllegalRange_2, begin,
end);
-                    record.setSourceClassName(TemporalPrimitive.class.getName());
-                    record.setSourceMethodName("setTimePeriod");
-                    Context.warningOccured(context, this, record);
+                    Context.warningOccured(Context.current(), this, TemporalPrimitive.class,
"setTimePeriod",
+                            Errors.class, Errors.Keys.IllegalRange_2, begin, end);
                 } else try {
                     metadata = TemporalUtilities.createPeriod(begin, end);
                     period.copyIdTo(metadata);

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultEllipsoid.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultEllipsoid.java?rev=1528414&r1=1528413&r2=1528414&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultEllipsoid.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultEllipsoid.java
[UTF-8] Wed Oct  2 10:34:58 2013
@@ -19,8 +19,6 @@ package org.apache.sis.referencing.datum
 import java.util.Map;
 import java.util.HashMap;
 import java.util.Collections;
-import java.util.logging.Level;
-import java.util.logging.LogRecord;
 import javax.measure.unit.SI;
 import javax.measure.unit.Unit;
 import javax.measure.quantity.Length;
@@ -570,11 +568,9 @@ public class DefaultEllipsoid extends Ab
      * Emits a warning telling that the given element is repeated twice.
      */
     private void warnDuplicated(final String element) {
-        final LogRecord record = Errors.getResources(null)
-                .getLogRecord(Level.WARNING, Errors.Keys.DuplicatedElement_1, element);
-        record.setSourceClassName(DefaultEllipsoid.class.getName());
-        record.setSourceMethodName("unmarshal"); // We cheat a bit since there is not such
method...
-        Context.warningOccured(Context.current(), this, record);
+         // We cheat a bit for the "unmarshal" method name since there is not such method...
+        Context.warningOccured(Context.current(), this, DefaultEllipsoid.class, "unmarshal",
+                Errors.class, Errors.Keys.DuplicatedElement_1, element);
     }
 
     /**

Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/Context.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/Context.java?rev=1528414&r1=1528413&r2=1528414&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/Context.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/Context.java
[UTF-8] Wed Oct  2 10:34:58 2013
@@ -25,6 +25,9 @@ import org.apache.sis.util.Version;
 import org.apache.sis.util.Exceptions;
 import org.apache.sis.util.logging.Logging;
 import org.apache.sis.util.logging.WarningListener;
+import org.apache.sis.util.resources.Errors;
+import org.apache.sis.util.resources.Messages;
+import org.apache.sis.util.resources.IndexedResourceBundle;
 import org.apache.sis.xml.MarshalContext;
 import org.apache.sis.xml.ValueConverter;
 import org.apache.sis.xml.ReferenceResolver;
@@ -401,12 +404,42 @@ public final class Context extends Marsh
     }
 
     /**
+     * Convenience method for sending a warning for the given message from the {@link Errors}
or {@link Messages}
+     * resources. The message will be logged at {@link Level#WARNING}.
+     *
+     * @param context   The current context, or {@code null} if none.
+     * @param source    The object that emitted a warning. Can not be null.
+     * @param classe    The class to declare as the warning source.
+     * @param method    The name of the method to declare as the warning source.
+     * @param resources Either {@code Errors.class} or {@code Messages.class}.
+     * @param key       The resource keys as one of the constants defined in the {@code Keys}
inner class.
+     * @param arguments The arguments to be given to {@code MessageFormat} for formatting
the log message.
+     */
+    public static void warningOccured(final Context context, final Object source, final Class<?>
classe, final String method,
+            final Class<? extends IndexedResourceBundle> resources, final int key,
final Object... arguments)
+    {
+        final Locale locale = context != null ? context.getLocale() : null;
+        final IndexedResourceBundle bundle;
+        if (resources == Errors.class) {
+            bundle = Errors.getResources(locale);
+        } else if (resources == Messages.class) {
+            bundle = Messages.getResources(locale);
+        } else {
+            throw new IllegalArgumentException(String.valueOf(resources));
+        }
+        final LogRecord warning = bundle.getLogRecord(Level.WARNING, key, arguments);
+        warning.setSourceClassName(classe.getCanonicalName());
+        warning.setSourceMethodName(method);
+        warningOccured(context, source, warning);
+    }
+
+    /**
      * Convenience method for sending a warning for the given exception.
      * The logger will be {@code "org.apache.sis.xml"}.
      *
      * @param context The current context, or {@code null} if none.
      * @param source  The object that emitted a warning. Can not be null.
-     * @param classe  The name of the class to declare as the warning source.
+     * @param classe  The class to declare as the warning source.
      * @param method  The name of the method to declare as the warning source.
      * @param cause   The exception which occurred.
      * @param warning {@code true} for {@link Level#WARNING}, or {@code false} for {@link
Level#FILE}.

Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_CharacterString.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_CharacterString.java?rev=1528414&r1=1528413&r2=1528414&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_CharacterString.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_CharacterString.java
[UTF-8] Wed Oct  2 10:34:58 2013
@@ -16,8 +16,6 @@
  */
 package org.apache.sis.internal.jaxb.gco;
 
-import java.util.logging.Level;
-import java.util.logging.LogRecord;
 import javax.xml.bind.annotation.XmlType;
 import javax.xml.bind.annotation.XmlElement;
 import javax.xml.bind.annotation.XmlSeeAlso;
@@ -137,13 +135,8 @@ public class GO_CharacterString {
                 property  = type;
                 noset     = true;
             }
-            final Context context = Context.current();
-            final LogRecord record = Messages.getResources(context != null ? context.getLocale()
: null)
-                    .getLogRecord(Level.WARNING, Messages.Keys.DiscardedExclusiveProperty_2,
-                                  NAMES[discarded], NAMES[property]);
-            record.setSourceClassName(getClass().getCanonicalName());
-            record.setSourceMethodName("setText");
-            Context.warningOccured(context, value, record);
+            Context.warningOccured(Context.current(), value, getClass(), "setText",
+                    Messages.class, Messages.Keys.DiscardedExclusiveProperty_2, NAMES[discarded],
NAMES[property]);
             if (noset) {
                 return;
             }

Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/Measure.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/Measure.java?rev=1528414&r1=1528413&r2=1528414&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/Measure.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/Measure.java
[UTF-8] Wed Oct  2 10:34:58 2013
@@ -19,8 +19,6 @@ package org.apache.sis.internal.jaxb.gco
 import java.io.File;
 import java.net.URI;
 import java.net.URISyntaxException;
-import java.util.logging.Level;
-import java.util.logging.LogRecord;
 import javax.measure.unit.Unit;
 import javax.measure.unit.NonSI;
 import javax.xml.bind.annotation.XmlValue;
@@ -165,11 +163,8 @@ public final class Measure {
      */
     public void setUnit(final Unit<?> newUnit) {
         if (unit != null && !unit.equals(newUnit)) {
-            final LogRecord record = Errors.getResources(null)
-                    .getLogRecord(Level.WARNING, Errors.Keys.IncompatiblePropertyValue_1,
unit);
-            record.setSourceClassName(getClass().getName());
-            record.setSourceMethodName("setUnit");
-            Context.warningOccured(Context.current(), this, record);
+            Context.warningOccured(Context.current(), this, getClass(), "setUnit",
+                    Errors.class, Errors.Keys.IncompatiblePropertyValue_1, unit);
         }
         unit = newUnit;
     }

Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/ObjectReference.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/ObjectReference.java?rev=1528414&r1=1528413&r2=1528414&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/ObjectReference.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/ObjectReference.java
[UTF-8] Wed Oct  2 10:34:58 2013
@@ -17,8 +17,6 @@
 package org.apache.sis.internal.jaxb.gco;
 
 import java.util.UUID;
-import java.util.logging.Level;
-import java.util.logging.LogRecord;
 import org.apache.sis.xml.XLink;
 import org.apache.sis.xml.IdentifierMap;
 import org.apache.sis.xml.IdentifierSpace;
@@ -150,11 +148,8 @@ final class ObjectReference {
         if (value != null) {
             final T previous = map.putSpecialized(authority, value);
             if (previous != null && !previous.equals(value)) {
-                final LogRecord record = Errors.getResources((context != null) ? context.getLocale()
: null)
-                        .getLogRecord(Level.WARNING, Errors.Keys.InconsistentAttribute_2,
authority.getName(), value);
-                record.setSourceClassName(IdentifierMap.class.getName());
-                record.setSourceMethodName("putSpecialized");
-                Context.warningOccured(context, map, record);
+                Context.warningOccured(context, map, IdentifierMap.class, "putSpecialized",
+                        Errors.class, Errors.Keys.InconsistentAttribute_2, authority.getName(),
value);
                 map.putSpecialized(authority, previous);
             }
         }

Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/util/CheckedArrayList.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/util/CheckedArrayList.java?rev=1528414&r1=1528413&r2=1528414&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/util/CheckedArrayList.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/util/CheckedArrayList.java
[UTF-8] Wed Oct  2 10:34:58 2013
@@ -21,8 +21,6 @@ import java.util.AbstractList;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
-import java.util.logging.Level;
-import java.util.logging.LogRecord;
 import org.apache.sis.internal.jaxb.Context;
 import org.apache.sis.util.ArraysExt;
 import org.apache.sis.util.resources.Errors;
@@ -106,11 +104,8 @@ public final class CheckedArrayList<E> e
             return false;
         }
         if (element != null) {
-            final LogRecord record = Errors.getResources(context.getLocale()).getLogRecord(Level.WARNING,
-                    Errors.Keys.IllegalArgumentClass_3, "element", type, element.getClass());
-            record.setSourceClassName(source.getClass().getName());
-            record.setSourceMethodName("add");
-            Context.warningOccured(context, source, record);
+            Context.warningOccured(context, source, source.getClass(), "add",
+                    Errors.class, Errors.Keys.IllegalArgumentClass_3, "element", type, element.getClass());
         }
         return true;
     }



Mime
View raw message