src/java.xml/share/classes/com/sun/org/apache/xml/internal/dtm/ref/IncrementalSAXSource_Xerces.java
author joehw
Wed, 18 Oct 2017 13:25:49 -0700
changeset 47359 e1a6c0168741
parent 47216 71c04702a3d5
child 48409 5ab69533994b
permissions -rw-r--r--
8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked Reviewed-by: lancea, rriggs, mullan
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6
7f561c08de6b Initial load
duke
parents:
diff changeset
     1
/*
45853
bfa06be36a17 8181154: Fix lint warnings in JAXP repo: deprecation
joehw
parents: 44797
diff changeset
     2
 * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
     3
 * @LastModified: Oct 2017
6
7f561c08de6b Initial load
duke
parents:
diff changeset
     4
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
     5
/*
44797
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 31497
diff changeset
     6
 * Licensed to the Apache Software Foundation (ASF) under one or more
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 31497
diff changeset
     7
 * contributor license agreements.  See the NOTICE file distributed with
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 31497
diff changeset
     8
 * this work for additional information regarding copyright ownership.
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 31497
diff changeset
     9
 * The ASF licenses this file to You under the Apache License, Version 2.0
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 31497
diff changeset
    10
 * (the "License"); you may not use this file except in compliance with
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 31497
diff changeset
    11
 * the License.  You may obtain a copy of the License at
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    12
 *
44797
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 31497
diff changeset
    13
 *      http://www.apache.org/licenses/LICENSE-2.0
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    14
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    15
 * Unless required by applicable law or agreed to in writing, software
7f561c08de6b Initial load
duke
parents:
diff changeset
    16
 * distributed under the License is distributed on an "AS IS" BASIS,
7f561c08de6b Initial load
duke
parents:
diff changeset
    17
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
7f561c08de6b Initial load
duke
parents:
diff changeset
    18
 * See the License for the specific language governing permissions and
7f561c08de6b Initial load
duke
parents:
diff changeset
    19
 * limitations under the License.
7f561c08de6b Initial load
duke
parents:
diff changeset
    20
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    21
7f561c08de6b Initial load
duke
parents:
diff changeset
    22
package com.sun.org.apache.xml.internal.dtm.ref;
7f561c08de6b Initial load
duke
parents:
diff changeset
    23
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
    24
import com.sun.org.apache.xalan.internal.utils.ObjectFactory;
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
    25
import com.sun.org.apache.xerces.internal.parsers.SAXParser;
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
    26
import com.sun.org.apache.xml.internal.res.XMLErrorResources;
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
    27
import com.sun.org.apache.xml.internal.res.XMLMessages;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    28
import java.io.IOException;
7f561c08de6b Initial load
duke
parents:
diff changeset
    29
import java.lang.reflect.Constructor;
7f561c08de6b Initial load
duke
parents:
diff changeset
    30
import java.lang.reflect.Method;
7f561c08de6b Initial load
duke
parents:
diff changeset
    31
import org.xml.sax.InputSource;
7f561c08de6b Initial load
duke
parents:
diff changeset
    32
import org.xml.sax.SAXException;
7f561c08de6b Initial load
duke
parents:
diff changeset
    33
import org.xml.sax.XMLReader;
7f561c08de6b Initial load
duke
parents:
diff changeset
    34
7f561c08de6b Initial load
duke
parents:
diff changeset
    35
7f561c08de6b Initial load
duke
parents:
diff changeset
    36
/** <p>IncrementalSAXSource_Xerces takes advantage of the fact that Xerces1
7f561c08de6b Initial load
duke
parents:
diff changeset
    37
 * incremental mode is already a coroutine of sorts, and just wraps our
7f561c08de6b Initial load
duke
parents:
diff changeset
    38
 * IncrementalSAXSource API around it.</p>
7f561c08de6b Initial load
duke
parents:
diff changeset
    39
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    40
 * <p>Usage example: See main().</p>
7f561c08de6b Initial load
duke
parents:
diff changeset
    41
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    42
 * <p>Status: Passes simple main() unit-test. NEEDS JAVADOC.</p>
7f561c08de6b Initial load
duke
parents:
diff changeset
    43
 * */
7f561c08de6b Initial load
duke
parents:
diff changeset
    44
public class IncrementalSAXSource_Xerces
7f561c08de6b Initial load
duke
parents:
diff changeset
    45
  implements IncrementalSAXSource
