Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/wilko/jaim/TocResponseFactory.java


1   /* 
2    *   (C) 2002 Paul Wilkinson  wilko@users.sourceforge.net
3    *
4    *   This program is free software; you can redistribute it and/or modify
5    *   it under the terms of the GNU General Public License as published by
6    *   the Free Software Foundation; either version 2 of the License, or
7    *   (at your option) any later version.
8    *
9    *   This program is distributed in the hope that it will be useful,
10   *   but WITHOUT ANY WARRANTY; without even the implied warranty of
11   *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12   *   GNU General Public License for more details.
13   *
14   *   You should have received a copy of the GNU General Public License
15   *   along with this program; if not, write to the Free Software
16   *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17   *
18   */
19  
20  /*
21   * TocResponseFactory.java
22   *
23   * Created on 4 May 2002, 12:05
24   */
25  
26  package com.wilko.jaim;
27  
28  /**
29   *
30   * @author  paulw
31   * @version $Revision: 1.5 $
32   */
33  
34  import java.util.Vector;
35  
36  public abstract class TocResponseFactory {
37  
38      static Vector responseHandlers = new Vector();
39      
40      /** Creates new TocResponseFactory */
41      public TocResponseFactory() {
42      }
43  
44      public static void addResponseHandler(TocResponseHandler h)
45      {
46          synchronized (responseHandlers)
47          {
48              responseHandlers.add(h);
49          }
50      }
51      
52      static TocResponse createResponse(byte[] b)
53      {
54          TocResponse tr=null;
55          String strversion=new String(b);
56          int colonpos=strversion.indexOf(':');
57          if (colonpos != -1)
58          {
59              String firstWord=strversion.substring(0,colonpos);
60              int i=0;
61              synchronized (responseHandlers)
62              {
63                  while ((i<responseHandlers.size())&&(tr==null))
64                  {
65                      TocResponseHandler h=(TocResponseHandler)responseHandlers.elementAt(i);
66                      if (h.canHandle(firstWord))
67                      {
68                          tr=h.parseString(strversion);
69                      }
70                      i++;
71                  }
72              }
73          }
74          if (tr==null)
75          {
76              GenericTocResponse gtr=new GenericTocResponse();
77              tr=gtr.parseString(strversion);
78          }
79          return(tr);
80      }
81      
82  }