View Javadoc

1   package fr.in2p3.jsaga.command;
2   
3   import fr.in2p3.jsaga.impl.context.ConfiguredContext;
4   import fr.in2p3.jsaga.impl.context.ConfigurableContextFactory;
5   import fr.in2p3.jsaga.impl.context.ContextImpl;
6   import fr.in2p3.jsaga.impl.session.SessionImpl;
7   import org.apache.commons.cli.*;
8   import org.ogf.saga.context.Context;
9   import org.ogf.saga.session.Session;
10  import org.ogf.saga.session.SessionFactory;
11  import org.ogf.saga.url.URLFactory;
12  
13  /* ***************************************************
14  * *** Centre de Calcul de l'IN2P3 - Lyon (France) ***
15  * ***             http://cc.in2p3.fr/             ***
16  * ***************************************************
17  * File:   ContextDestroy
18  * Author: Sylvain Reynaud (sreynaud@in2p3.fr)
19  * Date:   28 sept. 2007
20  * ***************************************************
21  * Description:                                      */
22  /**
23   *
24   */
25  public class ContextDestroy extends AbstractCommand {
26      private static final String OPT_HELP = "h", LONGOPT_HELP = "help";
27  
28      public ContextDestroy() {
29          super("jsaga-context-destroy", new String[]{"contextId"}, null);        
30      }
31  
32      public static void main(String[] args) throws Exception {
33          ContextDestroy command = new ContextDestroy();
34          CommandLine line = command.parse(args);
35          if (line.hasOption(OPT_HELP))
36          {
37              command.printHelpAndExit(null);
38          }
39          else {
40              // create empty session
41              Session session = SessionFactory.createSession(false);
42              ConfiguredContext[] configContexts = ConfigurableContextFactory.listConfiguredContext();
43              for (int i=0; i<configContexts.length; i++) {
44                  if (command.m_nonOptionValues.length==0
45                      || command.m_nonOptionValues[0].equals(configContexts[i].getUrlPrefix())
46                      || command.m_nonOptionValues[0].equals(configContexts[i].getType()))
47                  {
48                      Context context = ConfigurableContextFactory.createContext(configContexts[i]);
49                      ((ContextImpl) context).destroy();
50                      ((ContextImpl) context).close();
51                  }
52              }
53              session.close();
54          }
55      }
56  
57      protected Options createOptions() {
58          Options opt = new Options();
59  
60          // command
61          opt.addOption(OptionBuilder.withDescription("Display this help and exit")
62                  .withLongOpt(LONGOPT_HELP)
63                  .create(OPT_HELP));
64  
65          // system properties
66          opt.addOption(OptionBuilder.withDescription("Set context instance attribute (e.g. -DVOMS[0].UserVO=dteam)")
67                  .withArgName("ctxId>.<attr>=<value")
68                  .hasArg()
69                  .withValueSeparator()
70                  .create("D"));
71          return opt;
72      }
73  }