Java的面向对象数据库系统的源代码

源代码在线查看: cxmlcontenthandler.java

软件大小: 14235 K
上传用户: fansino
关键词: Java 对象 数据库系统 源代码
下载地址: 免注册下载 普通下载 VIP

相关代码

				/*								 ============================================================================				                   The Apache Software License, Version 1.1				 ============================================================================				 				 Copyright (C) 2000 The Apache Software Foundation. All rights reserved.				 				 Redistribution and use in source and binary forms, with or without modifica-				 tion, are permitted provided that the following conditions are met:				 				 1. Redistributions of  source code must  retain the above copyright  notice,				    this list of conditions and the following disclaimer.				 				 2. Redistributions in binary form must reproduce the above copyright notice,				    this list of conditions and the following disclaimer in the documentation				    and/or other materials provided with the distribution.				 				 3. The end-user documentation included with the redistribution, if any, must				    include  the following  acknowledgment:  "This product includes  software				    developed  by the  Apache Software Foundation  (http://www.apache.org/)."				    Alternately, this  acknowledgment may  appear in the software itself,  if				    and wherever such third-party acknowledgments normally appear.				 				 4. The names "Cocoon" and  "Apache Software Foundation"  must not be used to				    endorse  or promote  products derived  from this  software without  prior				    written permission. For written permission, please contact				    apache@apache.org.				 				 5. Products  derived from this software may not  be called "Apache", nor may				    "Apache" appear  in their name,  without prior written permission  of the				    Apache Software Foundation.				 				 THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,				 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND				 FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE				 APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,				 INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-				 DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS				 OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON				 ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT				 (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF				 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.				 				 This software  consists of voluntary contributions made  by many individuals				 on  behalf of the Apache Software  Foundation and was  originally created by				 Stefano Mazzocchi  . For more  information on the Apache 				 Software Foundation, please see .				 				*/								/*				 *  $Id: CXMLContentHandler.java,v 1.8 2001/01/11 10:02:53 conny Exp $				 *				 *  This code was part of the prove of concept of a binary representation of XML				 *  called CXML send to the Cocoon users list by Stefano Mazzocchi. It was modified				 *  to support the LexicalHandler interface.				 */								package org.ozoneDB.xml.util;								import java.io.OutputStream;				import java.io.IOException;				import java.io.Serializable;								import org.xml.sax.SAXException;				import org.xml.sax.ContentHandler;				import org.xml.sax.ext.LexicalHandler;				import org.xml.sax.Attributes;				import org.xml.sax.Locator;												/**				 */				class CXMLContentHandler implements ContentHandler, LexicalHandler, Serializable {				    				    public final static boolean debug = false;				    				    public final static int START_DOCUMENT = 0;				    public final static int END_DOCUMENT = 1;				    public final static int START_PREFIX_MAPPING = 2;				    public final static int END_PREFIX_MAPPING = 3;				    public final static int START_ELEMENT = 4;				    public final static int END_ELEMENT = 5;				    public final static int CHARACTERS = 6;				    public final static int IGNORABLE_WHITESPACE = 7;				    public final static int PROCESSING_INSTRUCTION = 8;				    public final static int COMMENT = 9;				    public final static int START_CDATA = 10;				    public final static int END_CDATA = 11;				    				    private final CompiledXMLOutputStream out;				    				    				    public CXMLContentHandler( OutputStream stream ) throws IOException{				        out = new CompiledXMLOutputStream( stream );				    }				    				    				    public void startDocument() throws SAXException {				        if (debug) {				            System.out.println(this.getClass().getName() + ": startDocument()");				        }				        try {				            out.writeEvent( START_DOCUMENT );				        } catch (Exception e) {				            throw new SAXException( e );				        } 				    } 				    				    				    public void endDocument() throws SAXException {				        if (debug) {				            System.out.println(this.getClass().getName() + ": endDocument()");				        }				        try {				            out.writeEvent( END_DOCUMENT );				        } catch (Exception e) {				            throw new SAXException( e );				        } 				    } 				    				    				    public void startPrefixMapping( java.lang.String prefix, java.lang.String uri ) throws SAXException {				        if (debug) {				            System.out.println(this.getClass().getName() + ": startPrefixMapping(...)");				        }				        try {				            out.writeEvent( START_PREFIX_MAPPING );				            out.writeString( prefix );				            out.writeString( uri );				        } catch (Exception e) {				            throw new SAXException( e );				        } 				    } 				    				    				    public void endPrefixMapping( java.lang.String prefix ) throws SAXException {				        if (debug) {				            System.out.println(this.getClass().getName() + ": endPrefixMapping(...)");				        }				        try {				            out.writeEvent( END_PREFIX_MAPPING );				            out.writeString( prefix );				        } catch (Exception e) {				            throw new SAXException( e );				        } 				    } 				    				    				    public void startElement( java.lang.String namespaceURI, java.lang.String localName, java.lang.String qName,				            Attributes atts ) throws SAXException {				        if (debug) {				            System.out.println(this.getClass().getName() + ": startElement(...)");				        }				        try {				            int length = atts.getLength();				            out.writeEvent( START_ELEMENT );				            out.writeAttributes( length );				            for (int i = 0; i < length; i++) {				                out.writeString( atts.getURI( i ) );				                out.writeString( atts.getLocalName( i ) );				                out.writeString( atts.getQName( i ) );				                out.writeString( atts.getType( i ) );				                				                // write att value as char to prevent the value from being				                // indexed by the CompiledXMLOutputStream				                String attValue = atts.getValue( i );				                out.writeChars( attValue.toCharArray(), 0, attValue.length() );								               // out.writeString( attValue );				            } 				            out.writeString( namespaceURI );				            out.writeString( localName );				            out.writeString( qName );				        } catch (Exception e) {				            throw new SAXException( e );				        } 				    } 				    				    				    public void endElement( java.lang.String namespaceURI, java.lang.String localName, java.lang.String qName ) 				            throws SAXException {				        if (debug) {				            System.out.println(this.getClass().getName() + ": endElement(...)");				        }				        try {				            out.writeEvent( END_ELEMENT );				            out.writeString( namespaceURI );				            out.writeString( localName );				            out.writeString( qName );				        } catch (Exception e) {				            throw new SAXException( e );				        } 				    } 				    				    				    public void characters( char[] ch, int start, int length ) throws SAXException {				        if (debug) {				            System.out.println(this.getClass().getName() + ": characters(...)");				        }				        try {				            out.writeEvent( CHARACTERS );				            out.writeChars( ch, start, length );				        } catch (Exception e) {				            throw new SAXException( e );				        } 				    } 				    				    				    public void ignorableWhitespace( char[] ch, int start, int length ) throws SAXException {				        if (debug) {				            System.out.println(this.getClass().getName() + ": ignorableWhitespace(...)");				        }				        try {				            out.writeEvent( IGNORABLE_WHITESPACE );				            out.writeChars( ch, start, length );				        } catch (Exception e) {				            throw new SAXException( e );				        } 				    } 				    				    				    public void processingInstruction( java.lang.String target, java.lang.String data ) throws SAXException {				        if (debug) {				            System.out.println(this.getClass().getName() + ": processingInstruction(...)");				        }				        try {				            out.writeEvent( PROCESSING_INSTRUCTION );				            out.writeString( target );				            out.writeString( data );				        } catch (Exception e) {				            throw new SAXException( e );				        } 				    } 				    								    public void comment( char[] ch, int start, int length ) throws SAXException {				        if (debug) {				            System.out.println(this.getClass().getName() + ": comment(...)");				        }				        try {				            out.writeEvent(COMMENT);				            out.writeChars(ch, start, length);				        } catch (Exception e) {				            throw new SAXException(e);				        } 				    } 				    								    public void startCDATA() throws SAXException {				        if (debug) {				            System.out.println(this.getClass().getName() + ": startCDATA()");				        }				        try {				            out.writeEvent(START_CDATA);				        } catch (Exception e) {				            throw new SAXException(e);				        } 				    } 				    				    				    public void endCDATA() throws SAXException {				        if (debug) {				            System.out.println(this.getClass().getName() + ": endCDATA()");				        }				        try {				            out.writeEvent(END_CDATA);				        } catch (Exception e) {				            throw new SAXException(e);				        } 				    } 				    				    public void startDTD(String name, String publicId, String systemId)				            throws SAXException {				        if (debug) {				            System.out.println(this.getClass().getName() + ": startDTD()");				        }				        //FIXME(?)				        //not handled				    } 												    public void endDTD() throws SAXException {				        if (debug) {				            System.out.println(this.getClass().getName() + ": endDTD()");				        }				        //FIXME(?)				        //not handled				    } 												    public void startEntity(String name) throws SAXException {				        if (debug) {				            System.out.println(this.getClass().getName() + ": startEntity()");				        }				        //FIXME(?)				        //not handled				    } 				    				    				    public void endEntity(String name) throws SAXException {				        if (debug) {				            System.out.println(this.getClass().getName() + ": endEntity()");				        }				        //FIXME(?)				        //not handled				    } 				    				    				    public void setDocumentLocator( Locator locator ) {				    // ignore.				    } 				    				    				    public void skippedEntity( java.lang.String name ) throws SAXException {				        if (debug) {				            System.out.println(this.getClass().getName() + ": skippedEntity(...)[ignored]");				        }				    // ignore.				    } 				}							

相关资源