KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > apt > pluggable > core > filer > IdeOutputFileObject


1 /*******************************************************************************
2  * Copyright (c) 2007 BEA Systems, Inc.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * wharley@bea.com - initial API and implementation
10  *******************************************************************************/

11
12 package org.eclipse.jdt.internal.apt.pluggable.core.filer;
13
14 import java.io.IOException JavaDoc;
15 import java.io.InputStream JavaDoc;
16 import java.io.OutputStream JavaDoc;
17 import java.io.PrintWriter JavaDoc;
18 import java.io.Reader JavaDoc;
19 import java.io.Writer JavaDoc;
20 import java.net.URI JavaDoc;
21 import java.util.Collection JavaDoc;
22 import java.util.Set JavaDoc;
23
24 import javax.tools.FileObject;
25 import javax.tools.JavaFileManager.Location;
26
27 import org.eclipse.core.resources.IFile;
28 import org.eclipse.jdt.internal.apt.pluggable.core.dispatch.IdeProcessingEnvImpl;
29
30 /**
31  * Implementation of FileObject for generating resource files in the IDE.
32  * This is used for files that are neither class files nor Java source files.
33  * TODO: at present this represents a write-only (generated) file. When we
34  * implement the openResource() calls in Filer, we may want to move some of
35  * these methods into a base class.
36  * @see IdeOutputJavaFileObject
37  */

38 public class IdeOutputFileObject implements FileObject
39 {
40     private final IdeProcessingEnvImpl _env;
41     private final IFile _file;
42     private final Collection JavaDoc<IFile> _parentFiles;
43
44
45     /**
46      * Create a new IdeOutputFileObject for writing. The file will not actually be written until the Writer or OutputStream is closed.
47      * @param env among other roles, the ProcessingEnvironment tracks what files have been generated in a given build.
48      * @param location must be an output location (see {@link Location#isOutputLocation()}).
49      * @param pkg
50      * @param relativeName
51      * @param parentFiles
52      * @see javax.tools.StandardLocation
53      */

54     public IdeOutputFileObject(IdeProcessingEnvImpl env, IFile file, Set JavaDoc<IFile> parentFiles) {
55         _env = env;
56         _file = file;
57         _parentFiles = parentFiles;
58     }
59
60     /* (non-Javadoc)
61      * @see javax.tools.FileObject#delete()
62      */

63     @Override JavaDoc
64     public boolean delete()
65     {
66         throw new UnsupportedOperationException JavaDoc("Deleting a generated file is not permitted");
67     }
68
69     /* (non-Javadoc)
70      * @see javax.tools.FileObject#getCharContent(boolean)
71      */

72     @Override JavaDoc
73     public CharSequence JavaDoc getCharContent(boolean ignoreEncodingErrors) throws IOException JavaDoc
74     {
75         throw new UnsupportedOperationException JavaDoc("Reading a generated file is not permitted");
76     }
77
78     /* (non-Javadoc)
79      * @see javax.tools.FileObject#getLastModified()
80      */

81     @Override JavaDoc
82     public long getLastModified()
83     {
84         throw new UnsupportedOperationException JavaDoc("Not yet implemented");
85     }
86
87     /* (non-Javadoc)
88      * @see javax.tools.FileObject#getName()
89      */

90     @Override JavaDoc
91     public String JavaDoc getName()
92     {
93         // TODO
94
throw new UnsupportedOperationException JavaDoc("Not yet implemented");
95     }
96
97     /* (non-Javadoc)
98      * @see javax.tools.FileObject#openInputStream()
99      */

100     @Override JavaDoc
101     public InputStream JavaDoc openInputStream() throws IOException JavaDoc
102     {
103         throw new UnsupportedOperationException JavaDoc("Reading a generated file is not permitted");
104     }
105
106     /* (non-Javadoc)
107      * @see javax.tools.FileObject#openOutputStream()
108      */

109     @Override JavaDoc
110     public OutputStream JavaDoc openOutputStream() throws IOException JavaDoc
111     {
112         return new IdeNonSourceOutputStream(_env, _file, _parentFiles);
113     }
114
115     /* (non-Javadoc)
116      * @see javax.tools.FileObject#openReader(boolean)
117      */

118     @Override JavaDoc
119     public Reader JavaDoc openReader(boolean ignoreEncodingErrors) throws IOException JavaDoc
120     {
121         throw new UnsupportedOperationException JavaDoc("Reading a generated file is not permitted");
122     }
123
124     /* (non-Javadoc)
125      * @see javax.tools.FileObject#openWriter()
126      */

127     @Override JavaDoc
128     public Writer JavaDoc openWriter() throws IOException JavaDoc
129     {
130         return new PrintWriter JavaDoc(openOutputStream());
131     }
132
133     /* (non-Javadoc)
134      * @see javax.tools.FileObject#toUri()
135      */

136     @Override JavaDoc
137     public URI JavaDoc toUri()
138     {
139         // TODO
140
throw new UnsupportedOperationException JavaDoc("Not yet implemented");
141     }
142
143 }
144
Popular Tags