Top Description Inners Fields Constructors Methods
net.sf.ehcache.config.generator.model

public Class XMLGeneratorVisitor

extends AbstractDepthFirstVisitor
Class Inheritance
Imports
java.io.PrintWriter, java.util.HashMap, .List, .Map

Implementation of an ElementVisitor extending from AbstractDepthFirstVisitor which can generate XML out of a NodeElement. Accepts a PrintWriter in the constructor and uses it to output the generated XML. Output can be controlled by enabling/disabling the various options present in OutputBehavior by calling enableOutputBehavior(OutputBehavior) or disableOutputBehavior(OutputBehavior)
Author
Abhishek Sanoujam

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static enum
XMLGeneratorVisitor.OutputBehavior

Enum controlling the generated XML output

Field Summary

Modifier and TypeField and Description
private final Map<XMLGeneratorVisitor.OutputBehavior, Boolean>
private int
private final PrintWriter
private NodeElement
private static final String
private boolean

Constructor Summary

AccessConstructor and Description
public
XMLGeneratorVisitor(PrintWriter out)

Constructor accepting the PrintWriter.

Method Summary

Modifier and TypeMethod and Description
public void
disableAllOutputBehaviors()

Disables all output behaviors

public void
public void
enableAllOutputBehaviors()

Enables all output behaviors

public void
protected void
endAttributes(NodeElement
the element
element
)

Overrides net.sf.ehcache.config.generator.model.AbstractDepthFirstVisitor.endAttributes.

Finish visiting attributes of the element.
protected void
endChildren(NodeElement
the element
element
)

Overrides net.sf.ehcache.config.generator.model.AbstractDepthFirstVisitor.endChildren.

Finish visiting children of the element.
protected void
private void
private void
public boolean

Returns:

true if enabled, otherwise false
isOutputBehaviorEnabled
(XMLGeneratorVisitor.OutputBehavior
the output behavior to inspect
behavior
)

Returns true if the output behavior is enabled

private void
private void
private String
protected void
startAttributes(NodeElement
the element
element
)

Overrides net.sf.ehcache.config.generator.model.AbstractDepthFirstVisitor.startAttributes.

Starts visiting the attributes of the element.
protected void
startChildren(NodeElement
the element
element
)

Overrides net.sf.ehcache.config.generator.model.AbstractDepthFirstVisitor.startChildren.

Starts visiting children of the element.
protected void
protected void
visitAttribute(NodeElement element, NodeAttribute attribute)

Visits an attribute.

protected void
visitAttributes(NodeElement
the element
element
,
List<NodeAttribute>
the attributes
attributes
)

Overrides net.sf.ehcache.config.generator.model.AbstractDepthFirstVisitor.visitAttributes.

Visits the attributes of the element.
protected void
Inherited from net.sf.ehcache.config.generator.model.AbstractDepthFirstVisitor:
visit

Field Detail

enabledOutputBehaviorsback to summary
private final Map<XMLGeneratorVisitor.OutputBehavior, Boolean> enabledOutputBehaviors
indentback to summary
private int indent
outback to summary
private final PrintWriter out
rootElementback to summary
private NodeElement rootElement
SPACERback to summary
private static final String SPACER
visitedFirstElementback to summary
private boolean visitedFirstElement

Constructor Detail

XMLGeneratorVisitorback to summary
public XMLGeneratorVisitor(PrintWriter out)

Constructor accepting the PrintWriter. All output behaviors are enabled by default.

Parameters
out:PrintWriter

the PrintWriter

Method Detail

disableAllOutputBehaviorsback to summary
public void disableAllOutputBehaviors()

Disables all output behaviors

disableOutputBehaviorback to summary
public void disableOutputBehavior(XMLGeneratorVisitor.OutputBehavior behavior)

Disables one particular OutputBehavior

enableAllOutputBehaviorsback to summary
public void enableAllOutputBehaviors()

Enables all output behaviors

enableOutputBehaviorback to summary
public void enableOutputBehavior(XMLGeneratorVisitor.OutputBehavior behavior)

Enables one particular OutputBehavior

endAttributesback to summary
protected void endAttributes(NodeElement element)

Overrides net.sf.ehcache.config.generator.model.AbstractDepthFirstVisitor.endAttributes.

Doc from net.sf.ehcache.config.generator.model.AbstractDepthFirstVisitor.endAttributes.

Finish visiting attributes of the element. Override as needed

Parameters
element:NodeElement

the element

Annotations
@Override
endChildrenback to summary
protected void endChildren(NodeElement element)

Overrides net.sf.ehcache.config.generator.model.AbstractDepthFirstVisitor.endChildren.

Doc from net.sf.ehcache.config.generator.model.AbstractDepthFirstVisitor.endChildren.

Finish visiting children of the element. Override as needed

Parameters
element:NodeElement

the element

Annotations
@Override
endElementback to summary
protected void endElement(NodeElement element)

Overrides net.sf.ehcache.config.generator.model.AbstractDepthFirstVisitor.endElement.

Doc from net.sf.ehcache.config.generator.model.AbstractDepthFirstVisitor.endElement.

Finish visiting the element. Override as needed

Parameters
element:NodeElement

the element

Annotations
@Override
indentBackwardback to summary
private void indentBackward()
indentForwardback to summary
private void indentForward()
isOutputBehaviorEnabledback to summary
public boolean isOutputBehaviorEnabled(XMLGeneratorVisitor.OutputBehavior behavior)

