rdonkin 01/12/18 11:54:17
Modified: betwixt/src/java/org/apache/commons/betwixt/io
BeanWriter.java
Log:
Added XMLIntrospector getter and setting (also a test of karma)
Revision Changes Path
1.8 +58 -7
jakarta-commons-sandbox/betwixt/src/java/org/apache/commons/betwixt/io/BeanWriter.java
Index: BeanWriter.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/betwixt/src/java/org/apache/commons/betwixt/io/BeanWriter.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- BeanWriter.java 2001/12/11 06:43:55 1.7
+++ BeanWriter.java 2001/12/18 19:54:17 1.8
@@ -5,7 +5,7 @@
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE file.
*
- * $Id: BeanWriter.java,v 1.7 2001/12/11 06:43:55 sanders Exp $
+ * $Id: BeanWriter.java,v 1.8 2001/12/18 19:54:17 rdonkin Exp $
*/
package org.apache.commons.betwixt.io;
@@ -42,7 +42,7 @@
* The indent string used is set by {@link #setIndent}.
*
* @author <a href="mailto:[EMAIL PROTECTED]">James Strachan</a>
- * @version $Revision: 1.7 $
+ * @version $Revision: 1.8 $
*/
public class BeanWriter {
@@ -109,6 +109,7 @@
/**
* <p> Switch on formatted output.
+ * This sets the end of line and the indent.
*/
public void enablePrettyPrint() {
endOfLine = "\n";
@@ -135,12 +136,41 @@
this.indent = indent;
}
+
+ /**
+ * <p> Get 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>
+ */
+ public XMLIntrospector getXMLIntrospector() {
+ return introspector;
+ }
+
+ /**
+ * <p> Set 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;
+ }
+
+
// Implementation methods
//-------------------------------------------------------------------------
/** Writes the given bean to the current stream using the given
<code>qualifiedName</code> */
- public void write(String qualifiedName, Object bean) throws IOException,
IntrospectionException {
+ public void write(
+ String qualifiedName,
+ Object bean)
+ throws
+ IOException,
+ IntrospectionException {
XMLBeanInfo beanInfo = introspector.introspect( bean );
if ( beanInfo != null ) {
ElementDescriptor elementDescriptor = beanInfo.getElementDescriptor();
@@ -154,8 +184,15 @@
}
}
+
/** Writes the given element */
- protected void write( String qualifiedName, ElementDescriptor
elementDescriptor, Context context ) throws IOException, IntrospectionException {
+ protected void write(
+ String qualifiedName,
+ ElementDescriptor elementDescriptor,
+ Context context )
+ throws
+ IOException,
+ IntrospectionException {
writePrintln();
writeIndent();
writer.write( "<" );
@@ -176,7 +213,12 @@
*
* @return true if some content was written
*/
- protected boolean writeContent( ElementDescriptor elementDescriptor, Context
context ) throws IOException, IntrospectionException {
+ protected boolean writeContent(
+ ElementDescriptor elementDescriptor,
+ Context context )
+ throws
+ IOException,
+ IntrospectionException {
boolean answer = false;
ElementDescriptor[] childDescriptors =
elementDescriptor.getElementDescriptors();
if ( childDescriptors != null && childDescriptors.length > 0 ) {
@@ -228,7 +270,11 @@
}
/** Writes the attribute declarations */
- protected void writeAttributes( ElementDescriptor elementDescriptor, Context
context ) throws IOException {
+ protected void writeAttributes(
+ ElementDescriptor elementDescriptor,
+ Context context )
+ throws
+ IOException {
AttributeDescriptor[] attributeDescriptors =
elementDescriptor.getAttributeDescriptors();
if ( attributeDescriptors != null ) {
for ( int i = 0, size = attributeDescriptors.length; i < size; i++ ) {
@@ -237,9 +283,14 @@
}
}
}
+
/** Writes an attribute declaration */
- protected void writeAttribute( AttributeDescriptor attributeDescriptor, Context
context ) throws IOException {
+ protected void writeAttribute(
+ AttributeDescriptor attributeDescriptor,
+ Context context )
+ throws
+ IOException {
Expression expression = attributeDescriptor.getTextExpression();
if ( expression != null ) {
Object value = expression.evaluate( context );
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>