📄 abstractbeanwriter.java
字号:
}
popBean();
}
}
}
log.trace( "Finished writing bean graph." );
}
/**
* Get <code>IDGenerator</code> implementation used to
* generate <code>ID</code> attribute values .
*
* @return implementation used for <code>ID</code> attribute generation
*/
public IDGenerator getIdGenerator() {
return idGenerator;
}
/**
* Set <code>IDGenerator</code> implementation
* used to generate <code>ID</code> attribute values.
* This property can be used to customize the algorithm used for generation.
*
* @param idGenerator use this implementation for <code>ID</code> attribute generation
*/
public void setIdGenerator(IDGenerator idGenerator) {
this.idGenerator = idGenerator;
}
/**
* Gets the dynamic configuration setting to be used for bean reading.
* @return the BindingConfiguration settings, not null
* @since 0.5
*/
public BindingConfiguration getBindingConfiguration() {
return bindingConfiguration;
}
/**
* Sets the dynamic configuration setting to be used for bean reading.
* @param bindingConfiguration the BindingConfiguration settings, not null
* @since 0.5
*/
public void setBindingConfiguration(BindingConfiguration bindingConfiguration) {
this.bindingConfiguration = bindingConfiguration;
}
/**
* <p>Should generated <code>ID</code> attribute values be added to the elements?</p>
*
* <p>If IDs are not being written then if a cycle is encountered in the bean graph,
* then a {@link CyclicReferenceException} will be thrown by the write method.</p>
*
* @return true if <code>ID</code> and <code>IDREF</code> attributes are to be written
* @deprecated 0.5 use {@link BindingConfiguration#getMapIDs}
*/
public boolean getWriteIDs() {
return getBindingConfiguration().getMapIDs();
}
/**
* Set whether generated <code>ID</code> attribute values should be added to the elements
* If this property is set to false, then <code>CyclicReferenceException</code>
* will be thrown whenever a cyclic occurs in the bean graph.
*
* @param writeIDs true if <code>ID</code>'s and <code>IDREF</code>'s should be written
* @deprecated 0.5 use {@link BindingConfiguration#setMapIDs}
*/
public void setWriteIDs(boolean writeIDs) {
getBindingConfiguration().setMapIDs( writeIDs );
}
/**
* <p>Gets whether empty elements should be written into the output.</p>
*
* <p>An empty element is one that has no attributes, no child elements
* and no body text.
* For example, <code><element/></code> is an empty element but
* <code><element attr='value'/></code> is not.</p>
*
* @return true if empty elements will be written into the output
* @since 0.5
*/
public boolean getWriteEmptyElements() {
return writeEmptyElements;
}
/**
* <p>Sets whether empty elements should be written into the output.</p>
*
* <p>An empty element is one that has no attributes, no child elements
* and no body text.
* For example, <code><element/></code> is an empty element but
* <code><element attr='value'/></code> is not.
*
* @param writeEmptyElements true if empty elements should be written into the output
* @since 0.5
*/
public void setWriteEmptyElements(boolean writeEmptyElements) {
this.writeEmptyElements = writeEmptyElements;
}
/**
* <p>Gets the introspector used.</p>
*
* <p>The {@link XMLBeanInfo} used to map each bean is
* created by the <code>XMLIntrospector</code>.
* One way in which the mapping can be customized is
* by altering the <code>XMLIntrospector</code>. </p>
*
* @return the <code>XMLIntrospector</code> used for introspection
*/
public XMLIntrospector getXMLIntrospector() {
return introspector;
}
/**
* <p>Sets the introspector to be used.</p>
*
* <p>The {@link XMLBeanInfo} used to map each bean is
* created by the <code>XMLIntrospector</code>.
* One way in which the mapping can be customized is by
* altering the <code>XMLIntrospector</code>. </p>
*
* @param introspector use this introspector
*/
public void setXMLIntrospector(XMLIntrospector introspector) {
this.introspector = introspector;
}
/**
* <p>Gets the current logging implementation.</p>
*
* @return the <code>Log</code> implementation which this class logs to
*/
public final Log getAbstractBeanWriterLog() {
return log;
}
/**
* <p> Set the current logging implementation. </p>
*
* @param log <code>Log</code> implementation to use
*/
public final void setAbstractBeanWriterLog(Log log) {
this.log = log;
}
// SAX-style methods
//-------------------------------------------------------------------------
/**
* Writes the start tag for an element.
*
* @param uri the element's namespace uri
* @param localName the element's local name
* @param qName the element's qualified name
* @param attr the element's attributes
*
* @throws IOException if an IO problem occurs during writing
* @throws SAXException if an SAX problem occurs during writing
* @since 0.5
*/
protected void startElement(
WriteContext context,
String uri,
String localName,
String qName,
Attributes attr)
throws
IOException,
SAXException {
// for backwards compatbility call older methods
startElement(uri, localName, qName, attr);
}
/**
* Writes the end tag for an element
*
* @param uri the element's namespace uri
* @param localName the element's local name
* @param qName the element's qualified name
*
* @throws IOException if an IO problem occurs during writing
* @throws SAXException if an SAX problem occurs during writing
* @since 0.5
*/
protected void endElement(
WriteContext context,
String uri,
String localName,
String qName)
throws
IOException,
SAXException {
// for backwards compatibility call older interface
endElement(uri, localName, qName);
}
/**
* Writes body text
*
* @param text the body text to be written
*
* @throws IOException if an IO problem occurs during writing
* @throws SAXException if an SAX problem occurs during writing
* @since 0.5
*/
protected void bodyText(WriteContext context, String text)
throws IOException, SAXException {
// for backwards compatibility call older interface
bodyText(text);
}
// Older SAX-style methods
//-------------------------------------------------------------------------
/**
* Writes the start tag for an element.
*
* @param uri the element's namespace uri
* @param localName the element's local name
* @param qName the element's qualified name
* @param attr the element's attributes
*
* @throws IOException if an IO problem occurs during writing
* @throws SAXException if an SAX problem occurs during writing
* @deprecated 0.5 use {@link #startElement(WriteContext, String, String, String, Attributes)}
*/
protected void startElement(
String uri,
String localName,
String qName,
Attributes attr)
throws
IOException,
SAXException {}
/**
* Writes the end tag for an element
*
* @param uri the element's namespace uri
* @param localName the element's local name
* @param qName the element's qualified name
*
* @throws IOException if an IO problem occurs during writing
* @throws SAXException if an SAX problem occurs during writing
* @deprecated 0.5 use {@link #endElement(WriteContext, String, String, String)}
*/
protected void endElement(
String uri,
String localName,
String qName)
throws
IOException,
SAXException {}
/**
* Writes body text
*
* @param text the body text to be written
*
* @throws IOException if an IO problem occurs during writing
* @throws SAXException if an SAX problem occurs during writing
* @deprecated 0.5 use {@link #bodyText(WriteContext, String)}
*/
protected void bodyText(String text) throws IOException, SAXException {}
// Implementation methods
//-------------------------------------------------------------------------
/**
* Writes the given element
*
* @param namespaceUri the namespace uri
* @param localName the local name
* @param qualifiedName qualified name to use for the element
* @param elementDescriptor the <code>ElementDescriptor</code> describing the element
* @param context the <code>Context</code> to use to evaluate the bean expressions
* @throws IOException if an IO problem occurs during writing
* @throws SAXException if an SAX problem occurs during writing
* @throws IntrospectionException if a java beans introspection problem occurs
*/
private void writeElement(
String namespaceUri,
String localName,
String qualifiedName,
ElementDescriptor elementDescriptor,
Context context )
throws
IOException,
SAXException,
IntrospectionException {
if( log.isTraceEnabled() ) {
log.trace( "Writing: " + qualifiedName + " element: " + elementDescriptor );
}
if ( !ignoreElement( elementDescriptor, context )) {
if ( log.isTraceEnabled() ) {
log.trace( "Element " + elementDescriptor + " is empty." );
}
Attributes attributes = addNamespaceDeclarations(
new ElementAttributes( elementDescriptor, context ), namespaceUri);
writeContext.setCurrentDescriptor(elementDescriptor);
startElement(
writeContext,
namespaceUri,
localName,
qualifiedName,
attributes);
writeElementContent( elementDescriptor, context ) ;
writeContext.setCurrentDescriptor(elementDescriptor);
endElement( writeContext, namespaceUri, localName, qualifiedName );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -