001: /*
002: * Copyright 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.io.InputStream;
030: import java.io.OutputStream;
031: import java.io.Reader;
032: import java.io.Writer;
033: import java.net.URI;
034:
035: /**
036: * Forwards calls to a given file object. Subclasses of this class
037: * might override some of these methods and might also provide
038: * additional fields and methods.
039: *
040: * @param <F> the kind of file object forwarded to by this object
041: * @author Peter von der Ahé
042: * @since 1.6
043: */
044: public class ForwardingFileObject<F extends FileObject> implements
045: FileObject {
046:
047: /**
048: * The file object which all methods are delegated to.
049: */
050: protected final F fileObject;
051:
052: /**
053: * Creates a new instance of ForwardingFileObject.
054: * @param fileObject delegate to this file object
055: */
056: protected ForwardingFileObject(F fileObject) {
057: fileObject.getClass(); // null check
058: this .fileObject = fileObject;
059: }
060:
061: public URI toUri() {
062: return fileObject.toUri();
063: }
064:
065: public String getName() {
066: return fileObject.getName();
067: }
068:
069: /**
070: * @throws IllegalStateException {@inheritDoc}
071: * @throws UnsupportedOperationException {@inheritDoc}
072: * @throws IOException {@inheritDoc}
073: */
074: public InputStream openInputStream() throws IOException {
075: return fileObject.openInputStream();
076: }
077:
078: /**
079: * @throws IllegalStateException {@inheritDoc}
080: * @throws UnsupportedOperationException {@inheritDoc}
081: * @throws IOException {@inheritDoc}
082: */
083: public OutputStream openOutputStream() throws IOException {
084: return fileObject.openOutputStream();
085: }
086:
087: /**
088: * @throws IllegalStateException {@inheritDoc}
089: * @throws UnsupportedOperationException {@inheritDoc}
090: * @throws IOException {@inheritDoc}
091: */
092: public Reader openReader(boolean ignoreEncodingErrors)
093: throws IOException {
094: return fileObject.openReader(ignoreEncodingErrors);
095: }
096:
097: /**
098: * @throws IllegalStateException {@inheritDoc}
099: * @throws UnsupportedOperationException {@inheritDoc}
100: * @throws IOException {@inheritDoc}
101: */
102: public CharSequence getCharContent(boolean ignoreEncodingErrors)
103: throws IOException {
104: return fileObject.getCharContent(ignoreEncodingErrors);
105: }
106:
107: /**
108: * @throws IllegalStateException {@inheritDoc}
109: * @throws UnsupportedOperationException {@inheritDoc}
110: * @throws IOException {@inheritDoc}
111: */
112: public Writer openWriter() throws IOException {
113: return fileObject.openWriter();
114: }
115:
116: public long getLastModified() {
117: return fileObject.getLastModified();
118: }
119:
120: public boolean delete() {
121: return fileObject.delete();
122: }
123: }
|