本文整理了Java中org.apache.sis.util.logging.WarningListeners
类的一些代码示例,展示了WarningListeners
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WarningListeners
类的具体详情如下:
包路径:org.apache.sis.util.logging.WarningListeners
类名称:WarningListeners
[英]Holds a list of WarningListener instances and provides convenience methods for emitting warnings. This is a helper class for org.apache.sis.storage.DataStore implementations or for other services susceptible to emit warnings. Observers can #addWarningListener for being notified about warnings, and processes can invoke one of the warning(…) methods for emitting warnings. All warnings are given to the listeners as LogRecord instances (this allows localizable messages and additional information like LogRecord#getMillis() and LogRecord#getThrown()). This WarningListeners class provides convenience methods like #warning(String,Exception), which builds LogRecord from an exception or from a string, but all those warning(…) methods ultimately delegate to #warning(LogRecord), thus providing a single point that subclasses can override. When a warning is emitted, the default behavior is:
代码示例来源:origin: apache/sis
/**
* Reports a warning represented by the given message and exception.
* At least one of {@code message} and {@code exception} shall be non-null.
*
* @param message the message to log, or {@code null} if none.
* @param exception the exception to log, or {@code null} if none.
*/
final void warning(final String message, final Exception exception) {
listeners.warning(message, exception);
}
代码示例来源:origin: apache/sis
/**
* Logs a warning using the localized error resource bundle for the locale given by
* {@link WarningListeners#getLocale()}.
*
* @param key one of {@link Errors.Keys} values.
*/
private void warning(final short key, final Object p1, final Object p2, final Exception e) {
final WarningListeners<DataStore> listeners = decoder.listeners;
listeners.warning(Errors.getResources(listeners.getLocale()).getString(key, p1, p2), e);
}
代码示例来源:origin: org.apache.sis.storage/sis-storage
/**
* Creates a new instance with no provider and initially no listener.
*/
protected DataStore() {
provider = null;
name = null;
locale = Locale.getDefault(Locale.Category.DISPLAY);
listeners = new WarningListeners<>(this);
}
代码示例来源:origin: org.apache.sis.storage/sis-storage
/**
* Reports a warning in the {@code "org.apache.sis.io.wkt"} logger. This method pretends that the
* warning come from {@code getMetadata()} method, which is the public facade for the parsing method.
*
* @param record the warning to report.
*/
private void log(final LogRecord record) {
record.setSourceClassName(listeners.getSource().getClass().getName());
record.setSourceMethodName("getMetadata");
record.setLoggerName(Loggers.WKT);
listeners.warning(record);
}
}
代码示例来源:origin: apache/sis
/**
* Tests {@link WarningListeners#warning(String, Exception)} with a registered listener.
*/
@Test
@DependsOnMethod("testAddAndRemoveWarningListener")
public void testWarning() {
listeners.addWarningListener(this);
listeners.warning("The message", null);
listeners.removeWarningListener(this);
assertNotNull("Listener has not been notified.", warning);
assertEquals(getClass().getName(), warning.getSourceClassName());
assertEquals("testWarning", warning.getSourceMethodName());
assertEquals("The message", warning.getMessage());
}
}
代码示例来源:origin: org.apache.sis.core/sis-utility
if (exception != null) {
trace = exception.getStackTrace();
message = Exceptions.formatChainedMessages(getLocale(), message, exception);
if (message == null) {
message = exception.toString();
if (isPublic(e)) {
record.setSourceClassName(e.getClassName());
record.setSourceMethodName(e.getMethodName());
warning(record);
代码示例来源:origin: org.apache.sis.storage/sis-storage
/**
* Returns the locale for error messages or warnings.
* Returns {@code null} if no locale is explicitly defined.
*
* @return the locale, or {@code null} if not explicitly defined.
*/
@Override
public final Locale getLocale() {
return (listeners != null) ? listeners.getLocale() : null;
}
代码示例来源:origin: apache/sis
/**
* Tests {@link WarningListeners#addWarningListener(WarningListener)} followed by
* {@link WarningListeners#removeWarningListener(WarningListener)}
*/
@Test
public void testAddAndRemoveWarningListener() {
listeners.addWarningListener(this);
try {
listeners.addWarningListener(this);
} catch (IllegalArgumentException e) {
// This is the expected exception.
assertTrue(e.getMessage().contains("TestListener"));
}
listeners.removeWarningListener(this);
try {
listeners.removeWarningListener(this);
} catch (NoSuchElementException e) {
// This is the expected exception.
assertTrue(e.getMessage().contains("TestListener"));
}
}
代码示例来源:origin: org.apache.sis.storage/sis-storage
/**
* Removes a previously registered listener.
*
* @param listener the listener to remove.
* @throws NoSuchElementException if the given listener is not registered in this data store.
*/
public void removeWarningListener(final WarningListener<? super DataStore> listener)
throws NoSuchElementException
{
listeners.removeWarningListener(listener);
}
代码示例来源:origin: org.apache.sis.core/sis-metadata
/**
* Adds a listener to be notified when a warning occurred while reading from or writing metadata.
* When a warning occurs, there is a choice:
*
* <ul>
* <li>If this metadata source has no warning listener, then the warning is logged at {@link Level#WARNING}.</li>
* <li>If this metadata source has at least one warning listener, then all listeners are notified
* and the warning is <strong>not</strong> logged by this metadata source instance.</li>
* </ul>
*
* Consider invoking this method in a {@code try} … {@code finally} block if the {@code MetadataSource}
* lifetime is longer than the listener lifetime, as below:
*
* {@preformat java
* source.addWarningListener(listener);
* try {
* // Do some work...
* } finally {
* source.removeWarningListener(listener);
* }
* }
*
* @param listener the listener to add.
* @throws IllegalArgumentException if the given listener is already registered in this metadata source.
*/
public void addWarningListener(final WarningListener<? super MetadataSource> listener)
throws IllegalArgumentException
{
listeners.addWarningListener(listener);
}
代码示例来源:origin: apache/sis
/**
* Reports a warning in the {@code "org.apache.sis.io.wkt"} logger. This method pretends that the
* warning come from {@code getMetadata()} method, which is the public facade for the parsing method.
*
* @param record the warning to report.
*/
private void log(final LogRecord record) {
record.setSourceClassName(listeners.getSource().getClass().getName());
record.setSourceMethodName("getMetadata");
record.setLoggerName(Loggers.WKT);
listeners.warning(record);
}
}
代码示例来源:origin: apache/sis
if (exception != null) {
trace = exception.getStackTrace();
message = Exceptions.formatChainedMessages(getLocale(), message, exception);
if (message == null) {
message = exception.toString();
if (isPublic(e)) {
record.setSourceClassName(e.getClassName());
record.setSourceMethodName(e.getMethodName());
warning(record);
代码示例来源:origin: apache/sis
/**
* Returns the locale to use for warnings and error messages.
*/
final Locale getLocale() {
return listeners.getLocale();
}
代码示例来源:origin: org.apache.sis.core/sis-metadata
/**
* Removes a previously registered listener.
*
* @param listener the listener to remove.
* @throws NoSuchElementException if the given listener is not registered in this metadata source.
*/
public void removeWarningListener(final WarningListener<? super MetadataSource> listener)
throws NoSuchElementException
{
listeners.removeWarningListener(listener);
}
代码示例来源:origin: org.apache.sis.storage/sis-storage
throws IllegalArgumentException
listeners.addWarningListener(listener);
代码示例来源:origin: apache/sis
/**
* Invoked by the UCAR netCDF library when an error occurred.
*
* @param message the error message.
*/
@Override
public void setError(final String message) {
listeners.warning(message, null);
}
代码示例来源:origin: org.apache.sis.storage/sis-storage
/**
* Reports a warning for a WKT that can not be read. This method should be invoked only when the CRS
* can not be created at all; it should not be invoked if the CRS has been created with some warnings.
*/
final void log(final Exception e) {
final DataStore store = listeners.getSource();
listeners.warning(Resources.forLocale(store.getLocale())
.getString(Resources.Keys.CanNotReadCRS_WKT_1, store.getDisplayName()), e);
}
代码示例来源:origin: apache/sis
/**
* Reports a warning to the specified listeners.
*
* @param listeners the listeners where to report the warning.
* @param caller the caller class to report, preferably a public class.
* @param method the caller method to report, preferable a public method.
* @param exception the exception that occurred, or {@code null} if none.
* @param resources the resources bundle for {@code key} and {@code arguments}, or {@code null} for {@link Resources}.
* @param key one or {@link Resources.Keys} constants.
* @param arguments values to be formatted in the {@link java.text.MessageFormat} pattern.
*/
static void warning(final WarningListeners<?> listeners, final Class<?> caller, final String method,
final Exception exception, IndexedResourceBundle resources, final short key, final Object... arguments)
{
if (resources == null) {
resources = Resources.forLocale(listeners.getLocale());
}
final LogRecord record = resources.getLogRecord(Level.WARNING, key, arguments);
record.setLoggerName(Modules.NETCDF);
record.setSourceClassName(caller.getCanonicalName());
record.setSourceMethodName(method);
if (exception != null) {
// TODO: avoid reporting the full exception stack trace (maybe leverage QuietLogRecord).
record.setThrown(exception);
}
listeners.warning(record);
}
代码示例来源:origin: apache/sis
/**
* Returns the locale for error messages or warnings.
* Returns {@code null} if no locale is explicitly defined.
*
* @return the locale, or {@code null} if not explicitly defined.
*/
@Override
public final Locale getLocale() {
return (listeners != null) ? listeners.getLocale() : null;
}
代码示例来源:origin: apache/sis
/**
* Creates a new instance with no provider and initially no listener.
*/
protected DataStore() {
provider = null;
name = null;
locale = Locale.getDefault(Locale.Category.DISPLAY);
listeners = new WarningListeners<>(this);
}
内容来源于网络,如有侵权,请联系作者删除!