forked from makerbot/ReplicatorG
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor more duplicate methods into abstract base class.
- Loading branch information
Matthew W. Samsonoff
committed
Mar 15, 2012
1 parent
ec60bea
commit 28a231c
Showing
3 changed files
with
64 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// vim:cindent:cino=\:0:et:fenc=utf-8:ff=unix:sw=4:ts=4: | ||
|
||
package replicatorg.app.service; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
import org.apache.commons.cli.CommandLine; | ||
import org.apache.commons.cli.CommandLineParser; | ||
import org.apache.commons.cli.GnuParser; | ||
import org.apache.commons.cli.OptionBuilder; | ||
import org.apache.commons.cli.Options; | ||
import org.apache.commons.cli.ParseException; | ||
|
||
import replicatorg.app.Base; | ||
|
||
public abstract class AbstractCommandFactory implements CommandFactory | ||
{ | ||
public Command createCommand(final List<String> arguments) | ||
throws ParseException, MissingArgumentException, | ||
ExtraArgumentsException | ||
{ | ||
final String[] array = arguments.toArray(new String[0]); | ||
final CommandLineParser commandLineParser = new GnuParser(); | ||
final Options options = createOptions(); | ||
final CommandLine commandLine = commandLineParser.parse( | ||
options, array, false); | ||
final Command command = createCommand(commandLine); | ||
return command; | ||
} | ||
|
||
protected abstract Command createCommand(CommandLine commandLine) | ||
throws MissingArgumentException, ExtraArgumentsException; | ||
|
||
protected abstract Options createOptions(); | ||
|
||
protected List<String> getArgumentsAsList(final CommandLine commandLine) | ||
{ | ||
final String[] array = commandLine.getArgs(); | ||
final List<String> list = Arrays.asList(array); | ||
return list; | ||
} | ||
|
||
protected String handleBusName(final CommandLine commandLine) | ||
{ | ||
final String busName; | ||
if (commandLine.hasOption("bus-name")) | ||
{ | ||
busName = commandLine.getOptionValue("bus-name"); | ||
} | ||
else | ||
{ | ||
busName = null; | ||
} | ||
return busName; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters