KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > vfs > PathExistsDependency


1 /*
2  * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Resin Open Source is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  *
23  * Free Software Foundation, Inc.
24  * 59 Temple Place, Suite 330
25  * Boston, MA 02111-1307 USA
26  *
27  * @author Scott Ferguson
28  */

29
30 package com.caucho.vfs;
31
32 import java.util.logging.Level JavaDoc;
33 import java.util.logging.Logger JavaDoc;
34
35 /**
36  * Class for keeping track of modifications.
37  */

38 public class PathExistsDependency implements Dependency {
39   private static final Logger JavaDoc log
40     = Logger.getLogger(PathExistsDependency.class.getName());
41   
42   Path _source;
43   boolean _exists;
44
45   /**
46    * Create a new dependency.
47    *
48    * @param source the source file
49    */

50   public PathExistsDependency(Path source)
51   {
52     if (source instanceof JarPath)
53       source = ((JarPath) source).getContainer();
54     
55     _source = source;
56     _exists = source.exists();
57   }
58
59   /**
60    * Create a new dependency with an already known modified time and length.
61    *
62    * @param source the source file
63    */

64   public PathExistsDependency(Path source, boolean exists)
65   {
66     _source = source;
67     _exists = exists;
68   }
69
70   /**
71    * Returns the underlying source path.
72    */

73   public Path getPath()
74   {
75     return _source;
76   }
77
78   /**
79    * If the source modified date changes at all, treat it as a modification.
80    * This protects against the case where multiple computers have
81    * misaligned dates and a '<' comparison may fail.
82    */

83   public boolean isModified()
84   {
85     boolean exists = _source.exists();
86
87     if (exists == _exists)
88       return false;
89     else if (exists) {
90       if (log.isLoggable(Level.FINE))
91         log.fine(_source.getNativePath() + " has been created.");
92
93       return true;
94     }
95     else {
96       if (log.isLoggable(Level.FINE))
97         log.fine(_source.getNativePath() + " has been deleted.");
98       
99       return true;
100     }
101   }
102
103   /**
104    * Returns true if the test Dependency has the same source path as
105    * this dependency.
106    */

107   public boolean equals(Object JavaDoc obj)
108   {
109     if (! (obj instanceof PathExistsDependency))
110       return false;
111
112     PathExistsDependency depend = (PathExistsDependency) obj;
113
114     return _source.equals(depend._source);
115   }
116
117   /**
118    * Returns a printable version of the dependency.
119    */

120   public String JavaDoc toString()
121   {
122     return ("PathExistsDependency[" + _source + "]");
123   }
124 }
125
Popular Tags