1. /*
  2. * @(#)GTKEngineParser.java 1.6 03/01/23
  3. *
  4. * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package com.sun.java.swing.plaf.gtk;
  8. import java.io.IOException;
  9. /**
  10. * The abstract base class for all theme engine parsers.
  11. *
  12. * @author Shannon Hickey
  13. * @version 1.6 01/23/03
  14. */
  15. abstract class GTKEngineParser {
  16. protected final int uniqueScopeID = GTKScanner.getUniqueScopeID();
  17. /**
  18. * Parse the body of an 'engine' section of an rc file and store
  19. * the results in a <CODE>GTKParser.EngineInfo<CODE> object.
  20. * <P>
  21. * This method takes three parameters. The first is a scanner to
  22. * retrieve tokens from. Configuration options on the scanner may be
  23. * changed by this method, but it must be sure to restore the previous
  24. * values when it has completed. A typical implementation will also
  25. * want to register its own symbols with the scanner. To do so, it should
  26. * save the current scope of the scanner, and then set the scanner's scope
  27. * to the value of 'uniqueScopeID'. Then, it should register its own
  28. * symbols with the scanner if they don't already exist. The int value
  29. * of every symbol registered must be > GTKScanner.TOKEN_LAST.
  30. * At the successful completion of this method, the old scope should be
  31. * restored, but the registered symbols can be left for the next use.
  32. * <P>
  33. * When this method is called, the scanner will be ready to return the first
  34. * token inside the opening '{' of an engine section. Therefore, with the
  35. * exception of returning early in error, this method must continue parsing
  36. * until it sees a matching outer '}', even if it no longer has interest in
  37. * the tokens returned.
  38. * <P>
  39. * The second parameter is the parser that called this method. It should
  40. * not be modified in any way, and has been included only to make available
  41. * its <CODE>resolvePixmapPath</CODE> method for resolving paths to images.
  42. * <P>
  43. * The last parameter will always be a single element array, for returning a
  44. * <CODE>GTKParser.EngineInfo</CODE> object representing the information
  45. * that was parsed. Upon invocation of this method, the array may already
  46. * contain an info object. If so, it is guaranteed that it was created by this
  47. * <CODE>GTKEngineParser</CODE> on a previous call to <CODE>parse</CODE>.
  48. * As such, its type can be assumed. Typically, an implementation will
  49. * want to append to, or merge with the information contained in any passed in
  50. * info object.
  51. * <P>
  52. * Upon successful completion, the information parsed should be stored in
  53. * a <CODE>GTKParser.EngineInfo</CODE> object as element 0 in the array
  54. * parameter. This can be null if we wish to signify, for any reason, that
  55. * that this entire engine section be thrown out and to use the default
  56. * engine instead.
  57. * <P>
  58. * This method should return <CODE>GTKScanner.TOKEN_NONE</CODE>, if successful,
  59. * otherwise the token that it expected but didn't get.
  60. *
  61. * @param scanner The scanner to retrieve tokens from.
  62. * @param parser The parser that called us.
  63. * @param retVal A single element array to store an object containing the
  64. * information parsed.
  65. *
  66. * @return <CODE>GTKScanner.TOKEN_NONE</CODE> if the parse was successful,
  67. * otherwise the token that was expected but not received.
  68. */
  69. abstract int parse(GTKScanner scanner,
  70. GTKParser parser,
  71. GTKParser.EngineInfo[] retVal) throws IOException;
  72. }