You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sis.apache.org by de...@apache.org on 2013/06/21 13:35:51 UTC
svn commit: r1495393 - in /sis/branches/JDK7/core:
sis-metadata/src/main/java/org/apache/sis/internal/jaxb/code/
sis-utility/src/main/java/org/apache/sis/internal/jaxb/
sis-utility/src/main/java/org/apache/sis/internal/jaxb/gmd/
sis-utility/src/main/ja...
Author: desruisseaux
Date: Fri Jun 21 11:35:51 2013
New Revision: 1495393
URL: http://svn.apache.org/r1495393
Log:
Use the WarningListener mechanism provided in the previous commit for reporting parsing errors.
Modified:
sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/code/PT_Locale.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/IdentifierMapAdapter.java
sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/IdentifierMapWithSpecialCases.java
sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/NonMarshalledAuthority.java
sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/SpecializedIdentifier.java
sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gmd/CodeListProxy.java
sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/logging/Logging.java
Modified: sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/code/PT_Locale.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/code/PT_Locale.java?rev=1495393&r1=1495392&r2=1495393&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/code/PT_Locale.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/code/PT_Locale.java [UTF-8] Fri Jun 21 11:35:51 2013
@@ -24,7 +24,6 @@ import javax.xml.bind.annotation.XmlElem
import javax.xml.bind.annotation.adapters.XmlAdapter;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import org.opengis.metadata.identification.CharacterSet;
-import org.apache.sis.util.logging.Logging;
import org.apache.sis.util.Locales;
import org.apache.sis.util.iso.Types;
import org.apache.sis.internal.jaxb.Context;
@@ -136,7 +135,7 @@ public final class PT_Locale extends Xml
} catch (PropertyException | ClassCastException e) {
// Should never happen. But if it happen anyway, just let the
// characterEncoding unitialized: it will not be marshalled.
- Logging.unexpectedException(PT_Locale.class, "beforeMarshal", e);
+ Context.warningOccured(Context.current(), marshaller, PT_Locale.class, "beforeMarshal", e, true);
return;
}
if (encoding != null) {
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=1495393&r1=1495392&r2=1495393&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] Fri Jun 21 11:35:51 2013
@@ -19,8 +19,10 @@ package org.apache.sis.internal.jaxb;
import java.util.Map;
import java.util.Locale;
import java.util.TimeZone;
+import java.util.logging.Level;
import java.util.logging.LogRecord;
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.xml.MarshalContext;
@@ -348,16 +350,20 @@ public final class Context extends Marsh
}
/**
- * Sends the given warning to the warning listener if there is one, or log the warning otherwise.
- * The {@link LogRecord#getLoggerName()} <strong>must</strong> be set to the proper logger name,
- * because this method relies on that information for fetching the logger.
+ * Sends the given warning to the warning listener if there is one, or logs the warning otherwise.
+ * In the later case, this method logs to the logger specified by {@link LogRecord#getLoggerName()}
+ * if defined, or to the {@code "org.apache.sis.xml"} logger otherwise.
*
* @param context The current context, or {@code null} if none.
- * @param source The object that emit a warning. Can not be null.
+ * @param source The object that emitted a warning. Can not be null.
* @param warning The warning.
*/
@SuppressWarnings("unchecked")
public static void warningOccured(final Context context, final Object source, final LogRecord warning) {
+ String logger = warning.getLoggerName();
+ if (logger == null) {
+ warning.setLoggerName(logger = "org.apache.sis.xml");
+ }
if (context != null) {
final WarningListener<?> warningListener = context.warningListener;
if (warningListener != null && warningListener.getSourceClass().isInstance(source)) {
@@ -365,7 +371,34 @@ public final class Context extends Marsh
return;
}
}
- Logging.getLogger(warning.getLoggerName()).log(warning);
+ /*
+ * Log the warning without stack-trace, since this method shall be used only for non-fatal warnings
+ * and we want to avoid polluting the logs.
+ */
+ warning.setThrown(null);
+ Logging.getLogger(logger).log(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 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}.
+ */
+ public static void warningOccured(final Context context, final Object source, final Class<?> classe,
+ final String method, final Exception cause, final boolean warning)
+ {
+ final LogRecord record = new LogRecord(warning ? Level.WARNING : Level.FINE,
+ Exceptions.formatChainedMessages(context != null ? context.getLocale() : null, null, cause));
+ record.setSourceClassName(classe.getCanonicalName());
+ record.setSourceMethodName(method);
+ record.setThrown(cause);
+ warningOccured(context, source, record);
}
/**
Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/IdentifierMapAdapter.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/IdentifierMapAdapter.java?rev=1495393&r1=1495392&r2=1495393&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/IdentifierMapAdapter.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/IdentifierMapAdapter.java [UTF-8] Fri Jun 21 11:35:51 2013
@@ -273,7 +273,7 @@ public class IdentifierMapAdapter extend
}
}
if (code != null) {
- identifiers.add(SpecializedIdentifier.parse(authority, code));
+ identifiers.add(SpecializedIdentifier.parse(this, authority, code));
}
return old;
}
Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/IdentifierMapWithSpecialCases.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/IdentifierMapWithSpecialCases.java?rev=1495393&r1=1495392&r2=1495393&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/IdentifierMapWithSpecialCases.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/IdentifierMapWithSpecialCases.java [UTF-8] Fri Jun 21 11:35:51 2013
@@ -198,7 +198,7 @@ public final class IdentifierMapWithSpec
return (id != null) ? id.toString() : old;
}
}
- SpecializedIdentifier.parseFailure(exception);
+ SpecializedIdentifier.parseFailure(this, exception);
return super.put(authority, code);
}
Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/NonMarshalledAuthority.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/NonMarshalledAuthority.java?rev=1495393&r1=1495392&r2=1495393&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/NonMarshalledAuthority.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/NonMarshalledAuthority.java [UTF-8] Fri Jun 21 11:35:51 2013
@@ -283,6 +283,10 @@ public final class NonMarshalledAuthorit
warningLogged = true;
final LogRecord record = Errors.getResources(null).getLogRecord(Level.WARNING,
Errors.Keys.MissingRequiredModule_1, "sis-metadata");
+ /*
+ * Log directly the the logger rather than invoking the Context.warningOccured(…) method because
+ * this warning does not occur during XML (un)marshalling. It may occurs only during serialization.
+ */
record.setThrown(e);
Logging.log(NonMarshalledAuthority.class, "readResolve", record);
}
Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/SpecializedIdentifier.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/SpecializedIdentifier.java?rev=1495393&r1=1495392&r2=1495393&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/SpecializedIdentifier.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/SpecializedIdentifier.java [UTF-8] Fri Jun 21 11:35:51 2013
@@ -26,7 +26,6 @@ import org.apache.sis.xml.XLink;
import org.apache.sis.xml.IdentifierMap;
import org.apache.sis.xml.IdentifierSpace;
import org.apache.sis.util.Debug;
-import org.apache.sis.util.logging.Logging;
import org.apache.sis.internal.util.Citations;
// Related to JDK7
@@ -89,12 +88,13 @@ public final class SpecializedIdentifier
* authorities declared in the {@link IdentifierSpace} interface. Otherwise a
* plain {@link IdentifierMapEntry} is created.
*
+ * @param source The object to declare as the source in case of failure.
* @param authority The authority, typically as one of the {@link IdentifierSpace} constants.
- * @param code The identifier code to parse.
+ * @param code The identifier code to parse.
*
* @see IdentifierMapAdapter#put(Citation, String)
*/
- static Identifier parse(final Citation authority, final String code) {
+ static Identifier parse(final IdentifierMap source, final Citation authority, final String code) {
if (authority instanceof NonMarshalledAuthority) {
switch (((NonMarshalledAuthority) authority).ordinal) {
case NonMarshalledAuthority.ID: {
@@ -104,7 +104,7 @@ public final class SpecializedIdentifier
try {
return new SpecializedIdentifier<>(IdentifierSpace.UUID, UUID.fromString(code));
} catch (IllegalArgumentException e) {
- parseFailure(e);
+ parseFailure(source, e);
break;
}
}
@@ -113,7 +113,7 @@ public final class SpecializedIdentifier
try {
href = new URI(code);
} catch (URISyntaxException e) {
- parseFailure(e);
+ parseFailure(source, e);
break;
}
return new SpecializedIdentifier<>(IdentifierSpace.HREF, href);
@@ -123,7 +123,7 @@ public final class SpecializedIdentifier
try {
href = new URI(code);
} catch (URISyntaxException e) {
- parseFailure(e);
+ parseFailure(source, e);
break;
}
final XLink xlink = new XLink();
@@ -140,13 +140,15 @@ public final class SpecializedIdentifier
* This is considered a non-fatal error, because the parse method can fallback
* on the generic {@link IdentifierMapEntry} in such cases.
*/
- static void parseFailure(final Exception e) {
+ static void parseFailure(final IdentifierMap source, final Exception e) {
// IdentifierMap.put(Citation,String) is the public facade.
- Logging.recoverableException(IdentifierMap.class, "put", e);
+ Context.warningOccured(Context.current(), source, IdentifierMap.class, "put", e, true);
}
/**
* Returns the authority specified at construction time.
+ *
+ * @return The identifier authority.
*/
@Override
public Citation getAuthority() {
@@ -166,6 +168,8 @@ public final class SpecializedIdentifier
/**
* Returns a string representation of the {@linkplain #getValue() identifier value},
* or {@code null} if none.
+ *
+ * @return The identifier value.
*/
@Override
public String getCode() {
Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gmd/CodeListProxy.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gmd/CodeListProxy.java?rev=1495393&r1=1495392&r2=1495393&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gmd/CodeListProxy.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gmd/CodeListProxy.java [UTF-8] Fri Jun 21 11:35:51 2013
@@ -24,7 +24,6 @@ import javax.xml.bind.annotation.XmlType
import javax.xml.bind.annotation.XmlValue;
import org.opengis.util.CodeList;
import org.apache.sis.util.iso.Types;
-import org.apache.sis.util.logging.Logging;
import org.apache.sis.internal.jaxb.Context;
@@ -183,7 +182,7 @@ public final class CodeListProxy {
value = ResourceBundle.getBundle("org.opengis.metadata.CodeLists",
locale, CodeList.class.getClassLoader()).getString(key);
} catch (MissingResourceException e) {
- Logging.recoverableException(CodeListAdapter.class, "marshal", e);
+ Context.warningOccured(context, code, CodeListAdapter.class, "marshal", e, false);
}
}
if (value != null) {
Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/logging/Logging.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/logging/Logging.java?rev=1495393&r1=1495392&r2=1495393&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/logging/Logging.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/logging/Logging.java [UTF-8] Fri Jun 21 11:35:51 2013
@@ -52,6 +52,18 @@ import org.apache.sis.util.Classes;
*/
public final class Logging extends Static {
/**
+ * The threshold at which {@link #unexpectedException(Logger, String, String, Throwable, Level)} shall
+ * set the throwable in the {@link LogRecord}. For any record to be logged at a lower {@link Level},
+ * the {@link LogRecord#setThrown(Throwable)} method will not be invoked.
+ *
+ * <p>The default value is 600, which is the {@link PerformanceLevel#PERFORMANCE} value.
+ * This value is between {@link Level#FINE} (500) and {@link Level#CONFIG} (700).
+ * Consequently we will ignore the stack traces of recoverable failures, but will report
+ * stack traces that may impact performance, configuration, or correctness.</p>
+ */
+ private static final int LEVEL_THRESHOLD_FOR_STACKTRACE = 600;
+
+ /**
* The factory for obtaining {@link Logger} instances, or {@code null} if none.
* If {@code null} (the default), then the standard JDK logging framework will be used.
* {@code Logging} scans the classpath for logger factories on class initialization.
@@ -383,7 +395,7 @@ public final class Logging extends Stati
if (method != null) {
record.setSourceMethodName(method);
}
- if (level.intValue() > 500) {
+ if (level.intValue() >= LEVEL_THRESHOLD_FOR_STACKTRACE) {
record.setThrown(error);
}
record.setLoggerName(logger.getName());