home *** CD-ROM | disk | FTP | other *** search
/ The Net: Ultimate Internet Guide / WWLCD1.ISO / pc / java / un2maiq4 / pjjava / src / pj / io / parserthread.java < prev    next >
Encoding:
Java Source  |  1996-08-14  |  2.8 KB  |  116 lines

  1. /*---------------------------------------------------------------------------
  2.  
  3.     Written by the Personal Journal developers of Dow Jones & Company, Inc.
  4.  
  5.     Dow Jones makes no representations or warranties about 
  6.     the suitability of this software, either express or 
  7.     implied, including but not limited to the implied warranties 
  8.     of merchantability, fitness for a particular purpose, 
  9.     or non-infringement.  Dow Jones will not be liable for 
  10.     any damages suffered by a user as a result of using, 
  11.     modifying or distributing this software or its derivatives.
  12.  
  13.  
  14.     @(#)ParserThread.java   0.00 09-Jan-95
  15.  
  16.         A thread which runs an instance of pj.io.StoryParser.
  17.  
  18.     Authors:
  19.  
  20.         rphall      Rick Hall
  21.  
  22.     Version Ident:
  23.  
  24.         $Header: /PjJavaClient/src/pj/io/ParserThread.java 2     1/21/96 5:27p Rphall $
  25.  
  26.     History:
  27.  
  28.         09-Jan-95    rphall      Initial Creation
  29.  
  30. ---------------------------------------------------------------------------*/
  31.  
  32. package pj.io;
  33.  
  34. import pj.io.Paper;
  35. import pj.io.PaperSection;
  36. import pj.io.StoryContainerNotification;
  37. import pj.io.StoryParser;
  38.  
  39. import java.io.InputStream;
  40. import java.lang.Thread;
  41. import java.util.Observable;
  42. import java.util.Observer;
  43.  
  44.  
  45. /*
  46. * A thread which runs an instance of pj.io.StoryParser.
  47. * @version 0.00, 09-Jan-95
  48. * @author  Rick Hall
  49. */
  50.  
  51. public class ParserThread extends Thread implements Observer
  52.     {
  53.  
  54.  
  55.     // --- Instance variables
  56.  
  57.     private boolean bStayAlive;
  58.     private InputStream isContent;
  59.     private Paper paper;
  60.  
  61.  
  62.  
  63.     // --- Public Constructors
  64.  
  65.     public ParserThread(InputStream is, Paper p)
  66.         {
  67.         bStayAlive = true;
  68.         isContent = is;
  69.         paper = p;
  70.         }
  71.  
  72.  
  73.     // --- Public Operations
  74.  
  75.     public void run()
  76.         {
  77.         // Observe paper
  78.         paper.addObserver(this);
  79.  
  80.         // Create parser and start parsing
  81.         StoryParser parse_obj = new StoryParser(isContent,paper);
  82.         try {
  83.             parse_obj.parse();
  84.             }
  85.         catch(Exception e)
  86.             {
  87.             System.out.println("Debug ParserThread run, exception "
  88.                     + e.toString() );
  89.             }
  90.  
  91.         // Hang out until notified of EOT
  92.         while (bStayAlive);
  93.  
  94.         } // run
  95.  
  96.     public synchronized void update(Observable who, Object arg)
  97.         {
  98.         if ( !(arg instanceof StoryContainerNotification) )
  99.             return;
  100.         StoryContainerNotification scn = (StoryContainerNotification) arg;
  101.         if (scn.newState != PaperSection.stateAdded)
  102.             return;
  103.  
  104.         // Kludge: should define PaperNotificationEOT
  105.         if (scn.strSubsect.equals(Paper.idPcolEOT))
  106.             {
  107.             //isContent.flush();
  108.             bStayAlive = false;
  109.             }
  110.  
  111.         } // update
  112.  
  113.     
  114.  
  115.     } // ParserThread
  116.