KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > izforge > izpack > Pack


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  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */

19
20 package com.izforge.izpack;
21
22 import java.io.Serializable JavaDoc;
23 import java.text.DecimalFormat JavaDoc;
24 import java.util.ArrayList JavaDoc;
25 import java.util.HashSet JavaDoc;
26 import java.util.List JavaDoc;
27 import java.util.Set JavaDoc;
28
29 import com.izforge.izpack.compiler.PackInfo;
30
31 /**
32  * Represents a Pack.
33  *
34  * @author Julien Ponge
35  */

36 public class Pack implements Serializable JavaDoc
37 {
38
39     static final long serialVersionUID = -5458360562175088671L;
40
41     /** Flag for store files of this pack outside the installation jar file */
42     public boolean loose;
43
44     /** The pack name. */
45     public String JavaDoc name;
46
47     /** The langpack id */
48     public String JavaDoc id;
49
50     /** An association of this pack to zero or more installation groups. An
51      * installation group is just a named collection of packs to allow for
52      * different pack collections to be selected, for example: minimal,
53      * default, all.
54      */

55     public Set JavaDoc installGroups = new HashSet JavaDoc();
56     
57     /** All packs in the same excludeGroup are mutually exclusive. The excludeGroup
58      * is a string and serves are key identifying each group of mutually
59      * exclusive packs.
60      */

61     public String JavaDoc excludeGroup = new String JavaDoc();
62
63     /** The group the pack is associated with. The pack group identifies
64      * packs with common functionality to allow for grouping of packs in a
65      * tree in the TargetPanel for example.
66      */

67     public String JavaDoc group;
68
69     /** The pack description. */
70     public String JavaDoc description;
71
72     /** The target operation system of this pack */
73     public List JavaDoc osConstraints = null;
74
75     /** The list of packs this pack depends on */
76     public List JavaDoc dependencies = null;
77
78     /** Reverse dependencies(childs) */
79     public List JavaDoc revDependencies = null;
80     
81     /** True if the pack is required. */
82     public boolean required;
83
84     /** The bumber of bytes contained in the pack. */
85     public long nbytes;
86
87     /** Whether this pack is suggested (preselected for installation). */
88     public boolean preselected;
89
90     /** The color of the node. This is used for the dependency graph algorithms */
91     public int color;
92
93     /** white colour */
94     public final static int WHITE = 0;
95
96     /** grey colour */
97     public final static int GREY = 1;
98
99     /** black colour */
100     public final static int BLACK = 2;
101
102     /**
103      * The constructor.
104      *
105      * @param name The pack name.
106      * @param id The id of the pack which is used e.g. for I18N
107      * @param description The pack description.
108      * @param osConstraints the OS constraint (or null for any OS)
109      * @param dependencies dependencies of this pack
110      * @param required Indicates wether the pack is required or not.
111      * @param preselected This pack will be selected automatically.
112      * @param loose Flag for store files of this pack outside the installation jar file
113      * @param excludegroup associated exclude group
114      */

115     public Pack(String JavaDoc name, String JavaDoc id, String JavaDoc description, List JavaDoc osConstraints, List JavaDoc dependencies,
116             boolean required, boolean preselected, boolean loose, String JavaDoc excludegroup)
117     {
118         this.name = name;
119         this.id = id;
120         this.description = description;
121         this.osConstraints = osConstraints;
122         this.dependencies = dependencies;
123         this.required = required;
124         this.preselected = preselected;
125         this.loose = loose;
126         this.excludeGroup = excludegroup;
127         nbytes = 0;
128         color = PackInfo.WHITE;
129     }
130
131     /**
132      * To a String (usefull for JLists).
133      *
134      * @return The String representation of the pack.
135      */

136     public String JavaDoc toString()
137     {
138         return name + " (" + description + ")";
139     }
140
141     /** getter method for dependencies
142      * @return the dependencies list*/

143     public List JavaDoc getDependencies()
144     {
145         return dependencies;
146     }
147     
148     
149     /**
150      * This adds a reverse dependency. With a reverse dependency we imply a child dependency or the
151      * dependents on this pack
152      *
153      * @param name0 The name of the pack that depents to this pack
154      */

155     public void addRevDep(String JavaDoc name0)
156     {
157         if (revDependencies == null) revDependencies = new ArrayList JavaDoc();
158         revDependencies.add(name0);
159     }
160
161     /**
162      * Creates a text list of all the packs it depend on
163      *
164      * @return the created text
165      */

166     public String JavaDoc depString()
167     {
168         String JavaDoc text = "";
169         if (dependencies == null) return text;
170         String JavaDoc name0;
171         for (int i = 0; i < dependencies.size() - 1; i++)
172         {
173             name0 = (String JavaDoc) dependencies.get(i);
174             text += name0 + ",";
175         }
176         name0 = (String JavaDoc) dependencies.get(dependencies.size() - 1);
177         text += name0;
178         return text;
179
180     }
181
182     /** Used of conversions. */
183     private final static double KILOBYTES = 1024.0;
184
185     /** Used of conversions. */
186     private final static double MEGABYTES = 1024.0 * 1024.0;
187
188     /** Used of conversions. */
189     private final static double GIGABYTES = 1024.0 * 1024.0 * 1024.0;
190
191     /** Used of conversions. */
192     private final static DecimalFormat JavaDoc formatter = new DecimalFormat JavaDoc("#,###.##");
193
194     /**
195      * Convert bytes into appropiate mesaurements.
196      *
197      * @param bytes A number of bytes to convert to a String.
198      * @return The String-converted value.
199      */

200     public static String JavaDoc toByteUnitsString(long bytes)
201     {
202         if (bytes < KILOBYTES)
203             return String.valueOf(bytes) + " bytes";
204         else if (bytes < (MEGABYTES))
205         {
206             double value = bytes / KILOBYTES;
207             return formatter.format(value) + " KB";
208         }
209         else if (bytes < (GIGABYTES))
210         {
211             double value = bytes / MEGABYTES;
212             return formatter.format(value) + " MB";
213         }
214         else
215         {
216             double value = bytes / GIGABYTES;
217             return formatter.format(value) + " GB";
218         }
219     }
220 }
221
Popular Tags