OSDN Git Service

android-2.1_r1 snapshot
[android-x86/sdk.git] / sdkmanager / libs / sdkuilib / src / com / android / sdkuilib / internal / repository / ArchiveInfo.java
1 /*\r
2  * Copyright (C) 2009 The Android Open Source Project\r
3  *\r
4  * Licensed under the Apache License, Version 2.0 (the "License");\r
5  * you may not use this file except in compliance with the License.\r
6  * You may obtain a copy of the License at\r
7  *\r
8  *      http://www.apache.org/licenses/LICENSE-2.0\r
9  *\r
10  * Unless required by applicable law or agreed to in writing, software\r
11  * distributed under the License is distributed on an "AS IS" BASIS,\r
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
13  * See the License for the specific language governing permissions and\r
14  * limitations under the License.\r
15  */\r
16 \r
17 package com.android.sdkuilib.internal.repository;\r
18 \r
19 import com.android.sdklib.internal.repository.Archive;\r
20 \r
21 import java.util.ArrayList;\r
22 import java.util.Collection;\r
23 \r
24 /**\r
25  * Represents an archive that we want to install.\r
26  * Note that the installer deals with archives whereas the user mostly sees packages\r
27  * but as far as we are concerned for installation there's a 1-to-1 mapping.\r
28  * <p/>\r
29  * A new archive is always a remote archive that needs to be downloaded and then\r
30  * installed. It can replace an existing local one. It can also depends on another\r
31  * (new or local) archive, which means the dependent archive needs to be successfully\r
32  * installed first. Finally this archive can also be a dependency for another one.\r
33  *\r
34  * @see ArchiveInfo#ArchiveInfo(Archive, Archive, ArchiveInfo)\r
35  */\r
36 class ArchiveInfo {\r
37 \r
38     private final Archive mNewArchive;\r
39     private final Archive mReplaced;\r
40     private final ArchiveInfo mDependsOn;\r
41     private final ArrayList<ArchiveInfo> mDependencyFor = new ArrayList<ArchiveInfo>();\r
42     private boolean mAccepted;\r
43     private boolean mRejected;\r
44 \r
45     /**\r
46      *\r
47      * @param newArchive A "new archive" to be installed. This is always an archive\r
48      *          that comes from a remote site. This can not be null.\r
49      * @param replaced An optional local archive that the new one will replace.\r
50      *          Can be null if this archive does not replace anything.\r
51      * @param dependsOn An optional new or local dependency, that is an archive that\r
52      *          <em>this</em> archive depends upon. In other words, we can only install\r
53      *          this archive if the dependency has been successfully installed. It also\r
54      *          means we need to install the dependency first.\r
55      */\r
56     public ArchiveInfo(Archive newArchive, Archive replaced, ArchiveInfo dependsOn) {\r
57         mNewArchive = newArchive;\r
58         mReplaced = replaced;\r
59         mDependsOn = dependsOn;\r
60     }\r
61 \r
62     /**\r
63      * Returns the "new archive" to be installed.\r
64      * This is always an archive that comes from a remote site.\r
65      */\r
66     public Archive getNewArchive() {\r
67         return mNewArchive;\r
68     }\r
69 \r
70     /**\r
71      * Returns an optional local archive that the new one will replace.\r
72      * Can be null if this archive does not replace anything.\r
73      */\r
74     public Archive getReplaced() {\r
75         return mReplaced;\r
76     }\r
77 \r
78     /**\r
79      * Returns an optional new or local dependency, that is an archive that <em>this</em>\r
80      * archive depends upon. In other words, we can only install this archive if the\r
81      * dependency has been successfully installed. It also means we need to install the\r
82      * dependency first.\r
83      */\r
84     public ArchiveInfo getDependsOn() {\r
85         return mDependsOn;\r
86     }\r
87 \r
88     /**\r
89      * Returns true if this new archive is a dependency for <em>another</em> one that we\r
90      * want to install.\r
91      */\r
92     public boolean isDependencyFor() {\r
93         return mDependencyFor.size() > 0;\r
94     }\r
95 \r
96     /**\r
97      * Adds an {@link ArchiveInfo} for which <em>this</em> package is a dependency.\r
98      * This means the package added here depends on this package.\r
99      */\r
100     public void addDependencyFor(ArchiveInfo dependencyFor) {\r
101         if (!mDependencyFor.contains(dependencyFor)) {\r
102             mDependencyFor.add(dependencyFor);\r
103         }\r
104     }\r
105 \r
106     public Collection<ArchiveInfo> getDependenciesFor() {\r
107         return mDependencyFor;\r
108     }\r
109 \r
110     /**\r
111      * Sets whether this archive was accepted (either manually by the user or\r
112      * automatically if it doesn't have a license) for installation.\r
113      */\r
114     public void setAccepted(boolean accepted) {\r
115         mAccepted = accepted;\r
116     }\r
117 \r
118     /**\r
119      * Returns whether this archive was accepted (either manually by the user or\r
120      * automatically if it doesn't have a license) for installation.\r
121      */\r
122     public boolean isAccepted() {\r
123         return mAccepted;\r
124     }\r
125 \r
126     /**\r
127      * Sets whether this archive was rejected manually by the user.\r
128      * An archive can neither accepted nor rejected.\r
129      */\r
130     public void setRejected(boolean rejected) {\r
131         mRejected = rejected;\r
132     }\r
133 \r
134     /**\r
135      * Returns whether this archive was rejected manually by the user.\r
136      * An archive can neither accepted nor rejected.\r
137      */\r
138     public boolean isRejected() {\r
139         return mRejected;\r
140     }\r
141 }\r