KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > jdo > spi > persistence > utility > generator > JavaFileWriter


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 /*
25  * JavaFileWriter.java
26  *
27  * Created on November 14, 2001, 5:11 PM
28  */

29
30 package com.sun.jdo.spi.persistence.utility.generator;
31
32 import java.io.IOException JavaDoc;
33
34 /**
35  * This interface can be used to describe a java source file. The resulting
36  * source definition can be viewed by calling {@link java.lang.Object#toString}
37  * or saved to a file by calling {@link #save}. The semantics of this
38  * interface are as follows:
39  * - Resource allocation is deferred to save - there is no need to worry about
40  * resource cleanup if an IOException is thrown from other methods (addImport,
41  * setPackage, addClass).
42  * - Any implementation of this interface must handle the closing of resources
43  * during save if an exception is thrown.
44  *
45  *<p>
46  * Use this interface in conjunction with one or more {@link JavaClassWriter}
47  * instances to describe the class(es) in a java file.
48  *
49  * @author raccah
50  */

51 public interface JavaFileWriter
52 {
53     /** Sets the package for this file. Note that the package name format
54      * must be package style (that is - it can contain . but not / or $).
55      * @param packageName The name of the package for this source file.
56      * @param comments The comments shown just above the package statement.
57      * The comments are passed as an array so the line separators can be added
58      * by the implementation. Note that not all implementations will choose
59      * to make use of this comment.
60      * @throws IOException If the package cannot be set.
61      */

62     public void setPackage (String JavaDoc packageName, String JavaDoc[] comments)
63         throws IOException JavaDoc;
64
65     /** Adds an import statement for this source file.
66      * @param importName Name of the class or package (including the *) to be
67      * imported. This string should not contain "import" or the ;
68      * @param comments The comments shown just above the import statement.
69      * The comments are passed as an array so the line separators can be added
70      * by the implementation. Note that not all implementations will choose
71      * to make use of this comment.
72      * @throws IOException If the import information cannot be added.
73      */

74     public void addImport (String JavaDoc importName, String JavaDoc[] comments)
75         throws IOException JavaDoc;
76
77     /** Adds a class to this source file.
78      * @param classWriter The definition of the class.
79      * @throws IOException If the class information cannot be added.
80      */

81     public void addClass (JavaClassWriter classWriter) throws IOException JavaDoc;
82
83     /** Saves the file by writing out the source contents to whatever
84      * file (or alternate representation) was specified (usually by the
85      * constructor of the implementation class.
86      * @throws IOException If the file cannot be saved.
87      */

88     public void save () throws IOException JavaDoc;
89 }
90
Popular Tags