KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > lib > cvsclient > command > watchers > WatchersBuilder


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.netbeans.lib.cvsclient.command.watchers;
20
21 import java.io.*;
22
23 import org.netbeans.lib.cvsclient.command.*;
24 import org.netbeans.lib.cvsclient.event.*;
25 import org.netbeans.lib.cvsclient.util.*;
26
27 /**
28  * Handles the building of a watchers information object and the firing of
29  * events when complete objects are built.
30  *
31  * @author Milos Kleint
32  */

33 public class WatchersBuilder implements Builder {
34
35     private static final String JavaDoc UNKNOWN_FILE = "? "; //NOI18N
36

37     /**
38      * The status object that is currently being built.
39      */

40     private WatchersInformation watchersInfo;
41
42     /**
43      * The event manager to use.
44      */

45     private final EventManager eventManager;
46
47     /**
48      * The directory where the command was executed.
49      * Used to compute absolute path to the file.
50      */

51     private final String JavaDoc localPath;
52
53     /**
54      * Creates a WatchersBuilder.
55      * @param eventManager the event manager that will fire events.
56      * @param localPath absolute path to the directory where the command was executed.
57      */

58     public WatchersBuilder(EventManager eventManager, String JavaDoc localPath) {
59         this.eventManager = eventManager;
60         this.localPath = localPath;
61     }
62
63     public void outputDone() {
64         if (watchersInfo != null) {
65             eventManager.fireCVSEvent(new FileInfoEvent(this, watchersInfo));
66             watchersInfo = null;
67         }
68     }
69
70     public void parseLine(String JavaDoc line, boolean isErrorMessage) {
71         if (line.startsWith(UNKNOWN_FILE)) {
72             File file = new File(localPath, line.substring(UNKNOWN_FILE.length()));
73             watchersInfo = new WatchersInformation(file);
74             outputDone();
75             return;
76         }
77
78         if (isErrorMessage) {
79             return;
80         }
81
82         if (line.startsWith(" ") || line.startsWith("\t")) { // NOI18N
83
BugLog.getInstance().assertNotNull(watchersInfo);
84
85             watchersInfo.addWatcher(line);
86             return;
87         }
88
89         // the line starts with file..
90
outputDone();
91         String JavaDoc trimmedLine = line.trim().replace('\t', ' ');
92         int spaceIndex = trimmedLine.indexOf(' ');
93
94         BugLog.getInstance().assertTrue(spaceIndex > 0, "Wrong line = " + line);
95
96         File file = new File(localPath,
97                              trimmedLine.substring(0, spaceIndex));
98         String JavaDoc watcher = trimmedLine.substring(spaceIndex + 1);
99         watchersInfo = new WatchersInformation(file);
100         watchersInfo.addWatcher(watcher);
101     }
102
103     public void parseEnhancedMessage(String JavaDoc key, Object JavaDoc value) {
104     }
105 }
106
Popular Tags