001 /*
002 * Copyright 2005-2006 Sun Microsystems, Inc. All Rights Reserved.
003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004 *
005 * This code is free software; you can redistribute it and/or modify it
006 * under the terms of the GNU General Public License version 2 only, as
007 * published by the Free Software Foundation. Sun designates this
008 * particular file as subject to the "Classpath" exception as provided
009 * by Sun in the LICENSE file that accompanied this code.
010 *
011 * This code is distributed in the hope that it will be useful, but WITHOUT
012 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014 * version 2 for more details (a copy is included in the LICENSE file that
015 * accompanied this code).
016 *
017 * You should have received a copy of the GNU General Public License version
018 * 2 along with this work; if not, write to the Free Software Foundation,
019 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020 *
021 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022 * CA 95054 USA or visit www.sun.com if you need additional information or
023 * have any questions.
024 */
025
026 package javax.tools;
027
028 import java.io.IOException;
029 import java.net.URI;
030 import java.util.Iterator;
031 import java.util.Set;
032 import javax.tools.JavaFileObject.Kind;
033
034 /**
035 * Forwards calls to a given file manager. Subclasses of this class
036 * might override some of these methods and might also provide
037 * additional fields and methods.
038 *
039 * @param <M> the kind of file manager forwarded to by this object
040 * @author Peter von der Ahé
041 * @since 1.6
042 */
043 public class ForwardingJavaFileManager<M extends JavaFileManager> implements JavaFileManager {
044
045 /**
046 * The file manager which all methods are delegated to.
047 */
048 protected final M fileManager;
049
050 /**
051 * Creates a new instance of ForwardingJavaFileManager.
052 * @param fileManager delegate to this file manager
053 */
054 protected ForwardingJavaFileManager(M fileManager) {
055 fileManager.getClass(); // null check
056 this.fileManager = fileManager;
057 }
058
059 /**
060 * @throws SecurityException {@inheritDoc}
061 * @throws IllegalStateException {@inheritDoc}
062 */
063 public ClassLoader getClassLoader(Location location) {
064 return fileManager.getClassLoader(location);
065 }
066
067 /**
068 * @throws IOException {@inheritDoc}
069 * @throws IllegalStateException {@inheritDoc}
070 */
071 public Iterable<JavaFileObject> list(Location location,
072 String packageName,
073 Set<Kind> kinds,
074 boolean recurse)
075 throws IOException
076 {
077 return fileManager.list(location, packageName, kinds, recurse);
078 }
079
080 /**
081 * @throws IllegalStateException {@inheritDoc}
082 */
083 public String inferBinaryName(Location location, JavaFileObject file) {
084 return fileManager.inferBinaryName(location, file);
085 }
086
087 /**
088 * @throws IllegalArgumentException {@inheritDoc}
089 */
090 public boolean isSameFile(FileObject a, FileObject b) {
091 return fileManager.isSameFile(a, b);
092 }
093
094 /**
095 * @throws IllegalArgumentException {@inheritDoc}
096 * @throws IllegalStateException {@inheritDoc}
097 */
098 public boolean handleOption(String current, Iterator<String> remaining) {
099 return fileManager.handleOption(current, remaining);
100 }
101
102 public boolean hasLocation(Location location) {
103 return fileManager.hasLocation(location);
104 }
105
106 public int isSupportedOption(String option) {
107 return fileManager.isSupportedOption(option);
108 }
109
110 /**
111 * @throws IllegalArgumentException {@inheritDoc}
112 * @throws IllegalStateException {@inheritDoc}
113 */
114 public JavaFileObject getJavaFileForInput(Location location,
115 String className,
116 Kind kind)
117 throws IOException
118 {
119 return fileManager.getJavaFileForInput(location, className, kind);
120 }
121
122 /**
123 * @throws IllegalArgumentException {@inheritDoc}
124 * @throws IllegalStateException {@inheritDoc}
125 */
126 public JavaFileObject getJavaFileForOutput(Location location,
127 String className,
128 Kind kind,
129 FileObject sibling)
130 throws IOException
131 {
132 return fileManager.getJavaFileForOutput(location, className, kind, sibling);
133 }
134
135 /**
136 * @throws IllegalArgumentException {@inheritDoc}
137 * @throws IllegalStateException {@inheritDoc}
138 */
139 public FileObject getFileForInput(Location location,
140 String packageName,
141 String relativeName)
142 throws IOException
143 {
144 return fileManager.getFileForInput(location, packageName, relativeName);
145 }
146
147 /**
148 * @throws IllegalArgumentException {@inheritDoc}
149 * @throws IllegalStateException {@inheritDoc}
150 */
151 public FileObject getFileForOutput(Location location,
152 String packageName,
153 String relativeName,
154 FileObject sibling)
155 throws IOException
156 {
157 return fileManager.getFileForOutput(location, packageName, relativeName, sibling);
158 }
159
160 public void flush() throws IOException {
161 fileManager.flush();
162 }
163
164 public void close() throws IOException {
165 fileManager.close();
166 }
167 }