OLD | NEW |
(Empty) | |
| 1 /* Copyright (c) 2002-2008 Sun Microsystems, Inc. All rights reserved |
| 2 * |
| 3 * This program is distributed under the terms of |
| 4 * the GNU General Public License Version 2. See the LICENSE file |
| 5 * at the top of the source tree. |
| 6 */ |
| 7 package org.pantsbuild.jmake; |
| 8 |
| 9 import java.io.File; |
| 10 import java.util.LinkedHashMap; |
| 11 import java.util.Map; |
| 12 |
| 13 /** |
| 14 * This class is a persistent container for the Project Class Directory, that ca
n |
| 15 * read and write itself from/to disk. |
| 16 * |
| 17 * @author Misha Dmitriev |
| 18 * 12 November 2001 |
| 19 */ |
| 20 public class PCDContainer { |
| 21 |
| 22 /** The data structure (currently {@link LinkedHashMap}) for PCD, that maps
class name to |
| 23 record containing information about the class */ |
| 24 Map<String,PCDEntry> pcd; |
| 25 String storeName; |
| 26 boolean textFormat; |
| 27 |
| 28 private PCDContainer(Map<String,PCDEntry> pcd, String storeName, boolean tex
tFormat) { |
| 29 this.storeName = storeName; |
| 30 this.pcd = pcd; |
| 31 this.textFormat = textFormat; |
| 32 } |
| 33 |
| 34 public static PCDContainer load(String storeName, boolean textFormat) { |
| 35 if (storeName == null) { |
| 36 storeName = Main.DEFAULT_STORE_NAME; |
| 37 } |
| 38 File storeFile = Utils.checkFileForName(storeName); |
| 39 if (storeFile != null) { |
| 40 Utils.printInfoMessageNoEOL("Opening project database... "); |
| 41 Map<String,PCDEntry> pcd; |
| 42 if (textFormat) { |
| 43 pcd = new TextProjectDatabaseReader().readProjectDatabaseFromFil
e(storeFile); |
| 44 } else { |
| 45 pcd = new BinaryProjectDatabaseReader().readProjectDatabaseFromF
ile(storeFile); |
| 46 } |
| 47 PCDContainer pcdc = new PCDContainer(pcd, storeName, textFormat); |
| 48 Utils.printInfoMessage("Done."); |
| 49 return pcdc; |
| 50 } |
| 51 return new PCDContainer(null, storeName, textFormat); |
| 52 } |
| 53 |
| 54 public void save() { |
| 55 Utils.printInfoMessageNoEOL("Writing project database... "); |
| 56 File outfile = new File(storeName); |
| 57 if (textFormat) { |
| 58 new TextProjectDatabaseWriter().writeProjectDatabaseToFile(outfile,
pcd); |
| 59 } else { |
| 60 new BinaryProjectDatabaseWriter().writeProjectDatabaseToFile(outfile
, pcd); |
| 61 } |
| 62 Utils.printInfoMessage("Done."); |
| 63 } |
| 64 } |
OLD | NEW |