1 package fr.in2p3.jsaga.command;
2
3 import org.apache.commons.cli.*;
4 import org.ogf.saga.namespace.*;
5 import org.ogf.saga.session.Session;
6 import org.ogf.saga.session.SessionFactory;
7 import org.ogf.saga.url.URL;
8 import org.ogf.saga.url.URLFactory;
9
10
11
12
13
14
15
16
17
18
19
20
21
22 public class NamespaceMove extends AbstractCommand {
23 private static final String OPT_HELP = "h", LONGOPT_HELP = "help";
24 private static final String OPT_NOT_OVERWRITE = "i", LONGOPT_NOT_OVERWRITE = "interactive";
25 private static final String OPT_RECURSIVE = "r", LONGOPT_RECURSIVE = "recursive";
26
27 public NamespaceMove() {
28 super("jsaga-mv", new String[]{"Source URL", "Target URL"}, new String[]{OPT_HELP, LONGOPT_HELP});
29 }
30
31 public static void main(String[] args) throws Exception {
32 NamespaceMove command = new NamespaceMove();
33 CommandLine line = command.parse(args);
34 command.execute(line);
35 }
36
37 public void execute(CommandLine line) throws Exception {
38 if (line.hasOption(OPT_HELP))
39 {
40 super.printHelpAndExit(null);
41 }
42 else
43 {
44
45 URL source = URLFactory.createURL(super.m_nonOptionValues[0]);
46 URL target = URLFactory.createURL(super.m_nonOptionValues[1]);
47 int flags =(line.hasOption(OPT_NOT_OVERWRITE) ? Flags.NONE : Flags.OVERWRITE)
48 .or(line.hasOption(OPT_RECURSIVE) ? Flags.RECURSIVE : Flags.NONE);
49
50
51 Session session = SessionFactory.createSession(true);
52 NSEntry entry = NSFactory.createNSEntry(session, source, Flags.NONE.getValue());
53 this.changeBehavior(session, target);
54 entry.move(target, flags);
55 entry.close();
56 System.exit(0);
57 }
58 }
59
60 protected void changeBehavior(Session session, URL target) throws Exception {
61
62 }
63
64 protected Options createOptions() {
65 Options opt = new Options();
66 opt.addOption(OptionBuilder.withDescription("Display this help and exit")
67 .withLongOpt(LONGOPT_HELP)
68 .create(OPT_HELP));
69 opt.addOption(OptionBuilder.withDescription("Do not overwrite target")
70 .isRequired(false)
71 .withLongOpt(LONGOPT_NOT_OVERWRITE)
72 .create(OPT_NOT_OVERWRITE));
73 opt.addOption(OptionBuilder.withDescription("Move recursively")
74 .isRequired(false)
75 .withLongOpt(LONGOPT_RECURSIVE)
76 .create(OPT_RECURSIVE));
77 return opt;
78 }
79 }