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 private Map<Path, JavaFile> files = new HashMap<>();
41
42 private String encoding = null;
43
44 /**
45 * Get a file from it's name. If the file does not exist within the
46 * FileManager, create a new one and return it.
47 */
48 public JavaFile getFile( Path path )
49 throws IOException
50 {
51
52 JavaFile real = this.files.get( path );
53
54 if ( real == null )
55 {
56 real = new JavaFileImpl( path, this.getEncoding() );
57 this.addFile( real );
58 }
59
60 return real;
61 }
62
63 /**
64 * Add a file to this filemanager.
65 */
66 public void addFile( JavaFile file )
67 {
68 this.files.put( file.getPath(), file );
69 }
70
71 /**
72 * Encoding is the encoding of source files.
73 *
74 * @param encoding encoding of source files
75 */
76 public void setEncoding( String encoding )
77 {
78 this.encoding = encoding;
79 }
80
81 /**
82 * see setEncoding(String)
83 *
84 * @see #setEncoding(String)
85 */
86 public String getEncoding()
87 {
88 return encoding;
89 }
90 }