src/share/jaxws_classes/com/sun/tools/internal/jxc/gen/config/NGCCHandler.java

changeset 286
f50545b5e2f1
child 368
0989ad8c0860
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/jaxws_classes/com/sun/tools/internal/jxc/gen/config/NGCCHandler.java	Tue Mar 06 16:09:35 2012 -0800
     1.3 @@ -0,0 +1,191 @@
     1.4 +/*
     1.5 + * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.  Oracle designates this
    1.11 + * particular file as subject to the "Classpath" exception as provided
    1.12 + * by Oracle in the LICENSE file that accompanied this code.
    1.13 + *
    1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.17 + * version 2 for more details (a copy is included in the LICENSE file that
    1.18 + * accompanied this code).
    1.19 + *
    1.20 + * You should have received a copy of the GNU General Public License version
    1.21 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.23 + *
    1.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.25 + * or visit www.oracle.com if you need additional information or have any
    1.26 + * questions.
    1.27 + */
    1.28 +
    1.29 +package com.sun.tools.internal.jxc.gen.config;
    1.30 +
    1.31 +import org.xml.sax.Attributes;
    1.32 +import org.xml.sax.SAXException;
    1.33 +
    1.34 +/**
    1.35 + *
    1.36 + *
    1.37 + * @version $Id: NGCCHandler.java,v 1.9 2002/09/29 02:55:48 okajima Exp $
    1.38 + * @author Kohsuke Kawaguchi (kk@kohsuke.org)
    1.39 + */
    1.40 +public abstract class NGCCHandler implements NGCCEventReceiver {
    1.41 +    protected NGCCHandler( NGCCEventSource source, NGCCHandler parent, int parentCookie ) {
    1.42 +
    1.43 +        _parent = parent;
    1.44 +        _source = source;
    1.45 +        _cookie = parentCookie;
    1.46 +    }
    1.47 +
    1.48 +    /**
    1.49 +     * Parent NGCCHandler, if any.
    1.50 +     * If this is the root handler, this field will be null.
    1.51 +     */
    1.52 +    protected final NGCCHandler _parent;
    1.53 +
    1.54 +    /**
    1.55 +     * Event source.
    1.56 +     */
    1.57 +    protected final NGCCEventSource _source;
    1.58 +
    1.59 +    /**
    1.60 +     * This method will be implemented by the generated code
    1.61 +     * and returns a reference to the current runtime.
    1.62 +     */
    1.63 +    protected abstract NGCCRuntime getRuntime();
    1.64 +
    1.65 +    /**
    1.66 +     * Cookie assigned by the parent.
    1.67 +     *
    1.68 +     * This value will be passed to the onChildCompleted handler
    1.69 +     * of the parent.
    1.70 +     */
    1.71 +    protected final int _cookie;
    1.72 +
    1.73 +    // used to copy parameters to (enter|leave)(Element|Attribute) events.
    1.74 +    //protected String localName,uri,qname;
    1.75 +
    1.76 +
    1.77 +    /**
    1.78 +     * Notifies the completion of a child object.
    1.79 +     *
    1.80 +     * @param result
    1.81 +     *      The parsing result of the child state.
    1.82 +     * @param cookie
    1.83 +     *      The cookie value passed to the child object
    1.84 +     *      when it is created.
    1.85 +     * @param needAttCheck
    1.86 +     *      This flag is true when the callee needs to call the
    1.87 +     *      processAttribute method to check attribute transitions.
    1.88 +     *      This flag is set to false when this method is triggered by
    1.89 +     *      attribute transition.
    1.90 +     */
    1.91 +    protected abstract void onChildCompleted( Object result, int cookie, boolean needAttCheck ) throws SAXException;
    1.92 +
    1.93 +//
    1.94 +//
    1.95 +// spawns a new child object from event handlers.
    1.96 +//
    1.97 +//
    1.98 +    public void spawnChildFromEnterElement( NGCCEventReceiver child,
    1.99 +        String uri, String localname, String qname, Attributes atts) throws SAXException {
   1.100 +
   1.101 +        int id = _source.replace(this,child);
   1.102 +        _source.sendEnterElement(id,uri,localname,qname,atts);
   1.103 +    }
   1.104 +    public void spawnChildFromEnterAttribute( NGCCEventReceiver child,
   1.105 +        String uri, String localname, String qname) throws SAXException {
   1.106 +
   1.107 +        int id = _source.replace(this,child);
   1.108 +        _source.sendEnterAttribute(id,uri,localname,qname);
   1.109 +    }
   1.110 +    public void spawnChildFromLeaveElement( NGCCEventReceiver child,
   1.111 +        String uri, String localname, String qname) throws SAXException {
   1.112 +
   1.113 +        int id = _source.replace(this,child);
   1.114 +        _source.sendLeaveElement(id,uri,localname,qname);
   1.115 +    }
   1.116 +    public void spawnChildFromLeaveAttribute( NGCCEventReceiver child,
   1.117 +        String uri, String localname, String qname) throws SAXException {
   1.118 +
   1.119 +        int id = _source.replace(this,child);
   1.120 +        _source.sendLeaveAttribute(id,uri,localname,qname);
   1.121 +    }
   1.122 +    public void spawnChildFromText( NGCCEventReceiver child,
   1.123 +        String value) throws SAXException {
   1.124 +
   1.125 +        int id = _source.replace(this,child);
   1.126 +        _source.sendText(id,value);
   1.127 +    }
   1.128 +
   1.129 +//
   1.130 +//
   1.131 +// reverts to the parent object from the child handler
   1.132 +//
   1.133 +//
   1.134 +    public void revertToParentFromEnterElement( Object result, int cookie,
   1.135 +        String uri,String local,String qname, Attributes atts ) throws SAXException {
   1.136 +
   1.137 +        int id = _source.replace(this,_parent);
   1.138 +        _parent.onChildCompleted(result,cookie,true);
   1.139 +        _source.sendEnterElement(id,uri,local,qname,atts);
   1.140 +    }
   1.141 +    public void revertToParentFromLeaveElement( Object result, int cookie,
   1.142 +        String uri,String local,String qname ) throws SAXException {
   1.143 +
   1.144 +        if(uri==NGCCRuntime.IMPOSSIBLE && uri==local && uri==qname && _parent==null )
   1.145 +            // all the handlers are properly finalized.
   1.146 +            // quit now, because we don't have any more NGCCHandler.
   1.147 +            // see the endDocument handler for detail
   1.148 +            return;
   1.149 +
   1.150 +        int id = _source.replace(this,_parent);
   1.151 +        _parent.onChildCompleted(result,cookie,true);
   1.152 +        _source.sendLeaveElement(id,uri,local,qname);
   1.153 +    }
   1.154 +    public void revertToParentFromEnterAttribute( Object result, int cookie,
   1.155 +        String uri,String local,String qname ) throws SAXException {
   1.156 +
   1.157 +        int id = _source.replace(this,_parent);
   1.158 +        _parent.onChildCompleted(result,cookie,true);
   1.159 +        _source.sendEnterAttribute(id,uri,local,qname);
   1.160 +    }
   1.161 +    public void revertToParentFromLeaveAttribute( Object result, int cookie,
   1.162 +        String uri,String local,String qname ) throws SAXException {
   1.163 +
   1.164 +        int id = _source.replace(this,_parent);
   1.165 +        _parent.onChildCompleted(result,cookie,true);
   1.166 +        _source.sendLeaveAttribute(id,uri,local,qname);
   1.167 +    }
   1.168 +    public void revertToParentFromText( Object result, int cookie,
   1.169 +        String text ) throws SAXException {
   1.170 +
   1.171 +        int id = _source.replace(this,_parent);
   1.172 +        _parent.onChildCompleted(result,cookie,true);
   1.173 +        _source.sendText(id,text);
   1.174 +    }
   1.175 +
   1.176 +
   1.177 +//
   1.178 +//
   1.179 +// error handler
   1.180 +//
   1.181 +//
   1.182 +    public void unexpectedEnterElement(String qname) throws SAXException {
   1.183 +        getRuntime().unexpectedX('<'+qname+'>');
   1.184 +    }
   1.185 +    public void unexpectedLeaveElement(String qname) throws SAXException {
   1.186 +        getRuntime().unexpectedX("</"+qname+'>');
   1.187 +    }
   1.188 +    public void unexpectedEnterAttribute(String qname) throws SAXException {
   1.189 +        getRuntime().unexpectedX('@'+qname);
   1.190 +    }
   1.191 +    public void unexpectedLeaveAttribute(String qname) throws SAXException {
   1.192 +        getRuntime().unexpectedX("/@"+qname);
   1.193 +    }
   1.194 +}

mercurial