7f561c08de6b Initial load
duke
parents:
diff changeset
    46
{
7f561c08de6b Initial load
duke
parents:
diff changeset
    47
  //
7f561c08de6b Initial load
duke
parents:
diff changeset
    48
  // Reflection. To allow this to compile with both Xerces1 and Xerces2, which
7f561c08de6b Initial load
duke
parents:
diff changeset
    49
  // require very different methods and objects, we need to avoid static
7f561c08de6b Initial load
duke
parents:
diff changeset
    50
  // references to those APIs. So until Xerces2 is pervasive and we're willing
7f561c08de6b Initial load
duke
parents:
diff changeset
    51
  // to make it a prerequisite, we will rely upon relection.
7f561c08de6b Initial load
duke
parents:
diff changeset
    52
  //
7f561c08de6b Initial load
duke
parents:
diff changeset
    53
  Method fParseSomeSetup=null; // Xerces1 method
7f561c08de6b Initial load
duke
parents:
diff changeset
    54
  Method fParseSome=null; // Xerces1 method
7f561c08de6b Initial load
duke
parents:
diff changeset
    55
  Object fPullParserConfig=null; // Xerces2 pull control object
7f561c08de6b Initial load
duke
parents:
diff changeset
    56
  Method fConfigSetInput=null; // Xerces2 method
7f561c08de6b Initial load
duke
parents:
diff changeset
    57
  Method fConfigParse=null; // Xerces2 method
7f561c08de6b Initial load
duke
parents:
diff changeset
    58
  Method fSetInputSource=null; // Xerces2 pull control method
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
    59
  Constructor<?> fConfigInputSourceCtor=null; // Xerces2 initialization method
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    60
  Method fConfigSetByteStream=null; // Xerces2 initialization method
7f561c08de6b Initial load
duke
parents:
diff changeset
    61
  Method fConfigSetCharStream=null; // Xerces2 initialization method
7f561c08de6b Initial load
duke
parents:
diff changeset
    62
  Method fConfigSetEncoding=null; // Xerces2 initialization method
7f561c08de6b Initial load
duke
parents:
diff changeset
    63
  Method fReset=null; // Both Xerces1 and Xerces2, but diff. signatures
7f561c08de6b Initial load
duke
parents:
diff changeset
    64
7f561c08de6b Initial load
duke
parents:
diff changeset
    65
  //
7f561c08de6b Initial load
duke
parents:
diff changeset
    66
  // Data
7f561c08de6b Initial load
duke
parents:
diff changeset
    67
  //
7f561c08de6b Initial load
duke
parents:
diff changeset
    68
  SAXParser fIncrementalParser;
7f561c08de6b Initial load
duke
parents:
diff changeset
    69
  private boolean fParseInProgress=false;
7f561c08de6b Initial load
duke
parents:
diff changeset
    70
7f561c08de6b Initial load
duke
parents:
diff changeset
    71
  //
7f561c08de6b Initial load
duke
parents:
diff changeset
    72
  // Constructors
7f561c08de6b Initial load
duke
parents:
diff changeset
    73
  //
7f561c08de6b Initial load
duke
parents:
diff changeset
    74
7f561c08de6b Initial load
duke
parents:
diff changeset
    75
  /** Create a IncrementalSAXSource_Xerces, and create a SAXParser
7f561c08de6b Initial load
duke
parents:
diff changeset
    76
   * to go with it. Xerces2 incremental parsing is only supported if
7f561c08de6b Initial load
duke
parents:
diff changeset
    77
   * this constructor is used, due to limitations in the Xerces2 API (as of
7f561c08de6b Initial load
duke
parents:
diff changeset
    78
   * Beta 3). If you don't like that restriction, tell the Xerces folks that
7f561c08de6b Initial load
duke
parents:
diff changeset
    79
   * there should be a simpler way to request incremental SAX parsing.
7f561c08de6b Initial load
duke
parents:
diff changeset
    80
   * */
7f561c08de6b Initial load
duke
parents:
diff changeset
    81
  public IncrementalSAXSource_Xerces()
7f561c08de6b Initial load
duke
parents:
diff changeset
    82
                throws NoSuchMethodException
7f561c08de6b Initial load
duke
parents:
diff changeset
    83
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
    84
                try
7f561c08de6b Initial load
duke
parents:
diff changeset
    85
                {
31497
4a6b2e733c0d 8130051: Cleanup usage of reflection in jaxp
dfuchs
parents: 25868
diff changeset
    86
                        // This should be cleaned up and the use of reflection
4a6b2e733c0d 8130051: Cleanup usage of reflection in jaxp
dfuchs
parents: 25868
diff changeset
    87
                        // removed - see JDK-8129880
4a6b2e733c0d 8130051: Cleanup usage of reflection in jaxp
dfuchs
parents: 25868
diff changeset
    88
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    89
                        // Xerces-2 incremental parsing support (as of Beta 3)
7f561c08de6b Initial load
duke
parents:
diff changeset
    90
                        // ContentHandlers still get set on fIncrementalParser (to get
7f561c08de6b Initial load
duke
parents:
diff changeset
    91
                        // conversion from XNI events to SAX events), but
7f561c08de6b Initial load
duke
parents:
diff changeset
    92
                        // _control_ for incremental parsing must be exercised via the config.
7f561c08de6b Initial load
duke
parents:
diff changeset
    93
                        //
7f561c08de6b Initial load
duke
parents:
diff changeset
    94
                        // At this time there's no way to read the existing config, only
7f561c08de6b Initial load
duke
parents:
diff changeset
    95
                        // to assert a new one... and only when creating a brand-new parser.
7f561c08de6b Initial load
duke
parents:
diff changeset
    96
                        //
7f561c08de6b Initial load
duke
parents:
diff changeset
    97
                        // Reflection is used to allow us to continue to compile against
7f561c08de6b Initial load
duke
parents:
diff changeset
    98
                        // Xerces1. If/when we can abandon the older versions of the parser,
7f561c08de6b Initial load
duke
parents:
diff changeset
    99
                        // this will simplify significantly.
7f561c08de6b Initial load
duke
parents:
diff changeset
   100
7f561c08de6b Initial load
duke
parents:
diff changeset
   101
                        // If we can't get the magic constructor, no need to look further.
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   102
                        Class<?> xniConfigClass=ObjectFactory.findProviderClass(
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   103
                            "com.sun.org.apache.xerces.internal.xni.parser.XMLParserConfiguration",
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   104
                            true);
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   105
                        Class<?>[] args1={xniConfigClass};
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   106
                        Constructor<?> ctor=SAXParser.class.getConstructor(args1);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   107
7f561c08de6b Initial load
duke
parents:
diff changeset
   108
                        // Build the parser configuration object. StandardParserConfiguration
7f561c08de6b Initial load
duke
parents:
diff changeset
   109
                        // happens to implement XMLPullParserConfiguration, which is the API
7f561c08de6b Initial load
duke
parents:
diff changeset
   110
                        // we're going to want to use.
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   111
                        Class<?> xniStdConfigClass=ObjectFactory.findProviderClass(
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   112
                            "com.sun.org.apache.xerces.internal.parsers.StandardParserConfiguration",
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   113
                            true);
45853
bfa06be36a17 8181154: Fix lint warnings in JAXP repo: deprecation
joehw
parents: 44797
diff changeset
   114
                        fPullParserConfig=xniStdConfigClass.getConstructor().newInstance();
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   115
                        Object[] args2={fPullParserConfig};
7f561c08de6b Initial load
duke
parents:
diff changeset
   116
                        fIncrementalParser = (SAXParser)ctor.newInstance(args2);
7f561c08de6b Initial load
duke
parents:
diff changeset
   117
7f561c08de6b Initial load
duke
parents:
diff changeset
   118
                        // Preload all the needed the configuration methods... I want to know they're
7f561c08de6b Initial load
duke
parents:
diff changeset
   119
                        // all here before we commit to trying to use them, just in case the
7f561c08de6b Initial load
duke
parents:
diff changeset
   120
                        // API changes again.
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   121
                        Class<?> fXniInputSourceClass=ObjectFactory.findProviderClass(
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   122
                            "com.sun.org.apache.xerces.internal.xni.parser.XMLInputSource",
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   123
                            true);
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   124
                        Class<?>[] args3={fXniInputSourceClass};
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   125
                        fConfigSetInput=xniStdConfigClass.getMethod("setInputSource",args3);
7f561c08de6b Initial load
duke
parents:
diff changeset
   126
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   127
                        Class<?>[] args4={String.class,String.class,String.class};
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   128
                        fConfigInputSourceCtor=fXniInputSourceClass.getConstructor(args4);
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   129
                        Class<?>[] args5={java.io.InputStream.class};
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   130
                        fConfigSetByteStream=fXniInputSourceClass.getMethod("setByteStream",args5);
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   131
                        Class<?>[] args6={java.io.Reader.class};
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   132
                        fConfigSetCharStream=fXniInputSourceClass.getMethod("setCharacterStream",args6);
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   133
                        Class<?>[] args7={String.class};
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   134
                        fConfigSetEncoding=fXniInputSourceClass.getMethod("setEncoding",args7);
7f561c08de6b Initial load
duke
parents:
diff changeset
   135
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   136
                        Class<?>[] argsb={Boolean.TYPE};
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   137
                        fConfigParse=xniStdConfigClass.getMethod("parse",argsb);
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   138
                        Class<?>[] noargs=new Class<?>[0];
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   139
                        fReset=fIncrementalParser.getClass().getMethod("reset",noargs);
7f561c08de6b Initial load
duke
parents:
diff changeset
   140
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   141
                catch(Exception e)
7f561c08de6b Initial load
duke
parents:
diff changeset
   142
                {
7f561c08de6b Initial load
duke
parents:
diff changeset
   143
            // Fallback if this fails (implemented in createIncrementalSAXSource) is
7f561c08de6b Initial load
duke
parents:
diff changeset
   144
                        // to attempt Xerces-1 incremental setup. Can't do tail-call in
7f561c08de6b Initial load
duke
parents:
diff changeset
   145
                        // constructor, so create new, copy Xerces-1 initialization,
7f561c08de6b Initial load
duke
parents:
diff changeset
   146
                        // then throw it away... Ugh.
7f561c08de6b Initial load
duke
parents:
diff changeset
   147
                        IncrementalSAXSource_Xerces dummy=new IncrementalSAXSource_Xerces(new SAXParser());
7f561c08de6b Initial load
duke
parents:
diff changeset
   148
                        this.fParseSomeSetup=dummy.fParseSomeSetup;
7f561c08de6b Initial load
duke
parents:
diff changeset
   149
                        this.fParseSome=dummy.fParseSome;
7f561c08de6b Initial load
duke
parents:
diff changeset
   150
                        this.fIncrementalParser=dummy.fIncrementalParser;
7f561c08de6b Initial load
duke
parents:
diff changeset
   151
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   152
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   153
7f561c08de6b Initial load
duke
parents:
diff changeset
   154
  /** Create a IncrementalSAXSource_Xerces wrapped around
7f561c08de6b Initial load
duke
parents:
diff changeset
   155
   * an existing SAXParser. Currently this works only for recent
7f561c08de6b Initial load
duke
parents:
diff changeset
   156
   * releases of Xerces-1.  Xerces-2 incremental is currently possible
7f561c08de6b Initial load
duke
parents:
diff changeset
   157
   * only if we are allowed to create the parser instance, due to
7f561c08de6b Initial load
duke
parents:
diff changeset
   158
   * limitations in the API exposed by Xerces-2 Beta 3; see the
7f561c08de6b Initial load
duke
parents:
diff changeset
   159
   * no-args constructor for that code.
7f561c08de6b Initial load
duke
parents:
diff changeset
   160
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   161
   * @exception if the SAXParser class doesn't support the Xerces
7f561c08de6b Initial load
duke
parents:
diff changeset
   162
   * incremental parse operations. In that case, caller should
7f561c08de6b Initial load
duke
parents:
diff changeset
   163
   * fall back upon the IncrementalSAXSource_Filter approach.
7f561c08de6b Initial load
duke
parents:
diff changeset
   164
   * */
7f561c08de6b Initial load
duke
parents:
diff changeset
   165
  public IncrementalSAXSource_Xerces(SAXParser parser)
7f561c08de6b Initial load
duke
parents:
diff changeset
   166
    throws NoSuchMethodException
7f561c08de6b Initial load
duke
parents:
diff changeset
   167
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   168
                // Reflection is used to allow us to compile against
7f561c08de6b Initial load
duke
parents:
diff changeset
   169
                // Xerces2. If/when we can abandon the older versions of the parser,
7f561c08de6b Initial load
duke
parents:
diff changeset
   170
                // this constructor will simply have to fail until/unless the
7f561c08de6b Initial load
duke
parents:
diff changeset
   171
                // Xerces2 incremental support is made available on previously
7f561c08de6b Initial load
duke
parents:
diff changeset
   172
                // constructed SAXParser instances.
7f561c08de6b Initial load
duke
parents:
diff changeset
   173
    fIncrementalParser=parser;
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   174
                Class<?> me=parser.getClass();
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   175
    Class<?>[] parms={InputSource.class};
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   176
    fParseSomeSetup=me.getMethod("parseSomeSetup",parms);
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   177
    parms=new Class<?>[0];
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   178
    fParseSome=me.getMethod("parseSome",parms);
7f561c08de6b Initial load
duke
parents:
diff changeset
   179
    // Fallback if this fails (implemented in createIncrementalSAXSource) is
7f561c08de6b Initial load
duke
parents:
diff changeset
   180
    // to use IncrementalSAXSource_Filter rather than Xerces-specific code.
7f561c08de6b Initial load
duke
parents:
diff changeset
   181
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   182
7f561c08de6b Initial load
duke
parents:
diff changeset
   183
  //
7f561c08de6b Initial load
duke
parents:
diff changeset
   184
  // Factories
7f561c08de6b Initial load
duke
parents:
diff changeset
   185
  //
7f561c08de6b Initial load
duke
parents:
diff changeset
   186
  static public IncrementalSAXSource createIncrementalSAXSource()
7f561c08de6b Initial load
duke
parents:
diff changeset
   187
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   188
                try
7f561c08de6b Initial load
duke
parents:
diff changeset
   189
                {
7f561c08de6b Initial load
duke
parents:
diff changeset
   190
                        return new IncrementalSAXSource_Xerces();
7f561c08de6b Initial load
duke
parents:
diff changeset
   191
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   192
                catch(NoSuchMethodException e)
7f561c08de6b Initial load
duke
parents:
diff changeset
   193
                {
7f561c08de6b Initial load
duke
parents:
diff changeset
   194
                        // Xerces version mismatch; neither Xerces1 nor Xerces2 succeeded.
7f561c08de6b Initial load
duke
parents:
diff changeset
   195
                        // Fall back on filtering solution.
7f561c08de6b Initial load
duke
parents:
diff changeset
   196
                        IncrementalSAXSource_Filter iss=new IncrementalSAXSource_Filter();
7f561c08de6b Initial load
duke
parents:
diff changeset
   197
                        iss.setXMLReader(new SAXParser());
7f561c08de6b Initial load
duke
parents:
diff changeset
   198
                        return iss;
7f561c08de6b Initial load
duke
parents:
diff changeset
   199
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   200
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   201
7f561c08de6b Initial load
duke
parents:
diff changeset
   202
  static public IncrementalSAXSource
7f561c08de6b Initial load
duke
parents:
diff changeset
   203
  createIncrementalSAXSource(SAXParser parser) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   204
                try
7f561c08de6b Initial load
duke
parents:
diff changeset
   205
                {
7f561c08de6b Initial load
duke
parents:
diff changeset
   206
                        return new IncrementalSAXSource_Xerces(parser);
7f561c08de6b Initial load
duke
parents:
diff changeset
   207
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   208
                catch(NoSuchMethodException e)
7f561c08de6b Initial load
duke
parents:
diff changeset
   209
                {
7f561c08de6b Initial load
duke
parents:
diff changeset
   210
                        // Xerces version mismatch; neither Xerces1 nor Xerces2 succeeded.
7f561c08de6b Initial load
duke
parents:
diff changeset
   211
                        // Fall back on filtering solution.
7f561c08de6b Initial load
duke
parents:
diff changeset
   212
                        IncrementalSAXSource_Filter iss=new IncrementalSAXSource_Filter();
7f561c08de6b Initial load
duke
parents:
diff changeset
   213
                        iss.setXMLReader(parser);
7f561c08de6b Initial load
duke
parents:
diff changeset
   214
                        return iss;
7f561c08de6b Initial load
duke
parents:
diff changeset
   215
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   216
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   217
7f561c08de6b Initial load
duke
parents:
diff changeset
   218
  //
7f561c08de6b Initial load
duke
parents:
diff changeset
   219
  // Public methods
7f561c08de6b Initial load
duke
parents:
diff changeset
   220
  //
7f561c08de6b Initial load
duke
parents:
diff changeset
   221
7f561c08de6b Initial load
duke
parents:
diff changeset
   222
  // Register handler directly with the incremental parser
7f561c08de6b Initial load
duke
parents:
diff changeset
   223
  public void setContentHandler(org.xml.sax.ContentHandler handler)
7f561c08de6b Initial load
duke
parents:
diff changeset
   224
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   225
    // Typecast required in Xerces2; SAXParser doesn't inheret XMLReader
7f561c08de6b Initial load
duke
parents:
diff changeset
   226
    // %OPT% Cast at asignment?
7f561c08de6b Initial load
duke
parents:
diff changeset
   227
    ((XMLReader)fIncrementalParser).setContentHandler(handler);
7f561c08de6b Initial load
duke
parents:
diff changeset
   228
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   229
7f561c08de6b Initial load
duke
parents:
diff changeset
   230
  // Register handler directly with the incremental parser
7f561c08de6b Initial load
duke
parents:
diff changeset
   231
  public void setLexicalHandler(org.xml.sax.ext.LexicalHandler handler)
7f561c08de6b Initial load
duke
parents:
diff changeset
   232
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   233
    // Not supported by all SAX2 parsers but should work in Xerces:
7f561c08de6b Initial load
duke
parents:
diff changeset
   234
    try
7f561c08de6b Initial load
duke
parents:
diff changeset
   235
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   236
      // Typecast required in Xerces2; SAXParser doesn't inheret XMLReader
7f561c08de6b Initial load
duke
parents:
diff changeset
   237
      // %OPT% Cast at asignment?
7f561c08de6b Initial load
duke
parents:
diff changeset
   238
      ((XMLReader)fIncrementalParser).setProperty("http://xml.org/sax/properties/lexical-handler",
7f561c08de6b Initial load
duke
parents:
diff changeset
   239
                                     handler);
7f561c08de6b Initial load
duke
parents:
diff changeset
   240
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   241
    catch(org.xml.sax.SAXNotRecognizedException e)
7f561c08de6b Initial load
duke
parents:
diff changeset
   242
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   243
      // Nothing we can do about it
7f561c08de6b Initial load
duke
parents:
diff changeset
   244
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   245
    catch(org.xml.sax.SAXNotSupportedException e)
7f561c08de6b Initial load
duke
parents:
diff changeset
   246
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   247
      // Nothing we can do about it
7f561c08de6b Initial load
duke
parents:
diff changeset
   248
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   249
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   250
7f561c08de6b Initial load
duke
parents:
diff changeset
   251
  // Register handler directly with the incremental parser
7f561c08de6b Initial load
duke
parents:
diff changeset
   252
  public void setDTDHandler(org.xml.sax.DTDHandler handler)
7f561c08de6b Initial load
duke
parents:
diff changeset
   253
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   254
    // Typecast required in Xerces2; SAXParser doesn't inheret XMLReader
7f561c08de6b Initial load
duke
parents:
diff changeset
   255
    // %OPT% Cast at asignment?
7f561c08de6b Initial load
duke
parents:
diff changeset
   256
    ((XMLReader)fIncrementalParser).setDTDHandler(handler);
7f561c08de6b Initial load
duke
parents:
diff changeset
   257
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   258
7f561c08de6b Initial load
duke
parents:
diff changeset
   259
  //================================================================
7f561c08de6b Initial load
duke
parents:
diff changeset
   260
  /** startParse() is a simple API which tells the IncrementalSAXSource
7f561c08de6b Initial load
duke
parents:
diff changeset
   261
   * to begin reading a document.
7f561c08de6b Initial load
duke
parents:
diff changeset
   262
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   263
   * @throws SAXException is parse thread is already in progress
7f561c08de6b Initial load
duke
parents:
diff changeset
   264
   * or parsing can not be started.
7f561c08de6b Initial load
duke
parents:
diff changeset
   265
   * */
7f561c08de6b Initial load
duke
parents:
diff changeset
   266
  public void startParse(InputSource source) throws SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
   267
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   268
    if (fIncrementalParser==null)
7f561c08de6b Initial load
duke
parents:
diff changeset
   269
      throw new SAXException(XMLMessages.createXMLMessage(XMLErrorResources.ER_STARTPARSE_NEEDS_SAXPARSER, null)); //"startParse needs a non-null SAXParser.");
7f561c08de6b Initial load
duke
parents:
diff changeset
   270
    if (fParseInProgress)
7f561c08de6b Initial load
duke
parents:
diff changeset
   271
      throw new SAXException(XMLMessages.createXMLMessage(XMLErrorResources.ER_STARTPARSE_WHILE_PARSING, null)); //"startParse may not be called while parsing.");
7f561c08de6b Initial load
duke
parents:
diff changeset
   272
7f561c08de6b Initial load
duke
parents:
diff changeset
   273
    boolean ok=false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   274
7f561c08de6b Initial load
duke
parents:
diff changeset
   275
    try
7f561c08de6b Initial load
duke
parents:
diff changeset
   276
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   277
      ok = parseSomeSetup(source);
7f561c08de6b Initial load
duke
parents:
diff changeset
   278
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   279
    catch(Exception ex)
7f561c08de6b Initial load
duke
parents:
diff changeset
   280
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   281
      throw new SAXException(ex);
7f561c08de6b Initial load
duke
parents:
diff changeset
   282
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   283
7f561c08de6b Initial load
duke
parents:
diff changeset
   284
    if(!ok)
7f561c08de6b Initial load
duke
parents:
diff changeset
   285
      throw new SAXException(XMLMessages.createXMLMessage(XMLErrorResources.ER_COULD_NOT_INIT_PARSER, null)); //"could not initialize parser with");
7f561c08de6b Initial load
duke
parents:
diff changeset
   286
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   287
7f561c08de6b Initial load
duke
parents:
diff changeset
   288
7f561c08de6b Initial load
duke
parents:
diff changeset
   289
  /** deliverMoreNodes() is a simple API which tells the coroutine
7f561c08de6b Initial load
duke
parents:
diff changeset
   290
   * parser that we need more nodes.  This is intended to be called
7f561c08de6b Initial load
duke
parents:
diff changeset
   291
   * from one of our partner routines, and serves to encapsulate the
7f561c08de6b Initial load
duke
parents:
diff changeset
   292
   * details of how incremental parsing has been achieved.
7f561c08de6b Initial load
duke
parents:
diff changeset
   293
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   294
   * @param parsemore If true, tells the incremental parser to generate
7f561c08de6b Initial load
duke
parents:
diff changeset
   295
   * another chunk of output. If false, tells the parser that we're
7f561c08de6b Initial load
duke
parents:
diff changeset
   296
   * satisfied and it can terminate parsing of this document.
7f561c08de6b Initial load
duke
parents:
diff changeset
   297
   * @return Boolean.TRUE if the CoroutineParser believes more data may be available
7f561c08de6b Initial load
duke
parents:
diff changeset
   298
   * for further parsing. Boolean.FALSE if parsing ran to completion.
7f561c08de6b Initial load
duke
parents:
diff changeset
   299
   * Exception if the parser objected for some reason.
7f561c08de6b Initial load
duke
parents:
diff changeset
   300
   * */
7f561c08de6b Initial load
duke
parents:
diff changeset
   301
  public Object deliverMoreNodes (boolean parsemore)
7f561c08de6b Initial load
duke
parents:
diff changeset
   302
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   303
    if(!parsemore)
7f561c08de6b Initial load
duke
parents:
diff changeset
   304
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   305
      fParseInProgress=false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   306
      return Boolean.FALSE;
7f561c08de6b Initial load
duke
parents:
diff changeset
   307
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   308
7f561c08de6b Initial load
duke
parents:
diff changeset
   309
    Object arg;
7f561c08de6b Initial load
duke
parents:
diff changeset
   310
    try {
7f561c08de6b Initial load
duke
parents:
diff changeset
   311
      boolean keepgoing = parseSome();
7f561c08de6b Initial load
duke
parents:
diff changeset
   312
      arg = keepgoing ? Boolean.TRUE : Boolean.FALSE;
7f561c08de6b Initial load
duke
parents:
diff changeset
   313
    } catch (SAXException ex) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   314
      arg = ex;
7f561c08de6b Initial load
duke
parents:
diff changeset
   315
    } catch (IOException ex) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   316
      arg = ex;
7f561c08de6b Initial load
duke
parents:
diff changeset
   317
    } catch (Exception ex) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   318
      arg = new SAXException(ex);
7f561c08de6b Initial load
duke
parents:
diff changeset
   319
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   320
    return arg;
7f561c08de6b Initial load
duke
parents:
diff changeset
   321
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   322
7f561c08de6b Initial load
duke
parents:
diff changeset
   323
        // Private methods -- conveniences to hide the reflection details
7f561c08de6b Initial load
duke
parents:
diff changeset
   324
        private boolean parseSomeSetup(InputSource source)
7f561c08de6b Initial load
duke
parents:
diff changeset
   325
                throws SAXException, IOException, IllegalAccessException,
7f561c08de6b Initial load
duke
parents:
diff changeset
   326
                                         java.lang.reflect.InvocationTargetException,
7f561c08de6b Initial load
duke
parents:
diff changeset
   327
                                         java.lang.InstantiationException
7f561c08de6b Initial load
duke
parents:
diff changeset
   328
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   329
                if(fConfigSetInput!=null)
7f561c08de6b Initial load
duke
parents:
diff changeset
   330
                {
7f561c08de6b Initial load
duke
parents:
diff changeset
   331
                        // Obtain input from SAX inputSource object, construct XNI version of
7f561c08de6b Initial load
duke
parents:
diff changeset
   332
                        // that object. Logic adapted from Xerces2.
7f561c08de6b Initial load
duke
parents:
diff changeset
   333
                        Object[] parms1={source.getPublicId(),source.getSystemId(),null};
7f561c08de6b Initial load
duke
parents:
diff changeset
   334
                        Object xmlsource=fConfigInputSourceCtor.newInstance(parms1);
7f561c08de6b Initial load
duke
parents:
diff changeset
   335
                        Object[] parmsa={source.getByteStream()};
7f561c08de6b Initial load
duke
parents:
diff changeset
   336
                        fConfigSetByteStream.invoke(xmlsource,parmsa);
7f561c08de6b Initial load
duke
parents:
diff changeset
   337
                        parmsa[0]=source.getCharacterStream();
7f561c08de6b Initial load
duke
parents:
diff changeset
   338
                        fConfigSetCharStream.invoke(xmlsource,parmsa);
7f561c08de6b Initial load
duke
parents:
diff changeset
   339
                        parmsa[0]=source.getEncoding();
7f561c08de6b Initial load
duke
parents:
diff changeset
   340
                        fConfigSetEncoding.invoke(xmlsource,parmsa);
7f561c08de6b Initial load
duke
parents:
diff changeset
   341
7f561c08de6b Initial load
duke
parents:
diff changeset
   342
                        // Bugzilla5272 patch suggested by Sandy Gao.
7f561c08de6b Initial load
duke
parents:
diff changeset
   343
                        // Has to be reflection to run with Xerces2
7f561c08de6b Initial load
duke
parents:
diff changeset
   344
                        // after compilation against Xerces1. or vice
7f561c08de6b Initial load
duke
parents:
diff changeset
   345
                        // versa, due to return type mismatches.
7f561c08de6b Initial load
duke
parents:
diff changeset
   346
                        Object[] noparms=new Object[0];
7f561c08de6b Initial load
duke
parents:
diff changeset
   347
                        fReset.invoke(fIncrementalParser,noparms);
7f561c08de6b Initial load
duke
parents:
diff changeset
   348
7f561c08de6b Initial load
duke
parents:
diff changeset
   349
                        parmsa[0]=xmlsource;
7f561c08de6b Initial load
duke
parents:
diff changeset
   350
                        fConfigSetInput.invoke(fPullParserConfig,parmsa);
7f561c08de6b Initial load
duke
parents:
diff changeset
   351
7f561c08de6b Initial load
duke
parents:
diff changeset
   352
                        // %REVIEW% Do first pull. Should we instead just return true?
7f561c08de6b Initial load
duke
parents:
diff changeset
   353
                        return parseSome();
7f561c08de6b Initial load
duke
parents:
diff changeset
   354
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   355
                else
7f561c08de6b Initial load
duke
parents:
diff changeset
   356
                {
7f561c08de6b Initial load
duke
parents:
diff changeset
   357
                        Object[] parm={source};
7f561c08de6b Initial load
duke
parents:
diff changeset
   358
                        Object ret=fParseSomeSetup.invoke(fIncrementalParser,parm);
7f561c08de6b Initial load
duke
parents:
diff changeset
   359
                        return ((Boolean)ret).booleanValue();
7f561c08de6b Initial load
duke
parents:
diff changeset
   360
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   361
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   362
//  Would null work???
7f561c08de6b Initial load
duke
parents:
diff changeset
   363
    private static final Object[] noparms=new Object[0];
7f561c08de6b Initial load
duke
parents:
diff changeset
   364
    private static final Object[] parmsfalse={Boolean.FALSE};
7f561c08de6b Initial load
duke
parents:
diff changeset
   365
    private boolean parseSome()
7f561c08de6b Initial load
duke
parents:
diff changeset
   366
                throws SAXException, IOException, IllegalAccessException,
7f561c08de6b Initial load
duke
parents:
diff changeset
   367
                                         java.lang.reflect.InvocationTargetException
7f561c08de6b Initial load
duke
parents:
diff changeset
   368
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   369
                // Take next parsing step, return false iff parsing complete:
7f561c08de6b Initial load
duke
parents:
diff changeset
   370
                if(fConfigSetInput!=null)
7f561c08de6b Initial load
duke
parents:
diff changeset
   371
                {
7f561c08de6b Initial load
duke
parents:
diff changeset
   372
                        Object ret=(Boolean)(fConfigParse.invoke(fPullParserConfig,parmsfalse));
7f561c08de6b Initial load
duke
parents:
diff changeset
   373
                        return ((Boolean)ret).booleanValue();
7f561c08de6b Initial load
duke
parents:
diff changeset
   374
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   375
                else
7f561c08de6b Initial load
duke
parents:
diff changeset
   376
                {
7f561c08de6b Initial load
duke
parents:
diff changeset
   377
                        Object ret=fParseSome.invoke(fIncrementalParser,noparms);
7f561c08de6b Initial load
duke
parents:
diff changeset
   378
                        return ((Boolean)ret).booleanValue();
7f561c08de6b Initial load
duke
parents:
diff changeset
   379
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   380
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   381
7f561c08de6b Initial load
duke
parents:
diff changeset
   382
7f561c08de6b Initial load
duke
parents:
diff changeset
   383
  //================================================================
7f561c08de6b Initial load
duke
parents:
diff changeset
   384
  /** Simple unit test. Attempt coroutine parsing of document indicated
7f561c08de6b Initial load
duke
parents:
diff changeset
   385
   * by first argument (as a URI), report progress.
7f561c08de6b Initial load
duke
parents:
diff changeset
   386
   */
45853
bfa06be36a17 8181154: Fix lint warnings in JAXP repo: deprecation
joehw
parents: 44797
diff changeset
   387
  @Deprecated
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   388
  public static void _main(String args[])
7f561c08de6b Initial load
duke
parents:
diff changeset
   389
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   390
    System.out.println("Starting...");
7f561c08de6b Initial load
duke
parents:
diff changeset
   391
7f561c08de6b Initial load
duke
parents:
diff changeset
   392
    CoroutineManager co = new CoroutineManager();
7f561c08de6b Initial load
duke
parents:
diff changeset
   393
    int appCoroutineID = co.co_joinCoroutineSet(-1);
7f561c08de6b Initial load
duke
parents:
diff changeset
   394
    if (appCoroutineID == -1)
7f561c08de6b Initial load
duke
parents:
diff changeset
   395
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   396
      System.out.println("ERROR: Couldn't allocate coroutine number.\n");
7f561c08de6b Initial load
duke
parents:
diff changeset
   397
      return;
7f561c08de6b Initial load
duke
parents:
diff changeset
   398
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   399
    IncrementalSAXSource parser=
7f561c08de6b Initial load
duke
parents:
diff changeset
   400
      createIncrementalSAXSource();
7f561c08de6b Initial load
duke
parents:
diff changeset
   401
7f561c08de6b Initial load
duke
parents:
diff changeset
   402
    // Use a serializer as our sample output
7f561c08de6b Initial load
duke
parents:
diff changeset
   403
    com.sun.org.apache.xml.internal.serialize.XMLSerializer trace;
7f561c08de6b Initial load
duke
parents:
diff changeset
   404
    trace=new com.sun.org.apache.xml.internal.serialize.XMLSerializer(System.out,null);
7f561c08de6b Initial load
duke
parents:
diff changeset
   405
    parser.setContentHandler(trace);
7f561c08de6b Initial load
duke
parents:
diff changeset
   406
    parser.setLexicalHandler(trace);
7f561c08de6b Initial load
duke
parents:
diff changeset
   407
7f561c08de6b Initial load
duke
parents:
diff changeset
   408
    // Tell coroutine to begin parsing, run while parsing is in progress
7f561c08de6b Initial load
duke
parents:
diff changeset
   409
7f561c08de6b Initial load
duke
parents:
diff changeset
   410
    for(int arg=0;arg<args.length;++arg)
7f561c08de6b Initial load
duke
parents:
diff changeset
   411
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   412
      try
7f561c08de6b Initial load
duke
parents:
diff changeset
   413
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
   414
        InputSource source = new InputSource(args[arg]);
7f561c08de6b Initial load
duke
parents:
diff changeset
   415
        Object result=null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   416
        boolean more=true;
7f561c08de6b Initial load
duke
parents:
diff changeset
   417
        parser.startParse(source);
7f561c08de6b Initial load
duke
parents:
diff changeset
   418
        for(result = parser.deliverMoreNodes(more);
7f561c08de6b Initial load
duke
parents:
diff changeset
   419
            result==Boolean.TRUE;
7f561c08de6b Initial load
duke
parents:
diff changeset
   420
            result = parser.deliverMoreNodes(more))
7f561c08de6b Initial load
duke
parents:
diff changeset
   421
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   422
          System.out.println("\nSome parsing successful, trying more.\n");
7f561c08de6b Initial load
duke
parents:
diff changeset
   423
7f561c08de6b Initial load
duke
parents:
diff changeset
   424
          // Special test: Terminate parsing early.
7f561c08de6b Initial load
duke
parents:
diff changeset
   425
          if(arg+1<args.length && "!".equals(args[arg+1]))
7f561c08de6b Initial load
duke
parents:
diff changeset
   426
          {
7f561c08de6b Initial load
duke
parents:
diff changeset
   427
            ++arg;
7f561c08de6b Initial load
duke
parents:
diff changeset
   428
            more=false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   429
          }
7f561c08de6b Initial load
duke
parents:
diff changeset
   430
7f561c08de6b Initial load
duke
parents:
diff changeset
   431
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   432
7f561c08de6b Initial load
duke
parents:
diff changeset
   433
        if (result instanceof Boolean && ((Boolean)result)==Boolean.FALSE)
7f561c08de6b Initial load
duke
parents:
diff changeset
   434
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   435
          System.out.println("\nParser ended (EOF or on request).\n");
7f561c08de6b Initial load
duke
parents:
diff changeset
   436
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   437
        else if (result == null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   438
          System.out.println("\nUNEXPECTED: Parser says shut down prematurely.\n");
7f561c08de6b Initial load
duke
parents:
diff changeset
   439
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   440
        else if (result instanceof Exception) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   441
          throw new com.sun.org.apache.xml.internal.utils.WrappedRuntimeException((Exception)result);
7f561c08de6b Initial load
duke
parents:
diff changeset
   442
          //          System.out.println("\nParser threw exception:");
7f561c08de6b Initial load
duke
parents:
diff changeset
   443
          //          ((Exception)result).printStackTrace();
7f561c08de6b Initial load
duke
parents:
diff changeset
   444
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   445
7f561c08de6b Initial load
duke
parents:
diff changeset
   446
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   447
7f561c08de6b Initial load
duke
parents:
diff changeset
   448
      catch(SAXException e)
7f561c08de6b Initial load
duke
parents:
diff changeset
   449
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
   450
        e.printStackTrace();
7f561c08de6b Initial load
duke
parents:
diff changeset
   451
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   452
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   453
7f561c08de6b Initial load
duke
parents:
diff changeset
   454
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   455
7f561c08de6b Initial load
duke
parents:
diff changeset
   456
7f561c08de6b Initial load
duke
parents:
diff changeset
   457
} // class IncrementalSAXSource_Xerces