View Javadoc

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  * *** Centre de Calcul de l'IN2P3 - Lyon (France) ***
12  * ***             http://cc.in2p3.fr/             ***
13  * ***************************************************
14  * File:   NamespaceRemove
15  * Author: Sylvain Reynaud (sreynaud@in2p3.fr)
16  * Date:   12 sept. 2007
17  * ***************************************************
18  * Description:                                      */
19  /**
20   *
21   */
22  public class NamespaceRemove extends AbstractCommand {
23      private static final String OPT_HELP = "h", LONGOPT_HELP = "help";
24      private static final String OPT_RECURSIVE = "r", LONGOPT_RECURSIVE = "recursive";
25  
26      public NamespaceRemove() {
27          super("jsaga-rm", new String[]{"URL"}, new String[]{OPT_HELP, LONGOPT_HELP});
28      }
29  
30      public static void main(String[] args) throws Exception {
31          NamespaceRemove command = new NamespaceRemove();
32          CommandLine line = command.parse(args);
33          if (line.hasOption(OPT_HELP))
34          {
35              command.printHelpAndExit(null);
36          }
37          else
38          {
39              // get arguments
40              URL url = URLFactory.createURL(command.m_nonOptionValues[0]);
41              Flags flags = (line.hasOption(OPT_RECURSIVE) ? Flags.RECURSIVE : Flags.NONE);
42  
43              // execute command
44              Session session = SessionFactory.createSession(true);
45              NSEntry entry = NSFactory.createNSEntry(session, url, Flags.NONE.getValue());
46              entry.remove(flags.getValue());
47              entry.close();
48              System.exit(0);
49          }
50      }
51  
52      protected Options createOptions() {
53          Options opt = new Options();
54          opt.addOption(OptionBuilder.withDescription("Display this help and exit")
55                  .withLongOpt(LONGOPT_HELP)
56                  .create(OPT_HELP));
57          opt.addOption(OptionBuilder.withDescription("Remove recursively")
58                  .isRequired(false)
59                  .withLongOpt(LONGOPT_RECURSIVE)
60                  .create(OPT_RECURSIVE));
61          return opt;
62      }
63  }