本文整理了Java中org.apache.sis.util.logging.WarningListeners.addWarningListener()
方法的一些代码示例,展示了WarningListeners.addWarningListener()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WarningListeners.addWarningListener()
方法的具体详情如下:
包路径:org.apache.sis.util.logging.WarningListeners
类名称:WarningListeners
方法名:addWarningListener
[英]Adds a listener to be notified when a warning occurred. When a warning occurs, there is a choice:
代码示例来源:origin: apache/sis
/**
* 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
throws IllegalArgumentException
listeners.addWarningListener(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: org.apache.sis.storage/sis-storage
throws IllegalArgumentException
listeners.addWarningListener(listener);
代码示例来源: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: 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());
}
}
内容来源于网络,如有侵权,请联系作者删除!