01: /*
02: * $Id: DescribeCommand.java 674 2006-10-06 12:15:59Z hengels $
03: * (c) Copyright 2004 con:cern development team.
04: *
05: * This file is part of con:cern (http://concern.sf.net).
06: *
07: * con:cern is free software; you can redistribute it and/or modify
08: * it under the terms of the GNU Lesser General Public License
09: * as published by the Free Software Foundation; either version 2.1
10: * of the License, or (at your option) any later version.
11: *
12: * Please see COPYING for the complete licence.
13: */
14: package org.concern.client.commandline;
15:
16: import org.concern.model.Activity;
17: import org.concern.model.Process;
18: import java.util.*;
19:
20: /**
21: * <b>Example</b>: list all projects that are enlisted for the asynchronous Implementation activity<br>
22: * <pre>
23: * concern.sh Project list org.concern.test.project.Implementation
24: * </pre>
25: *
26: * @author hengels
27: */
28: public class DescribeCommand extends Command {
29: private String[] activities;
30:
31: public DescribeCommand() {
32: usage = "[ACTIVITY]...\n Describe all or some of the activities.";
33: }
34:
35: public String[] getActivities() {
36: return activities;
37: }
38:
39: public void setActivities(String[] activities) {
40: this .activities = activities;
41: }
42:
43: public void setArguments(String[] args) {
44: activities = new String[args.length];
45: for (int i = 0; i < args.length; i++) {
46: String activity = args[i];
47: activities[i] = activity;
48: }
49: }
50:
51: public void run() {
52: try {
53: Process process = controller.getProcess();
54:
55: if (activities == null || activities.length == 0
56: || "*".equals(activities[0]))
57: activities = allNames(process);
58:
59: for (int i = 0; i < activities.length; i++) {
60: String name = activities[i];
61: Activity activity = process.getActivity(name);
62: if (activity != null) {
63: System.out.println("describe " + name + ":");
64: System.out.println("precondition: "
65: + activity.getPrecondition());
66: System.out.println("postcondition: "
67: + activity.getPostcondition());
68: } else {
69: System.out
70: .println("describe " + name + ": UNKNOWN");
71: }
72: }
73: } catch (Exception e) {
74: System.out.println("describe: ERROR");
75: e.printStackTrace();
76: }
77: }
78:
79: private String[] allNames(Process process) {
80: String[] names = new String[process.getActivities().size()];
81: int i = 0;
82: for (Iterator iterator = process.getActivities().iterator(); iterator
83: .hasNext();) {
84: Activity activity = (Activity) iterator.next();
85: names[i++] = activity.getName();
86: }
87: Arrays.sort(names);
88: return names;
89: }
90: }
|