rdonkin 2003/07/13 14:28:24 Modified: betwixt/src/java/org/apache/commons/betwixt/io BeanRuleSet.java BeanWriter.java Log: Added support for simple reading of beans with mixed content. Patch submitted by Aslak Hellesoy. Revision Changes Path 1.7 +41 -9 jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/io/BeanRuleSet.java Index: BeanRuleSet.java =================================================================== RCS file: /home/cvs/jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/io/BeanRuleSet.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- BeanRuleSet.java 1 Jul 2003 19:10:45 -0000 1.6 +++ BeanRuleSet.java 13 Jul 2003 21:28:24 -0000 1.7 @@ -67,6 +67,7 @@ import org.apache.commons.betwixt.AttributeDescriptor; import org.apache.commons.betwixt.ElementDescriptor; +import org.apache.commons.betwixt.TextDescriptor; import org.apache.commons.betwixt.XMLBeanInfo; import org.apache.commons.betwixt.XMLIntrospector; import org.apache.commons.betwixt.digester.XMLIntrospectorHelper; @@ -314,7 +315,9 @@ if (childDescriptor.isWrapCollectionsInElement()) { path += '/' + grandChildQName; if (log.isTraceEnabled()) { - log.trace("Descriptor wraps elements in collection, path:" + path); + log.trace( + "Descriptor wraps elements in collection, path:" + + path); } } else { @@ -322,8 +325,8 @@ + (prefix.endsWith("/")?"":"/") + grandChildQName; if (log.isTraceEnabled()) { log.trace( - "Descriptor does not wrap elements in collection, path:" - + path); + "Descriptor does not wrap elements in collection, path:" + + path); } } } @@ -664,7 +667,35 @@ } } } - + + /** + * Called by digester with the (concatinated) body text. + * + * @param text the String comprising all the body text + */ + public void body(String text) { + + log.trace("Body with text " + text); + if ( digester.getCount() > 0 ) { + Context bodyContext = context.newContext( digester.peek() ); + // Take the first content descriptor + ElementDescriptor typeDescriptor = getElementDescriptor( descriptor ); + TextDescriptor descriptor = typeDescriptor.getPrimaryBodyTextDescriptor(); + if ( descriptor != null ) { + if ( log.isTraceEnabled() ) { + log.trace("Setting mixed content for:"); + log.trace(descriptor); + } + Updater updater = descriptor.getUpdater(); + log.trace( "Updating mixed content with:" ); + log.trace( updater ); + if ( updater != null && text != null ) { + updater.update( bodyContext, text ); + } + } + } + } + /** * Process the end of this element. */ @@ -766,6 +797,7 @@ } catch (Exception e) { log.warn( "Could not create instance of type: " + theClass.getName() ); + log.debug( "Create new instance failed: ", e ); return null; } } 1.18 +7 -6 jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/io/BeanWriter.java Index: BeanWriter.java =================================================================== RCS file: /home/cvs/jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/io/BeanWriter.java,v retrieving revision 1.17 retrieving revision 1.18 diff -u -r1.17 -r1.18 --- BeanWriter.java 11 Apr 2003 21:47:12 -0000 1.17 +++ BeanWriter.java 13 Jul 2003 21:28:24 -0000 1.18 @@ -169,8 +169,9 @@ * and allows encoding to be set.</p> * * @param out write out representations to this stream - * @param end the name of the encoding to be used. This should be compatible + * @param enc the name of the encoding to be used. This should be compatible * with the encoding types described in <code>java.io</code> + * @throws UnsupportedEncodingException if the given encoding is not supported */ public BeanWriter(OutputStream out, String enc) throws UnsupportedEncodingException { this.writer = new BufferedWriter( new OutputStreamWriter( out, enc ) );
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]