1 /* 2 * Copyright (C) 2011 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.sdklib.internal.repository; 18 19 import com.android.sdklib.internal.repository.Archive; 20 import com.android.sdklib.internal.repository.IDescription; 21 import com.android.sdklib.internal.repository.Package; 22 23 /** 24 * Represents an archive that we want to install and the archive that it is 25 * going to replace, if any. 26 */ 27 public class ArchiveReplacement implements IDescription { 28 29 private final Archive mNewArchive; 30 private final Archive mReplaced; 31 32 /** 33 * Creates a new replacement where the {@code newArchive} will replace the 34 * currently installed {@code replaced} archive. 35 * When {@code newArchive} is not intended to replace anything (e.g. because 36 * the user is installing a new package not present on her system yet), then 37 * {@code replace} shall be null. 38 * 39 * @param newArchive A "new archive" to be installed. This is always an archive 40 * that comes from a remote site. This <em>may</em> be null. 41 * @param replaced An optional local archive that the new one will replace. 42 * Can be null if this archive does not replace anything. 43 */ ArchiveReplacement(Archive newArchive, Archive replaced)44 public ArchiveReplacement(Archive newArchive, Archive replaced) { 45 mNewArchive = newArchive; 46 mReplaced = replaced; 47 } 48 49 /** 50 * Returns the "new archive" to be installed. 51 * This <em>may</em> be null for missing archives. 52 */ getNewArchive()53 public Archive getNewArchive() { 54 return mNewArchive; 55 } 56 57 /** 58 * Returns an optional local archive that the new one will replace. 59 * Can be null if this archive does not replace anything. 60 */ getReplaced()61 public Archive getReplaced() { 62 return mReplaced; 63 } 64 65 /** 66 * Returns the long description of the parent package of the new archive, if not null. 67 * Otherwise returns an empty string. 68 */ getLongDescription()69 public String getLongDescription() { 70 if (mNewArchive != null) { 71 Package p = mNewArchive.getParentPackage(); 72 if (p != null) { 73 return p.getLongDescription(); 74 } 75 } 76 return ""; 77 } 78 79 /** 80 * Returns the short description of the parent package of the new archive, if not null. 81 * Otherwise returns an empty string. 82 */ getShortDescription()83 public String getShortDescription() { 84 if (mNewArchive != null) { 85 Package p = mNewArchive.getParentPackage(); 86 if (p != null) { 87 return p.getShortDescription(); 88 } 89 } 90 return ""; 91 } 92 93 /** 94 * Returns the short description of the parent package of the new archive, if not null. 95 * Otherwise returns the default Object toString result. 96 * <p/> 97 * This is mostly helpful for debugging. For UI display, use the {@link IDescription} 98 * interface. 99 */ 100 @Override toString()101 public String toString() { 102 if (mNewArchive != null) { 103 Package p = mNewArchive.getParentPackage(); 104 if (p != null) { 105 return p.getShortDescription(); 106 } 107 } 108 return super.toString(); 109 } 110 } 111