Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

ActionFactory.java 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. * Copyright (c) 2006-2014 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.actions;
  23. import com.dmdirc.commandline.CommandLineOptionsModule.Directory;
  24. import com.dmdirc.commandline.CommandLineOptionsModule.DirectoryType;
  25. import com.dmdirc.commandparser.parsers.GlobalCommandParser;
  26. import com.dmdirc.interfaces.ActionController;
  27. import com.dmdirc.interfaces.actions.ActionType;
  28. import com.dmdirc.interfaces.config.IdentityController;
  29. import java.util.List;
  30. import javax.inject.Inject;
  31. import javax.inject.Provider;
  32. import javax.inject.Singleton;
  33. /**
  34. * Factory for creating {@link Action}s.
  35. */
  36. @Singleton
  37. public class ActionFactory {
  38. /** Provider of global command parsers. */
  39. private final Provider<GlobalCommandParser> globalCommandParserProvider;
  40. /** The controller that will own actions. */
  41. private final Provider<ActionController> actionController;
  42. /** The controller to use to retrieve and update settings. */
  43. private final Provider<IdentityController> identityController;
  44. /** The factory to use to create substitutors. */
  45. private final ActionSubstitutorFactory substitutorFactory;
  46. /** The base directory to store actions in. */
  47. private final String actionsDirectory;
  48. /**
  49. * Creates a new instance of {@link ActionFactory}.
  50. *
  51. * @param actionController The controller that will own actions.
  52. * @param identityController The controller to use to retrieve and update settings.
  53. * @param globalCommandParserProvider The global command parser to use for actions without windows.
  54. * @param substitutorFactory The factory to use to create substitutors.
  55. * @param actionsDirectory The base directory to store actions in.
  56. */
  57. @Inject
  58. public ActionFactory(
  59. final Provider<ActionController> actionController,
  60. final Provider<IdentityController> identityController,
  61. final Provider<GlobalCommandParser> globalCommandParserProvider,
  62. final ActionSubstitutorFactory substitutorFactory,
  63. @Directory(DirectoryType.ACTIONS) final String actionsDirectory) {
  64. this.actionController = actionController;
  65. this.identityController = identityController;
  66. this.globalCommandParserProvider = globalCommandParserProvider;
  67. this.substitutorFactory = substitutorFactory;
  68. this.actionsDirectory = actionsDirectory;
  69. }
  70. /**
  71. * Creates a new instance of Action. The group and name specified must
  72. * be the group and name of a valid action already saved to disk.
  73. *
  74. * @param group The group the action belongs to
  75. * @param name The name of the action
  76. * @return A relevant action.
  77. */
  78. public Action getAction(final String group, final String name) {
  79. return new Action(globalCommandParserProvider, substitutorFactory, actionController.get(),
  80. identityController.get(), actionsDirectory, group, name);
  81. }
  82. /**
  83. * Creates a new instance of Action with the specified properties and saves
  84. * it to disk.
  85. *
  86. * @param group The group the action belongs to
  87. * @param name The name of the action
  88. * @param triggers The triggers to use
  89. * @param response The response to use
  90. * @param conditions The conditions to use
  91. * @param conditionTree The condition tree to use
  92. * @param newFormat The new formatter to use
  93. * @return A relevant action.
  94. */
  95. public Action getAction(final String group, final String name,
  96. final ActionType[] triggers, final String[] response,
  97. final List<ActionCondition> conditions,
  98. final ConditionTree conditionTree, final String newFormat) {
  99. return new Action(globalCommandParserProvider, substitutorFactory, actionController.get(),
  100. identityController.get(), actionsDirectory, group,
  101. name, triggers, response, conditions, conditionTree, newFormat);
  102. }
  103. }