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
15
16
17
18
19
20
21
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
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
61 opt.addOption(OptionBuilder.withDescription("Display this help and exit")
62 .withLongOpt(LONGOPT_HELP)
63 .create(OPT_HELP));
64
65
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 }