KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > kelp > forte > services > XMLCCleanCompilerGroup


1 /*
2  * Enhydra Java Application Server Project
3  *
4  * The contents of this file are subject to the Enhydra Public License
5  * Version 1.1 (the "License"); you may not use this file except in
6  * compliance with the License. You may obtain a copy of the License on
7  * the Enhydra web site ( http://www.enhydra.org/ ).
8  *
9  * Software distributed under the License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
11  * the License for the specific terms governing rights and limitations
12  * under the License.
13  *
14  * The Initial Developer of the Enhydra Application Server is Lutris
15  * Technologies, Inc. The Enhydra Application Server and portions created
16  * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
17  * All Rights Reserved.
18  *
19  * Contributor(s):
20  * Lisa Reese
21  *
22  */

23
24 package org.enhydra.kelp.forte.services;
25
26 import java.io.IOException JavaDoc;
27 import java.util.*;
28
29 import org.openide.compiler.*;
30 import org.openide.compiler.Compiler;
31 import org.openide.filesystems.*;
32
33 /** Does the work of cleaning up after an external compiler.
34  *
35  * @author rees0234
36  */

37 public class XMLCCleanCompilerGroup extends CompilerGroup {
38
39     private Set compilers = new HashSet (); // Set<XMLCCompilerCleanCompiler>
40

41     public void add (Compiler JavaDoc c) throws IllegalArgumentException JavaDoc {
42         if (! (c instanceof XMLCCleanCompiler)) throw new IllegalArgumentException JavaDoc ();
43         compilers.add (c);
44     }
45
46     public boolean start () {
47         boolean ok = true;
48         Iterator it = compilers.iterator ();
49         while (it.hasNext ()) {
50             XMLCCleanCompiler c = (XMLCCleanCompiler) it.next ();
51             if (c.isUpToDate ()) continue;
52             FileObject fo = c.getFileObject ();
53             FileObject toKill = FileUtil.findBrother (fo, "compiledExt");
54             if (toKill == null) continue;
55             try {
56                 FileLock lock = toKill.lock ();
57                 try {
58                     toKill.delete (lock);
59                     fireProgressEvent (new ProgressEvent (this, fo, ProgressEvent.TASK_WRITING));
60                 } finally {
61                     lock.releaseLock ();
62                 }
63             } catch (IOException JavaDoc ioe) {
64                 fireErrorEvent (new ErrorEvent (this, toKill, 0, 0, ioe.toString (), null));
65                 ok = false;
66             }
67         }
68         return ok;
69     }
70
71 }
72
Popular Tags