|
1 | 1 | package com.marklogic.appdeployer.impl;
|
2 | 2 |
|
3 |
| -import java.util.ArrayList; |
4 |
| -import java.util.List; |
5 |
| - |
6 | 3 | import com.marklogic.appdeployer.command.Command;
|
7 | 4 | import com.marklogic.mgmt.ManageClient;
|
8 | 5 | import com.marklogic.mgmt.admin.AdminManager;
|
9 | 6 |
|
| 7 | +import java.util.ArrayList; |
| 8 | +import java.util.List; |
| 9 | + |
10 | 10 | /**
|
11 | 11 | * Simple implementation that allows for a list of commands to be set.
|
12 | 12 | */
|
13 | 13 | public class SimpleAppDeployer extends AbstractAppDeployer {
|
14 | 14 |
|
15 |
| - private List<Command> commands; |
| 15 | + private List<Command> commands; |
| 16 | + |
| 17 | + public SimpleAppDeployer(Command... commandArray) { |
| 18 | + super(); |
| 19 | + buildModifiableCommandList(commandArray); |
| 20 | + } |
16 | 21 |
|
17 |
| - public SimpleAppDeployer(Command... commandArray) { |
18 |
| - super(); |
19 |
| - buildModifiableCommandList(commandArray); |
20 |
| - } |
| 22 | + public SimpleAppDeployer(ManageClient manageClient, AdminManager adminManager, Command... commandArray) { |
| 23 | + super(manageClient, adminManager); |
| 24 | + buildModifiableCommandList(commandArray); |
| 25 | + } |
21 | 26 |
|
22 |
| - public SimpleAppDeployer(ManageClient manageClient, AdminManager adminManager, Command... commandArray) { |
23 |
| - super(manageClient, adminManager); |
24 |
| - buildModifiableCommandList(commandArray); |
25 |
| - } |
| 27 | + /** |
| 28 | + * Arrays.asList produces an unmodifiable list, but we want a client to be able to modify the list. |
| 29 | + * |
| 30 | + * @param commandArray |
| 31 | + */ |
| 32 | + protected void buildModifiableCommandList(Command... commandArray) { |
| 33 | + if (commandArray != null) { |
| 34 | + commands = new ArrayList<Command>(commandArray.length); |
| 35 | + for (Command c : commandArray) { |
| 36 | + commands.add(c); |
| 37 | + } |
| 38 | + } else { |
| 39 | + commands = new ArrayList<Command>(); |
| 40 | + } |
| 41 | + } |
26 | 42 |
|
27 |
| - /** |
28 |
| - * Arrays.asList produces an unmodifiable list, but we want a client to be able to modify the list. |
29 |
| - * |
30 |
| - * @param commandArray |
31 |
| - */ |
32 |
| - protected void buildModifiableCommandList(Command... commandArray) { |
33 |
| - if (commandArray != null) { |
34 |
| - commands = new ArrayList<Command>(commandArray.length); |
35 |
| - for (Command c : commandArray) { |
36 |
| - commands.add(c); |
37 |
| - } |
38 |
| - } else { |
39 |
| - commands = new ArrayList<Command>(); |
40 |
| - } |
41 |
| - } |
| 43 | + /** |
| 44 | + * Convenience method for finding a command of a certain type, presumably so it can be modified/reconfigured. |
| 45 | + * |
| 46 | + * @param clazz |
| 47 | + * @return |
| 48 | + */ |
| 49 | + public Command getCommandOfType(Class<?> clazz) { |
| 50 | + for (Command c : commands) { |
| 51 | + if (c.getClass().equals(clazz)) { |
| 52 | + return c; |
| 53 | + } |
| 54 | + } |
| 55 | + return null; |
| 56 | + } |
42 | 57 |
|
43 |
| - /** |
44 |
| - * Convenience method for finding a command of a certain type, presumably so it can be modified/reconfigured. |
45 |
| - * |
46 |
| - * @param clazz |
47 |
| - * @return |
48 |
| - */ |
49 |
| - public Command getCommandOfType(Class<?> clazz) { |
50 |
| - for (Command c : commands) { |
51 |
| - if (c.getClass().equals(clazz)) { |
52 |
| - return c; |
53 |
| - } |
54 |
| - } |
55 |
| - return null; |
56 |
| - } |
| 58 | + /** |
| 59 | + * Convenience method for finding a command with the given short class name (i.e. no package info in it), presumably so it can be |
| 60 | + * modified/reconfigured. |
| 61 | + * |
| 62 | + * @param shortClassName |
| 63 | + * @return |
| 64 | + */ |
| 65 | + public Command getCommand(String shortClassName) { |
| 66 | + for (Command c : commands) { |
| 67 | + if (c.getClass().getSimpleName().equals(shortClassName)) { |
| 68 | + return c; |
| 69 | + } |
| 70 | + } |
| 71 | + return null; |
| 72 | + } |
57 | 73 |
|
58 |
| - /** |
59 |
| - * Convenience method for finding a command with the given class name, presumably so it can be |
60 |
| - * modified/reconfigured. |
61 |
| - * |
62 |
| - * @param className |
63 |
| - * @return |
64 |
| - */ |
65 |
| - public Command getCommand(String className) { |
66 |
| - for (Command c : commands) { |
67 |
| - if (c.getClass().getSimpleName().equals(className)) { |
68 |
| - return c; |
69 |
| - } |
70 |
| - } |
71 |
| - return null; |
72 |
| - } |
| 74 | + /** |
| 75 | + * Remove the first command that has the same short class name as the given argument, and return it |
| 76 | + * if it's removed. |
| 77 | + * |
| 78 | + * @param shortClassName |
| 79 | + * @return |
| 80 | + */ |
| 81 | + public Command removeCommand(String shortClassName) { |
| 82 | + for (Command c : commands) { |
| 83 | + if (c.getClass().getSimpleName().equals(shortClassName)) { |
| 84 | + commands.remove(c); |
| 85 | + return c; |
| 86 | + } |
| 87 | + } |
| 88 | + return null; |
| 89 | + } |
73 | 90 |
|
74 |
| - /** |
75 |
| - * Keep this public so that a client can easily manipulate the list in case a default set of commands has been |
76 |
| - * provided. |
77 |
| - */ |
78 |
| - @Override |
79 |
| - public List<Command> getCommands() { |
80 |
| - return commands; |
81 |
| - } |
| 91 | + /** |
| 92 | + * Keep this public so that a client can easily manipulate the list in case a default set of commands has been |
| 93 | + * provided. |
| 94 | + */ |
| 95 | + @Override |
| 96 | + public List<Command> getCommands() { |
| 97 | + return commands; |
| 98 | + } |
82 | 99 |
|
83 |
| - public void setCommands(List<Command> commands) { |
84 |
| - this.commands = commands; |
85 |
| - } |
| 100 | + public void setCommands(List<Command> commands) { |
| 101 | + this.commands = commands; |
| 102 | + } |
86 | 103 |
|
87 | 104 | }
|
0 commit comments