View Javadoc

1   package zeus.concepts.xmlobject.acc;
2   
3   import java.io.File;
4   import java.io.FileNotFoundException;
5   
6   import org.w3c.dom.Document;
7   import org.w3c.dom.Element;
8   
9   import zeus.concepts.xmlobject.Parser;
10  
11  /***
12   * Parser for contacts info files. 
13   */
14  public class ContactsParser extends Parser {
15  
16      /***
17       * Default constructor. 
18       */
19      public ContactsParser() {
20          super();
21      }
22  
23      /***
24       * Construct instance, initialise input source to specified file.
25       */
26      public ContactsParser(File file) throws FileNotFoundException {
27          super(file);
28      }
29  
30      /***
31       * Construct instance, initialise input source to specified document.
32       */
33      public ContactsParser(String document) {
34          super(document);
35      }
36  
37      /***
38       * Begin translation. Creates a Contact or Contacts object and
39       * delegates to it.
40       */
41      protected Object translateRoot(Document document) {
42          Element element = document.getDocumentElement();
43          String tag = element.getTagName();
44          if(tag.equals("contacts")) {
45              Contacts root = new Contacts();
46              root.translate(element);
47              return root;
48          }
49          else if(tag.equals("contact")) {
50              Contact root = new Contact();
51              root.translate(element);
52              return root;
53          }
54          return null;
55      }
56  
57      /***
58       * Retrieve the root object and cast it to a Contacts instance.
59       */
60      public Contacts getContacts() {
61          return (Contacts)getRootObject();
62      }
63  
64      /***
65       * Retrieve the root object and cast it to a Contact instance.
66       */
67      public Contact getContact() {
68          return (Contact)getRootObject();
69      }
70  
71  }