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.

ConfigBinding.java 2.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * Copyright (c) 2006-2017 DMDirc Developers
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
  5. * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
  6. * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
  7. * permit persons to whom the Software is furnished to do so, subject to the following conditions:
  8. *
  9. * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
  10. * Software.
  11. *
  12. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  13. * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
  14. * OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  15. * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  16. */
  17. package com.dmdirc.config.binding;
  18. import java.lang.annotation.ElementType;
  19. import java.lang.annotation.Retention;
  20. import java.lang.annotation.RetentionPolicy;
  21. import java.lang.annotation.Target;
  22. /**
  23. * Indicates that a field or method should be bound to a given configuration setting. If a method is
  24. * targeted, the method should take a single argument.
  25. */
  26. @Retention(RetentionPolicy.RUNTIME)
  27. @Target({ElementType.FIELD, ElementType.METHOD})
  28. public @interface ConfigBinding {
  29. /**
  30. * The domain of the configuration setting to bind to.
  31. *
  32. * @return The configuration setting's domain
  33. */
  34. String domain() default "";
  35. /**
  36. * The key of the configuration setting to bind to.
  37. *
  38. * @return The configuration setting's key
  39. */
  40. String key();
  41. /**
  42. * Ordered list of fallback domain/key pairs to attempt to use.
  43. *
  44. * @return Domain/key pairs to use
  45. */
  46. String[] fallbacks() default {};
  47. /**
  48. * Whether or not the configuration will be applied initially or only on updates.
  49. *
  50. * @return True if the value should be applied initially, false otherwise.
  51. */
  52. boolean applyInitially() default true;
  53. /**
  54. * For settings that support fallbacks, whether or not a value is required. If it is not
  55. * required, a "false:" setting will result in {@code null} being returned, rather than
  56. * the next fallback being tried.
  57. *
  58. * @return True if the setting is required, false otherwise.
  59. */
  60. boolean required() default true;
  61. /**
  62. * {@link Invocation} class that will be created and used to execute the config binding. The
  63. * default just directly executes or sets the value.
  64. */
  65. Class<? extends Invocation> invocation() default BasicInvocation.class;
  66. }