Returns true if the output behavior is enabled

Parameters
behavior:XMLGeneratorVisitor.OutputBehavior

the output behavior to inspect

Returns:boolean

true if enabled, otherwise false

newLineback to summary
private void newLine()
printWithoutSpacerback to summary
private void printWithoutSpacer(String string)
spacerback to summary
private String spacer()
startAttributesback to summary
protected void startAttributes(NodeElement element)

Overrides net.sf.ehcache.config.generator.model.AbstractDepthFirstVisitor.startAttributes.

Doc from net.sf.ehcache.config.generator.model.AbstractDepthFirstVisitor.startAttributes.

Starts visiting the attributes of the element. Override as needed

Parameters
element:NodeElement

the element

Annotations
@Override
startChildrenback to summary
protected void startChildren(NodeElement element)

Overrides net.sf.ehcache.config.generator.model.AbstractDepthFirstVisitor.startChildren.

Doc from net.sf.ehcache.config.generator.model.AbstractDepthFirstVisitor.startChildren.

Starts visiting children of the element. Override as needed

Parameters
element:NodeElement

the element

Annotations
@Override
startElementback to summary
protected void startElement(NodeElement element)

Overrides net.sf.ehcache.config.generator.model.AbstractDepthFirstVisitor.startElement.

Doc from net.sf.ehcache.config.generator.model.AbstractDepthFirstVisitor.startElement.

Starts visiting an element. Override as needed

Parameters
element:NodeElement

the element

Annotations
@Override
visitAttributeback to summary
protected void visitAttribute(NodeElement element, NodeAttribute attribute)

Visits an attribute.

visitAttributesback to summary
protected void visitAttributes(NodeElement element, List<NodeAttribute> attributes)

Overrides net.sf.ehcache.config.generator.model.AbstractDepthFirstVisitor.visitAttributes.

Doc from net.sf.ehcache.config.generator.model.AbstractDepthFirstVisitor.visitAttributes.

Visits the attributes of the element. Override as needed

Parameters
element:NodeElement

the element

attributes:List<NodeAttribute>

the attributes

Annotations
@Override
visitElementback to summary
protected void visitElement(NodeElement element)

Overrides net.sf.ehcache.config.generator.model.AbstractDepthFirstVisitor.visitElement.

Doc from net.sf.ehcache.config.generator.model.AbstractDepthFirstVisitor.visitElement.

Visits the element. Override as needed

Parameters
element:NodeElement

the element

Annotations
@Override
net.sf.ehcache.config.generator.model back to summary

public final Enum XMLGeneratorVisitor.OutputBehavior

extends Enum<XMLGeneratorVisitor.OutputBehavior>
Class Inheritance

Enum controlling the generated XML output
Author
Abhishek Sanoujam

Field Summary

Modifier and TypeField and Description
public static final XMLGeneratorVisitor.OutputBehavior
INDENT_CHIlD_ELEMENTS

Output behavior controlling whether child elements should be indented or not

public static final XMLGeneratorVisitor.OutputBehavior
NEWLINE_AT_END

Output behavior controlling whether new lines should be added at the end or not

public static final XMLGeneratorVisitor.OutputBehavior
NEWLINE_FOR_EACH_ATTRIBUTE

Output behavior controlling whether new lines should be added for each attribute

public static final XMLGeneratorVisitor.OutputBehavior
NEWLINE_FOR_EACH_ELEMENT

Output behavior controlling whether new lines should be added for each child element

public static final XMLGeneratorVisitor.OutputBehavior
OUTPUT_OPTIONAL_ATTRIBUTES_WITH_DEFAULT_VALUES

Output behavior controlling whether optional attributes having default values should be generated or not

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static XMLGeneratorVisitor.OutputBehavior
public static XMLGeneratorVisitor.OutputBehavior[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

INDENT_CHIlD_ELEMENTSback to summary
public static final XMLGeneratorVisitor.OutputBehavior INDENT_CHIlD_ELEMENTS

Output behavior controlling whether child elements should be indented or not

NEWLINE_AT_ENDback to summary
public static final XMLGeneratorVisitor.OutputBehavior NEWLINE_AT_END

Output behavior controlling whether new lines should be added at the end or not

NEWLINE_FOR_EACH_ATTRIBUTEback to summary
public static final XMLGeneratorVisitor.OutputBehavior NEWLINE_FOR_EACH_ATTRIBUTE

Output behavior controlling whether new lines should be added for each attribute

NEWLINE_FOR_EACH_ELEMENTback to summary
public static final XMLGeneratorVisitor.OutputBehavior NEWLINE_FOR_EACH_ELEMENT

Output behavior controlling whether new lines should be added for each child element

OUTPUT_OPTIONAL_ATTRIBUTES_WITH_DEFAULT_VALUESback to summary
public static final XMLGeneratorVisitor.OutputBehavior OUTPUT_OPTIONAL_ATTRIBUTES_WITH_DEFAULT_VALUES

Output behavior controlling whether optional attributes having default values should be generated or not

Constructor Detail

OutputBehaviorback to summary
private OutputBehavior()

Method Detail

valueOfback to summary
public static XMLGeneratorVisitor.OutputBehavior valueOf(String name)
valuesback to summary
public static XMLGeneratorVisitor.OutputBehavior[] values()