You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CallbackManager.java 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. * Copyright (c) 2006-2015 DMDirc Developers
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy
  5. * of this software and associated documentation files (the "Software"), to deal
  6. * in the Software without restriction, including without limitation the rights
  7. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. * copies of the Software, and to permit persons to whom the Software is
  9. * furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  20. * SOFTWARE.
  21. */
  22. package com.dmdirc.parser.common;
  23. import com.dmdirc.parser.interfaces.Parser;
  24. import com.dmdirc.parser.interfaces.callbacks.CallbackInterface;
  25. /**
  26. * Parser Callback Manager.
  27. * Manages adding/removing/calling callbacks.
  28. */
  29. public interface CallbackManager {
  30. /**
  31. * Initialises this callback manager.
  32. *
  33. * @param parser The parser associated with this CallbackManager
  34. */
  35. void initialise(Parser parser);
  36. /**
  37. * Remove all callbacks associated with a specific object.
  38. *
  39. * @param o instance of ICallbackInterface to remove.
  40. */
  41. void delAllCallback(CallbackInterface o);
  42. /**
  43. * Add all callbacks that this object implements.
  44. *
  45. * @param o instance of ICallbackInterface to add.
  46. */
  47. void addAllCallback(CallbackInterface o);
  48. /**
  49. * Add a callback.
  50. * This method will throw a CallbackNotFoundException if the callback does not exist.
  51. *
  52. * @param <S> The type of callback
  53. * @param callback Type of callback object
  54. * @param o instance of ICallbackInterface to add.
  55. * @throws CallbackNotFoundException If callback is not found.
  56. * @throws NullPointerException If 'o' is null
  57. */
  58. <S extends CallbackInterface> void addCallback(Class<S> callback, S o)
  59. throws CallbackNotFoundException;
  60. /**
  61. * Add a callback with a specific target.
  62. * This method will throw a CallbackNotFoundException if the callback does not exist.
  63. *
  64. * @param <S> The type of callback
  65. * @param callback Type of callback object.
  66. * @param o instance of ICallbackInterface to add.
  67. * @param target Parameter to specify that a callback should only fire for specific things
  68. * @throws CallbackNotFoundException If callback is not found.
  69. * @throws NullPointerException If 'o' is null
  70. */
  71. <S extends CallbackInterface> void addCallback(Class<S> callback, S o, String target)
  72. throws CallbackNotFoundException;
  73. /**
  74. * Remove a callback.
  75. *
  76. * @param callback Type of callback object.
  77. * @param o instance of ICallbackInterface to remove.
  78. */
  79. void delCallback(Class<? extends CallbackInterface> callback, CallbackInterface o);
  80. /**
  81. * Gets a proxy object which can be used to despatch callbacks of the
  82. * specified type. Callers may pass <code>null</code> for the first two
  83. * arguments of any callback, and these will automatically be replaced
  84. * by the relevant Parser instance and the current date.
  85. *
  86. * @param <T> The type of the callback to retrieve
  87. * @param callback The callback to retrieve
  88. * @return A proxy object which can be used to call the specified callback
  89. */
  90. @SuppressWarnings({"unchecked", "rawtypes"})
  91. <T extends CallbackInterface> T getCallback(Class<T> callback);
  92. }