View Javadoc

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.util.Hashtable;
24  
25  /**
26   * <p>
27   *
28   * Singleton that handles holding references to JavaFiles. This allows
29   * Alexandria to lookup and see if a file has already been parsed out and then
30   * it can load the information from memory instead of reparsing the file. </p>
31   * <p>
32   *
33   * Note. This assumes that the file will not be modified on disk while
34   * Alexandria is running. </p>
35   */
36  public class FileManager
37  {
38  
39      /**
40       * The Singleton instance of this FileManager
41       */
42      private static FileManager instance = new FileManager();
43  
44      private Hashtable files = new Hashtable();
45  
46      private String encoding = null;
47  
48      /**
49       * Get an instance of the FileManager
50       */
51      public static FileManager getInstance()
52      {
53          return instance;
54      }
55  
56      /**
57       * Get a file from it's name. If the file does not exist within the
58       * FileManager, create a new one and return it.
59       */
60      public JavaFile getFile( String name )
61          throws IOException
62      {
63  
64          JavaFile real = (JavaFile) this.files.get( name );
65  
66          if ( real == null )
67          {
68              real = new JavaFileImpl( name, this.getEncoding() );
69              this.addFile( real );
70          }
71  
72          return real;
73      }
74  
75      /**
76       * Add a file to this filemanager.
77       */
78      public void addFile( JavaFile file )
79      {
80          this.files.put( file.getFilename(), file );
81      }
82  
83      /**
84       * Encoding is the encoding of source files.
85       *
86       * @param encoding encoding of source files
87       */
88      public void setEncoding( String encoding )
89      {
90          this.encoding = encoding;
91      }
92  
93      /**
94       * see setEncoding(String)
95       *
96       * @see #setEncoding(String)
97       */
98      public String getEncoding()
99      {
100         return encoding;
101     }
102 }