View Javadoc

1   /*
2    * Copyright 2001-2004 The Apache Software Foundation.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.jdiagnose.library;
17  
18  import org.jdiagnose.DiagnosticUnit;
19  
20  /***
21   * Ensures that a particular file is available on the classpath.
22   * 
23   * User: jamie
24   * Date: May 31, 2004
25   * Time: 8:38:08 PM
26   */
27  public class ExistsOnClasspathDiagnostic extends DiagnosticUnit {
28      
29      private String filename = null;
30      
31      /***
32       * Create a new diagnostic with a fqn and a filename to check
33       * @param name the name of this diagnostic
34       * @param filename the filename to look for
35       */
36      public ExistsOnClasspathDiagnostic(String name, String filename) {
37          super(name);
38          this.filename = filename;
39      }
40      
41      /***
42       * Default Constructor. Filename property MUST be set.
43       */
44      public ExistsOnClasspathDiagnostic() {
45          super();
46      }
47      
48      /***
49       * Constructs a new diagnostic with a filename.
50       * @param filename the filename to look for
51       */
52      public ExistsOnClasspathDiagnostic(String filename) {
53          super();
54          this.filename = filename;
55      }
56      
57      /***
58       * Checks for the existence of filename on the classpath.
59       */
60      public void diagnoseExistence() {
61          assertNotNull("filename property should not be null", filename);
62          assertNotNull(filename + " could not be found on the classpath",
63                  this.getClass().getResource(filename));
64      }
65      
66      /***
67       * @return Returns the filename.
68       */
69      public String getFilename() {
70          return filename;
71      }
72      
73      /***
74       * @param filename The filename to set.
75       */
76      public void setFilename(String filename) {
77          this.filename = filename;
78      }
79  }