KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > izforge > izpack > panels > InstallPanelAutomationHelper


1 /*
2  * IzPack - Copyright 2001-2007 Julien Ponge, All Rights Reserved.
3  *
4  * http://www.izforge.com/izpack/
5  * http://developer.berlios.de/projects/izpack/
6  *
7  * Copyright 2003 Jonathan Halliday
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  * http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  */

21
22 package com.izforge.izpack.panels;
23
24 import net.n3.nanoxml.XMLElement;
25
26 import com.izforge.izpack.installer.AutomatedInstallData;
27 import com.izforge.izpack.installer.IUnpacker;
28 import com.izforge.izpack.installer.PanelAutomation;
29 import com.izforge.izpack.installer.PanelAutomationHelper;
30 import com.izforge.izpack.installer.UnpackerFactory;
31 import com.izforge.izpack.util.AbstractUIProgressHandler;
32
33 /**
34  * Functions to support automated usage of the InstallPanel
35  *
36  * @author Jonathan Halliday
37  */

38 public class InstallPanelAutomationHelper extends PanelAutomationHelper implements PanelAutomation,
39         AbstractUIProgressHandler
40 {
41
42     private int noOfPacks = 0;
43
44     /**
45      * Null op - this panel type has no state to serialize.
46      *
47      * @param installData unused.
48      * @param panelRoot unused.
49      */

50     public void makeXMLData(AutomatedInstallData installData, XMLElement panelRoot)
51     {
52         // do nothing.
53
}
54
55     /**
56      * Perform the installation actions.
57      *
58      * @param panelRoot The panel XML tree root.
59      *
60      * @return true if the installation was successful.
61      */

62     public boolean runAutomated(AutomatedInstallData idata, XMLElement panelRoot)
63     {
64         /*
65         Unpacker unpacker = new Unpacker(idata, this);
66         unpacker.start();
67         */

68         IUnpacker unpacker = UnpackerFactory.getUnpacker(idata.info.getUnpackerClassName(), idata, this);
69         Thread JavaDoc unpackerthread = new Thread JavaDoc(unpacker, "IzPack - Unpacker thread");
70         unpackerthread.start();
71         boolean done = false;
72         while (!done && unpackerthread.isAlive())
73         {
74             try
75             {
76                 Thread.sleep(100);
77             }
78             catch (InterruptedException JavaDoc e)
79             {
80                 // ignore it, we're waiting for the unpacker to finish...
81
}
82         }
83         return unpacker.getResult();
84     }
85
86     /**
87      * Reports progress on System.out
88      *
89      * @see AbstractUIProgressHandler#startAction(String, int)
90      */

91     public void startAction(String JavaDoc name, int no_of_steps)
92     {
93         System.out.println("[ Starting to unpack ]");
94         this.noOfPacks = no_of_steps;
95     }
96
97     /**
98      * Sets state variable for thread sync.
99      *
100      * @see com.izforge.izpack.util.AbstractUIProgressHandler#stopAction()
101      */

102     public void stopAction()
103     {
104         System.out.println("[ Unpacking finished. ]");
105         boolean done = true;
106     }
107
108     /**
109      * Null op.
110      *
111      * @param val
112      * @param msg
113      * @see com.izforge.izpack.util.AbstractUIProgressHandler#progress(int, String)
114      */

115     public void progress(int val, String JavaDoc msg)
116     {
117         // silent for now. should log individual files here, if we had a verbose
118
// mode?
119
}
120
121     /**
122      * Reports progress to System.out
123      *
124      * @param packName The currently installing pack.
125      * @param stepno The number of the pack
126      * @param stepsize unused
127      * @see com.izforge.izpack.util.AbstractUIProgressHandler#nextStep(String, int, int)
128      */

129     public void nextStep(String JavaDoc packName, int stepno, int stepsize)
130     {
131         System.out.print("[ Processing package: " + packName + " (");
132         System.out.print(stepno);
133         System.out.print('/');
134         System.out.print(this.noOfPacks);
135         System.out.println(") ]");
136     }
137
138 }
139
Popular Tags