1 package org.apache.maven.jxr.pacman; 2 3 /* 4 * Licensed to the Apache Software Foundation (ASF) under one 5 * or more contributor license agreements. See the NOTICE file 6 * distributed with this work for additional information 7 * regarding copyright ownership. The ASF licenses this file 8 * to you under the Apache License, Version 2.0 (the 9 * "License"); you may not use this file except in compliance 10 * with the License. You may obtain a copy of the License at 11 * 12 * http://www.apache.org/licenses/LICENSE-2.0 13 * 14 * Unless required by applicable law or agreed to in writing, 15 * software distributed under the License is distributed on an 16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 * KIND, either express or implied. See the License for the 18 * specific language governing permissions and limitations 19 * under the License. 20 */ 21 22 import java.io.IOException; 23 import java.nio.file.Path; 24 import java.util.HashMap; 25 import java.util.Map; 26 27 /** 28 * <p> 29 * 30 * Singleton that handles holding references to JavaFiles. This allows 31 * Alexandria to lookup and see if a file has already been parsed out and then 32 * it can load the information from memory instead of reparsing the file. </p> 33 * <p> 34 * 35 * Note. This assumes that the file will not be modified on disk while 36 * Alexandria is running. </p> 37 */ 38 public class FileManager 39 { 40 /** 41 * The Singleton instance of this FileManager 42 */ 43 private static FileManagerManager.html#FileManager">FileManager instance = new FileManager(); 44 45 private Map<Path, JavaFile> files = new HashMap<>(); 46 47 private String encoding = null; 48 49 /** 50 * Get an instance of the FileManager 51 */ 52 public static FileManager getInstance() 53 { 54 return instance; 55 } 56 57 /** 58 * Get a file from it's name. If the file does not exist within the 59 * FileManager, create a new one and return it. 60 */ 61 public JavaFile getFile( Path path ) 62 throws IOException 63 { 64 65 JavaFile real = this.files.get( path ); 66 67 if ( real == null ) 68 { 69 real = new JavaFileImpl( path, this.getEncoding() ); 70 this.addFile( real ); 71 } 72 73 return real; 74 } 75 76 /** 77 * Add a file to this filemanager. 78 */ 79 public void addFile( JavaFile file ) 80 { 81 this.files.put( file.getPath(), file ); 82 } 83 84 /** 85 * Encoding is the encoding of source files. 86 * 87 * @param encoding encoding of source files 88 */ 89 public void setEncoding( String encoding ) 90 { 91 this.encoding = encoding; 92 } 93 94 /** 95 * see setEncoding(String) 96 * 97 * @see #setEncoding(String) 98 */ 99 public String getEncoding() 100 { 101 return encoding; 102 } 103 }