JavaWriterpublic abstract class JavaWriter extends Object implements org.apache.axis.wsdl.gen.GeneratorEmitter knows about WSDL writers, one each for PortType, Binding, Service,
Definition, Type. But for some of these WSDL types, Wsdl2java generates
multiple files. Each of these files has a corresponding writer that extends
JavaWriter. So the Java WSDL writers (JavaPortTypeWriter, JavaBindingWriter,
etc.) each calls a file writer (JavaStubWriter, JavaSkelWriter, etc.) for
each file that that WSDL generates.
For example, when Emitter calls JavaWriterFactory for a Binding Writer, it
returns a JavaBindingWriter. JavaBindingWriter, in turn, contains a
JavaStubWriter, JavaSkelWriter, and JavaImplWriter since a Binding may cause
a stub, skeleton, and impl template to be generated.
Note that the writers that are given to Emitter by JavaWriterFactory DO NOT
extend JavaWriter. They simply implement Writer and delegate the actual
task of writing to extensions of JavaWriter.
All of Wsdl2java's Writer implementations follow a common behaviour.
JavaWriter is the abstract base class that dictates this common behaviour.
This behaviour is primarily placed within the generate method. The generate
method calls, in succession (note: the starred methods are the ones you are
probably most interested in):
- * getFileName
- This is an abstract method that must be implemented by the subclass.
It returns the fully-qualified file name.
- isFileGenerated(file)
- You should not need to override this method. It checks to see whether
this file is in the List returned by emitter.getGeneratedFileNames.
- registerFile(file)
- You should not need to override this method. It registers this file by
calling emitter.getGeneratedFileInfo().add(...).
- * verboseMessage(file)
- You may override this method if you want to provide more information.
The generate method only calls verboseMessage if verbose is turned on.
- getPrintWriter(file)
- You should not need to override this method. Given the file name, it
creates a PrintWriter for it.
- * writeFileHeader(pw)
- You may want to override this method. The default implementation
generates nothing.
- * writeFileBody(pw)
- This is an abstract method that must be implemented by the subclass.
This is where the body of a file is generated.
- * writeFileFooter(pw)
- You may want to override this method. The default implementation
generates nothing.
- closePrintWriter(pw)
- You should not need to override this method. It simply closes the
PrintWriter.
|
Fields Summary |
---|
protected static final int | LINE_LENGTHThis controls how many characters per line for javadoc comments | protected Emitter | emitterField emitter | protected String | typeField type |
Constructors Summary |
---|
protected JavaWriter(Emitter emitter, String type)Constructor.
this.emitter = emitter;
this.type = type;
|
Methods Summary |
---|
protected void | closePrintWriter(java.io.PrintWriter pw)Close the print writer.
pw.close();
| public void | generate()Generate a file.
String file = getFileName();
if (isFileGenerated(file)) {
throw new DuplicateFileException(
Messages.getMessage("duplicateFile00", file), file);
}
registerFile(file);
if (emitter.isVerbose()) {
String msg = verboseMessage(file);
if (msg != null) {
System.out.println(msg);
}
}
PrintWriter pw = getPrintWriter(file);
writeFileHeader(pw);
writeFileBody(pw);
writeFileFooter(pw);
closePrintWriter(pw);
| protected abstract java.lang.String | getFileName()This method must be implemented by a subclass. It
returns the fully-qualified name of the file to be
generated.
| protected java.lang.String | getJavadocDescriptionPart(java.lang.String documentation, boolean addTab)Takes out new lines and wraps at Javadoc tags
if (documentation == null) {
return "";
}
String doc = documentation.trim();
if (documentation.trim().length() == 0) {
//nothing to do
return doc;
}
// make @ tags start a new line (for javadoc tags mostly)
StringTokenizer st = new StringTokenizer(doc, "@");
StringBuffer newComments;
if (st.hasMoreTokens()) {
String token = st.nextToken();
boolean startLine = Character.isWhitespace(token.charAt(token.length() - 1))
&& (token.charAt(token.length() - 1) != '\n");
newComments = new StringBuffer(token);
while (st.hasMoreTokens()) {
token = st.nextToken();
// don't span links across lines
if (startLine) {
newComments.append('\n");
}
newComments.append('@");
startLine = Character.isWhitespace(token.charAt(token.length() - 1))
& (token.charAt(token.length() - 1) != '\n");
newComments.append(token);
}
} else {
newComments = new StringBuffer(doc);
}
newComments.insert(0, addTab ? " * " : " * ");
// tweak comment ending tags by insterting a
// space between the star and the slash, BUG13407
int pos = newComments.toString().indexOf("*/");
while (pos >= 0) {
newComments.insert(pos + 1, ' ");
pos = newComments.toString().indexOf("*/");
}
// now pretty it up based on column length
int lineStart = 0;
int newlinePos = 0;
while (lineStart < newComments.length()) {
newlinePos = newComments.toString().indexOf("\n", lineStart);
if (newlinePos == -1) {
newlinePos = newComments.length();
}
if ((newlinePos - lineStart) > LINE_LENGTH) {
// find first whitespace after length
lineStart += LINE_LENGTH;
while ((lineStart < newComments.length())
&& !Character.isWhitespace(newComments.charAt(lineStart))) {
lineStart++;
}
if (lineStart < newComments.length()) {
// don't insert if line wold break at EOF
char next = newComments.charAt(lineStart);
// insert new line header
if ((next == '\r") || (next == '\n")) {
//newline exists at the break point, don't put in another one
newComments.insert(lineStart + 1, addTab ? " * " : " * ");
lineStart += addTab ? 8 : 4;
} else {
newComments.insert(lineStart, addTab ? "\n * " : "\n * ");
lineStart += addTab ? 8 : 4;
}
}
// chew up witespace after newline
while ((lineStart < newComments.length())
&& (newComments.charAt(lineStart) == ' ")) { // only chew up simple spaces
newComments.delete(lineStart, lineStart + 1);
}
} else {
if (++newlinePos < newComments.length()) {
newComments.insert(newlinePos, addTab ? " * " : " * ");
}
lineStart = newlinePos;
lineStart += addTab ? 7 : 3;
}
}
return newComments.toString();
| protected java.io.PrintWriter | getPrintWriter(java.lang.String filename)You should not need to override this method.
Given the file name, it creates a PrintWriter for it.
File file = new File(filename);
File parent = new File(file.getParent());
parent.mkdirs();
FileOutputStream out = new FileOutputStream(file);
OutputStreamWriter writer = new OutputStreamWriter(out, "UTF-8");
return new PrintWriter(writer);
| protected boolean | isFileGenerated(java.lang.String file)You should not need to override this method. It checks
to see whether the given file is in the List returned
by emitter.getGeneratedFileNames.
return emitter.getGeneratedFileNames().contains(file);
| protected void | registerFile(java.lang.String file)You should not need to override this method.
It registers the given file by calling
emitter.getGeneratedFileInfo().add(...).
emitter.getGeneratedFileInfo().add(file, null, type);
| protected java.lang.String | verboseMessage(java.lang.String file)Return the string: "Generating ". Override this
method if you want to provide more information.
return Messages.getMessage("generating", file);
| protected void | writeComment(java.io.PrintWriter pw, org.w3c.dom.Element element)Output a documentation element as a Java comment.
writeComment(pw, element, true);
| protected void | writeComment(java.io.PrintWriter pw, org.w3c.dom.Element element, boolean addTab)Output a documentation element as a Java comment.
if (element == null) {
return;
}
Node child = element.getFirstChild();
if (child == null) {
return;
}
String comment = child.getNodeValue();
if (comment != null) {
int start = 0;
pw.println(); // blank line
pw.println(addTab ? " /**" : "/**");
pw.println(getJavadocDescriptionPart(comment, addTab));
pw.println(addTab ? " */" : " */");
}
| protected abstract void | writeFileBody(java.io.PrintWriter pw)This method must be implemented by a subclass. This
is where the body of a file is generated.
| protected void | writeFileFooter(java.io.PrintWriter pw)You may want to override this method. This default
implementation generates nothing.
| protected void | writeFileHeader(java.io.PrintWriter pw)This method is intended to be overridden as necessary
to generate file header information. This default
implementation does nothing.
|
|