KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > ve > luz > ica > jackass > tools > DeployTool


1 /*
2  * Copyright (c) 2003 by The Jackass Team
3  * Licensed under the Open Software License version 2.0
4  */

5 package ve.luz.ica.jackass.tools;
6
7 import java.io.BufferedReader JavaDoc;
8 import java.io.InputStream JavaDoc;
9 import java.io.InputStreamReader JavaDoc;
10
11 import org.apache.commons.logging.Log;
12 import org.apache.commons.logging.LogFactory;
13 import org.omg.CORBA.ORB JavaDoc;
14 import org.omg.PortableServer.POA JavaDoc;
15 import org.omg.PortableServer.POAHelper JavaDoc;
16
17 import ve.luz.ica.jackass.deploy.Deployer;
18 import ve.luz.ica.jackass.deploy.DeployerHelper;
19 import ve.luz.ica.remoteio.FileUtil;
20 import ve.luz.ica.remoteio.RemoteFile;
21
22 /**
23  * This class is a command line tool for deploying applications
24  * @author Carlos Arévalo
25  */

26 public final class DeployTool
27 {
28     private static final Log LOG = LogFactory.getLog(DeployTool.class);
29
30     /**
31      * Private constructor.
32      */

33     private DeployTool()
34     {
35     }
36
37     /**
38      * Deploys an application
39      * @param args the command line parameters
40      */

41     public static void main(String JavaDoc[] args)
42     {
43         try
44         {
45             ORB JavaDoc orb = org.omg.CORBA.ORB.init(args, null);
46             org.omg.CORBA.Object JavaDoc poaObj = orb.resolve_initial_references("RootPOA");
47             POA JavaDoc poa = POAHelper.narrow(poaObj);
48             poa.the_POAManager().activate();
49
50             Deployer deployer = null;
51             org.omg.CORBA.Object JavaDoc obj = null;
52
53             if (args.length < 1)
54             {
55                 System.out.println("Usage: deploytool operation <deployment file name>");
56                 return;
57             }
58
59             String JavaDoc deployerIor = System.getProperty("Deployer");
60             if (deployerIor == null)
61             {
62                 InputStream JavaDoc is = ClassLoader.getSystemResourceAsStream("jackass.deployers");
63                 InputStreamReader JavaDoc isr = new InputStreamReader JavaDoc(is);
64                 java.io.BufferedReader JavaDoc myInput = new BufferedReader JavaDoc(isr);
65                 deployerIor = myInput.readLine();
66             }
67
68             obj = orb.string_to_object(deployerIor);
69             deployer = DeployerHelper.narrow(obj);
70
71             if (args[0].equals("d") || args[0].equals("deploy"))
72             {
73                 System.out.println("Deploying "+args[1]);
74                 RemoteFile remoteFile = FileUtil.createRemoteFile(args[1], poa);
75                 deployer.deploy(remoteFile);
76                 System.out.println("Deployment complete");
77             }
78             else if (args[0].equals("u") || args[0].equals("undeploy"))
79             {
80                 System.out.println("Undeploying "+args[1]);
81                 deployer.undeploy(args[1]);
82                 System.out.println("Undeployment complete");
83             }
84             else
85             {
86                 System.out.println("Usage: deploytool operation <deployment file name>");
87                 return;
88             }
89         }
90         catch (Exception JavaDoc e)
91         {
92             System.out.println("Error deploying application " + e.getMessage());
93             if (LOG.isErrorEnabled()) LOG.error("Error deploying application ", e);
94         }
95
96     }
97 }
98
Popular Tags