org.apache.sis.util.logging.WarningListeners.addWarningListener()方法的使用及代码示例

x33g5p2x  于2022-02-03 转载在 其他  
字(4.2k)|赞(0)|评价(0)|浏览(121)

本文整理了Java中org.apache.sis.util.logging.WarningListeners.addWarningListener()方法的一些代码示例,展示了WarningListeners.addWarningListener()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WarningListeners.addWarningListener()方法的具体详情如下:
包路径:org.apache.sis.util.logging.WarningListeners
类名称:WarningListeners
方法名:addWarningListener

WarningListeners.addWarningListener介绍

[英]Adds a listener to be notified when a warning occurred. When a warning occurs, there is a choice:

  • If this object has no warning listener, then the warning is logged at java.util.logging.Level#WARNING.
  • If this object has at least one warning listener, then all listeners are notified and the warning is not logged by this object.
    [中]添加发生警告时要通知的侦听器。出现警告时,可以选择:
    *如果这个对象没有警告侦听器,那么警告会记录在java中。util。登录中。级别#警告。
    *如果此对象至少有一个警告侦听器,则会通知所有侦听器,并且此对象不会记录该警告。

代码示例

代码示例来源:origin: apache/sis

  1. /**
  2. * Adds a listener to be notified when a warning occurred while reading from or writing metadata.
  3. * When a warning occurs, there is a choice:
  4. *
  5. * <ul>
  6. * <li>If this metadata source has no warning listener, then the warning is logged at {@link Level#WARNING}.</li>
  7. * <li>If this metadata source has at least one warning listener, then all listeners are notified
  8. * and the warning is <strong>not</strong> logged by this metadata source instance.</li>
  9. * </ul>
  10. *
  11. * Consider invoking this method in a {@code try} … {@code finally} block if the {@code MetadataSource}
  12. * lifetime is longer than the listener lifetime, as below:
  13. *
  14. * {@preformat java
  15. * source.addWarningListener(listener);
  16. * try {
  17. * // Do some work...
  18. * } finally {
  19. * source.removeWarningListener(listener);
  20. * }
  21. * }
  22. *
  23. * @param listener the listener to add.
  24. * @throws IllegalArgumentException if the given listener is already registered in this metadata source.
  25. */
  26. public void addWarningListener(final WarningListener<? super MetadataSource> listener)
  27. throws IllegalArgumentException
  28. {
  29. listeners.addWarningListener(listener);
  30. }

代码示例来源:origin: apache/sis

  1. throws IllegalArgumentException
  2. listeners.addWarningListener(listener);

代码示例来源:origin: org.apache.sis.core/sis-metadata

  1. /**
  2. * Adds a listener to be notified when a warning occurred while reading from or writing metadata.
  3. * When a warning occurs, there is a choice:
  4. *
  5. * <ul>
  6. * <li>If this metadata source has no warning listener, then the warning is logged at {@link Level#WARNING}.</li>
  7. * <li>If this metadata source has at least one warning listener, then all listeners are notified
  8. * and the warning is <strong>not</strong> logged by this metadata source instance.</li>
  9. * </ul>
  10. *
  11. * Consider invoking this method in a {@code try} … {@code finally} block if the {@code MetadataSource}
  12. * lifetime is longer than the listener lifetime, as below:
  13. *
  14. * {@preformat java
  15. * source.addWarningListener(listener);
  16. * try {
  17. * // Do some work...
  18. * } finally {
  19. * source.removeWarningListener(listener);
  20. * }
  21. * }
  22. *
  23. * @param listener the listener to add.
  24. * @throws IllegalArgumentException if the given listener is already registered in this metadata source.
  25. */
  26. public void addWarningListener(final WarningListener<? super MetadataSource> listener)
  27. throws IllegalArgumentException
  28. {
  29. listeners.addWarningListener(listener);
  30. }

代码示例来源:origin: org.apache.sis.storage/sis-storage

  1. throws IllegalArgumentException
  2. listeners.addWarningListener(listener);

代码示例来源:origin: apache/sis

  1. /**
  2. * Tests {@link WarningListeners#addWarningListener(WarningListener)} followed by
  3. * {@link WarningListeners#removeWarningListener(WarningListener)}
  4. */
  5. @Test
  6. public void testAddAndRemoveWarningListener() {
  7. listeners.addWarningListener(this);
  8. try {
  9. listeners.addWarningListener(this);
  10. } catch (IllegalArgumentException e) {
  11. // This is the expected exception.
  12. assertTrue(e.getMessage().contains("TestListener"));
  13. }
  14. listeners.removeWarningListener(this);
  15. try {
  16. listeners.removeWarningListener(this);
  17. } catch (NoSuchElementException e) {
  18. // This is the expected exception.
  19. assertTrue(e.getMessage().contains("TestListener"));
  20. }
  21. }

代码示例来源:origin: apache/sis

  1. /**
  2. * Tests {@link WarningListeners#warning(String, Exception)} with a registered listener.
  3. */
  4. @Test
  5. @DependsOnMethod("testAddAndRemoveWarningListener")
  6. public void testWarning() {
  7. listeners.addWarningListener(this);
  8. listeners.warning("The message", null);
  9. listeners.removeWarningListener(this);
  10. assertNotNull("Listener has not been notified.", warning);
  11. assertEquals(getClass().getName(), warning.getSourceClassName());
  12. assertEquals("testWarning", warning.getSourceMethodName());
  13. assertEquals("The message", warning.getMessage());
  14. }
  15. }

相关文章