KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ejbca > ui > cli > CaListCAsCommand


1 /*************************************************************************
2  * *
3  * EJBCA: The OpenSource Certificate Authority *
4  * *
5  * This software is free software; you can redistribute it and/or *
6  * modify it under the terms of the GNU Lesser General Public *
7  * License as published by the Free Software Foundation; either *
8  * version 2.1 of the License, or any later version. *
9  * *
10  * See terms of license at gnu.org. *
11  * *
12  *************************************************************************/

13  
14 package org.ejbca.ui.cli;
15
16 import java.util.Collection JavaDoc;
17 import java.util.Iterator JavaDoc;
18
19 import org.ejbca.core.ejb.ca.caadmin.ICAAdminSessionRemote;
20 import org.ejbca.core.model.ca.caadmin.CAInfo;
21
22 /**
23  * Lists the names of all available CAs.
24  *
25  * @version $Id: CaListCAsCommand.java,v 1.1 2006/01/17 20:28:05 anatom Exp $
26  */

27 public class CaListCAsCommand extends BaseCaAdminCommand {
28     /**
29      * Creates a new instance of CaListCAsCommand
30      *
31      * @param args command line arguments
32      */

33     public CaListCAsCommand(String JavaDoc[] args) {
34         super(args);
35     }
36
37     /**
38      * Runs the command
39      *
40      * @throws IllegalAdminCommandException Error in command args
41      * @throws ErrorAdminCommandException Error running command
42      */

43     public void execute() throws IllegalAdminCommandException, ErrorAdminCommandException {
44             
45         if (args.length > 1) {
46            String JavaDoc msg = "Lists the names of all available CAs.\nUsage: CA listcas";
47            throw new IllegalAdminCommandException(msg);
48         }
49         try {
50             ICAAdminSessionRemote casession = getCAAdminSessionRemote();
51             Collection JavaDoc caids = casession.getAvailableCAs(administrator);
52             Iterator JavaDoc iter = caids.iterator();
53             while (iter.hasNext()) {
54                 int caid = ((Integer JavaDoc)iter.next()).intValue();
55                 CAInfo ca = casession.getCAInfo(administrator,caid);
56                 getOutputStream().println();
57                 getOutputStream().println("CA Name: "+ca.getName());
58                 getOutputStream().println("Id: "+ca.getCAId());
59                 getOutputStream().println("DN: "+ca.getSubjectDN());
60                 getOutputStream().println("Type: "+ca.getCAType());
61                 getOutputStream().println("Expire time: "+ca.getExpireTime());
62                 getOutputStream().println("Signed by: "+ca.getSignedBy());
63             }
64         } catch (Exception JavaDoc e) {
65             throw new ErrorAdminCommandException(e);
66         }
67     } // execute
68
}
69
Popular Tags