KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > tools > Repository


1 /*
2  * Copyright (C) 2005 Alfresco, Inc.
3  *
4  * Licensed under the Mozilla Public License version 1.1
5  * with a permitted attribution clause. You may obtain a
6  * copy of the License at
7  *
8  * http://www.alfresco.org/legal/license.txt
9  *
10  * Unless required by applicable law or agreed to in writing,
11  * software distributed under the License is distributed on an
12  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13  * either express or implied. See the License for the specific
14  * language governing permissions and limitations under the
15  * License.
16  */

17 package org.alfresco.tools;
18
19 import java.io.IOException JavaDoc;
20
21 /**
22  * Initializes the full application context and then waits for a
23  * keypress to exit.
24  *
25  * @author Derek Hulley
26  */

27 public class Repository extends Tool
28 {
29     @Override JavaDoc
30     String JavaDoc getToolName()
31     {
32         return "Repository";
33     }
34
35     @Override JavaDoc
36     ToolContext processArgs(String JavaDoc[] args) throws ToolException
37     {
38         ToolContext context = new ToolContext();
39         context.setLogin(true);
40
41         int i = 0;
42         while (i < args.length)
43         {
44             if (args[i].equals("-h") || args[i].equals("-help"))
45             {
46                 context.setHelp(true);
47                 break;
48             }
49             else if (args[i].equals("-user"))
50             {
51                 i++;
52                 if (i == args.length || args[i].length() == 0)
53                 {
54                     throw new ToolException("The value <user> for the option -user must be specified");
55                 }
56                 context.setUsername(args[i]);
57             }
58             else if (args[i].equals("-pwd"))
59             {
60                 i++;
61                 if (i == args.length || args[i].length() == 0)
62                 {
63                     throw new ToolException("The value <password> for the option -pwd must be specified");
64                 }
65                 context.setPassword(args[i]);
66             }
67             else
68             {
69                 throw new ToolException("Unknown option " + args[i] + ". Use -help for options.");
70             }
71
72             // next argument
73
i++;
74         }
75
76         return context;
77     }
78
79     @Override JavaDoc
80     void displayHelp()
81     {
82         System.out.println(
83                 "usage: repository [OPTIONS] \n" +
84                 "\n" +
85                 "Initialize the Alfresco application context, initiating any \n" +
86                 "configured server beans (e.g. CIFS server, FTP server, etc). \n" +
87                 "\n" +
88                 "Options: \n" +
89                 " -h -help Display this help \n" +
90                 " -user USER Login as USER \n" +
91                 " -pwd PASSWORD Use PASSWORD to login");
92     }
93
94     @Override JavaDoc
95     synchronized void execute() throws ToolException
96     {
97         try
98         {
99             System.out.println("\nRepository initialized.\nPress ENTER to exit...");
100             System.in.read();
101             System.out.println("\nShutting down the repository.");
102             // start the ticker
103
new ShutdownNotifierThread().start();
104             try { wait(3000L); } catch (InterruptedException JavaDoc e) {}
105         }
106         catch (IOException JavaDoc e)
107         {
108             // just ignore
109
}
110     }
111     
112     /**
113      * Start the repository and wait for a keypress to stop
114      *
115      * @param args not used
116      */

117     public static void main(String JavaDoc[] args)
118     {
119         new Repository().start(args);
120     }
121     
122     private static class ShutdownNotifierThread extends Thread JavaDoc
123     {
124         private ShutdownNotifierThread()
125         {
126             this.setDaemon(true);
127         }
128         @Override JavaDoc
129         public synchronized void run()
130         {
131             while (true)
132             {
133                 System.out.print('.');
134                 try
135                 {
136                     wait(500L);
137                 }
138                 catch (InterruptedException JavaDoc e)
139                 {
140                 }
141             }
142         }
143     }
144 }
145
Popular Tags