Search in sources :

Example 1 with ScannerException

use of com.ibm.dtfj.javacore.parser.framework.scanner.ScannerException in project openj9 by eclipse.

the class ParserController method parse.

/**
 * Support for one image builder parsing javacore data for only one runtime.
 * Multiple runtime support will require overriding this method in a subclass.
 */
public Image parse(IScannerManager scannerManager) throws ParserException {
    ILookAheadBuffer lookAhead = scannerManager.getLookAheadBuffer();
    // For error reporting
    StringBuffer sb = new StringBuffer();
    try {
        for (int i = 1; i <= 2 && i <= lookAhead.maxDepth(); ++i) {
            IParserToken token = lookAhead.lookAhead(i);
            if (token != null) {
                sb.append(token.getValue());
            }
        }
    } catch (IOException e) {
    } catch (IndexOutOfBoundsException e) {
    } catch (ScannerException e) {
        throw new ParserException(e);
    }
    // Don't get too much data
    sb.setLength(Math.min(300, sb.length()));
    String first = sb.toString();
    IImageBuilder imageBuilder = null;
    try {
        imageBuilder = generateImageBuilder();
    } catch (BuilderFailureException e) {
        throw new ParserException(e);
    }
    boolean anyMatched = false;
    try {
        lookAhead.init();
        for (Iterator it = fFramework.iterator(); it.hasNext(); ) {
            processUnknownData(lookAhead);
            ISectionParser sectionParser = (ISectionParser) it.next();
            sectionParser.readIntoDTFJ(lookAhead, imageBuilder);
            /*
				 * Retrieve the error log.
				 */
            Iterator errors = sectionParser.getErrors();
            if ((fListener != null) && errors.hasNext()) {
                while (errors.hasNext()) {
                    fListener.handleEvent(errors.next().toString());
                }
            }
            anyMatched |= sectionParser.anyMatched();
        }
    } catch (IOException e) {
        /*
			 * If IO exception encountered, parser may have reached a non-recoverable state, so for now no
			 * point in continuing the parsing process.
			 */
        e.printStackTrace();
    } catch (RuntimeException e) {
        /*
			 * For internal tracing purposes (Eclipse catches runtime exceptions,
			 * and they get hard to track even with the eclipse error log view).
			 */
        e.printStackTrace();
        throw e;
    } catch (ScannerException e) {
        throw new ParserException(e);
    }
    if (!anyMatched) {
        throw new ParserException("Not a javacore file. First line: " + first);
    }
    return imageBuilder.getImage();
}
Also used : ParserException(com.ibm.dtfj.javacore.parser.framework.parser.ParserException) ISectionParser(com.ibm.dtfj.javacore.parser.framework.parser.ISectionParser) ILookAheadBuffer(com.ibm.dtfj.javacore.parser.framework.parser.ILookAheadBuffer) IOException(java.io.IOException) ScannerException(com.ibm.dtfj.javacore.parser.framework.scanner.ScannerException) BuilderFailureException(com.ibm.dtfj.javacore.builder.BuilderFailureException) IParserToken(com.ibm.dtfj.javacore.parser.framework.scanner.IParserToken) Iterator(java.util.Iterator) IImageBuilder(com.ibm.dtfj.javacore.builder.IImageBuilder)

Aggregations

BuilderFailureException (com.ibm.dtfj.javacore.builder.BuilderFailureException)1 IImageBuilder (com.ibm.dtfj.javacore.builder.IImageBuilder)1 ILookAheadBuffer (com.ibm.dtfj.javacore.parser.framework.parser.ILookAheadBuffer)1 ISectionParser (com.ibm.dtfj.javacore.parser.framework.parser.ISectionParser)1 ParserException (com.ibm.dtfj.javacore.parser.framework.parser.ParserException)1 IParserToken (com.ibm.dtfj.javacore.parser.framework.scanner.IParserToken)1 ScannerException (com.ibm.dtfj.javacore.parser.framework.scanner.ScannerException)1 IOException (java.io.IOException)1 Iterator (java.util.Iterator)1