1 /** 2 * Redistribution and use of this software and associated documentation ("Software"), with or 3 * without modification, are permitted provided that the following conditions are met: 4 * 5 * 1. Redistributions of source code must retain copyright statements and notices. Redistributions 6 * must also contain a copy of this document. 7 * 8 * 2. Redistributions in binary form must reproduce the above copyright notice, this list of 9 * conditions and the following disclaimer in the documentation and/or other materials provided with 10 * the distribution. 11 * 12 * 3. The name "Exolab" must not be used to endorse or promote products derived from this Software 13 * without prior written permission of Intalio, Inc. For written permission, please contact 14 * info@exolab.org. 15 * 16 * 4. Products derived from this Software may not be called "Exolab" nor may "Exolab" appear in 17 * their names without prior written permission of Intalio, Inc. Exolab is a registered trademark of 18 * Intalio, Inc. 19 * 20 * 5. Due credit should be given to the Exolab Project (http://www.exolab.org/). 21 * 22 * THIS SOFTWARE IS PROVIDED BY INTALIO, INC. AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESSED OR 23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 24 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTALIO, INC. OR ITS 25 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 28 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY 29 * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 * 31 * Copyright 1999-2002 (C) Intalio, Inc. All Rights Reserved. 32 * 33 * $Id$ 34 */ 35 36 package org.exolab.castor.xml.schema.reader; 37 38 import org.exolab.castor.xml.XMLException; 39 import org.exolab.castor.xml.schema.SchemaContext; 40 41 /** 42 * A utility class for Unmarshalling elements with only String content 43 * 44 * @author <a href="mailto:kvisco@intalio.com">Keith Visco</a> 45 * @version $Revision$ $Date: 2003-03-03 00:05:44 -0700 (Mon, 03 Mar 2003) $ 46 **/ 47 public class CharacterUnmarshaller extends ComponentReader { 48 49 50 private StringBuffer sb = null; 51 52 private String currentName = null; 53 54 /** 55 * Creates a new StringUnmarshaller. 56 * 57 * @param schemaContext the schema context to get some configuration settings from 58 **/ 59 public CharacterUnmarshaller(final SchemaContext schemaContext) { 60 super(schemaContext); 61 sb = new StringBuffer(); 62 } // -- CharacterUnmarshaller 63 64 /** 65 * Returns the name of the element that this ComponentReader handles 66 * 67 * @return the name of the element that this ComponentReader handles 68 **/ 69 public String elementName() { 70 return currentName; 71 } // -- elementName 72 73 /** 74 * Sets the name of the element that this CharacterUnmarshaller handles 75 * 76 * @param name the name of the element that this character unmarshaller handles 77 **/ 78 public void elementName(String name) { 79 currentName = name; 80 } // -- elementName 81 82 /** 83 * Returns the Object created by this ComponentReader 84 * 85 * @return the Object created by this ComponentReader 86 **/ 87 public Object getObject() { 88 return getString(); 89 } // -- getObject 90 91 /** 92 * Returns the set of characters recieved by this CharacterUnmarshaller as a String 93 * 94 * @return the set of characters recieved by this CharacterUnmarshaller as a String 95 **/ 96 public String getString() { 97 return sb.toString(); 98 } // -- getString 99 100 /** 101 * The SAX characters method for recieving characters 102 * 103 * @see org.xml.sax.DocumentHandler 104 **/ 105 public void characters(char[] ch, int start, int length) throws XMLException { 106 sb.append(ch, start, length); 107 } // -- characters 108 109 /** 110 * Clears the current buffer 111 **/ 112 public void clear() { 113 sb.setLength(0); 114 } // -- clear 115 116 } // -- CharacterUnmarshaller