KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > cobertura > instrument > CoberturaFile


1 /*
2  * Cobertura - http://cobertura.sourceforge.net/
3  *
4  * Copyright (C) 2006 John Lewis
5  *
6  * Note: This file is dual licensed under the GPL and the Apache
7  * Source License (so that it can be used from both the main
8  * Cobertura classes and the ant tasks).
9  *
10  * Cobertura is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published
12  * by the Free Software Foundation; either version 2 of the License,
13  * or (at your option) any later version.
14  *
15  * Cobertura is distributed in the hope that it will be useful, but
16  * WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  * General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Cobertura; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
23  * USA
24  */

25
26 package net.sourceforge.cobertura.instrument;
27
28 import java.io.File JavaDoc;
29
30 import net.sourceforge.cobertura.util.ArchiveUtil;
31
32 /**
33  * This represents a regular File, but unlike java.io.File, the baseDir and
34  * relative pathname used to create it are saved for later use.
35  *
36  * @author John Lewis
37  */

38 class CoberturaFile extends File JavaDoc
39 {
40
41     private static final long serialVersionUID = 0L;
42
43     private String JavaDoc baseDir;
44     private String JavaDoc pathname;
45
46     CoberturaFile(String JavaDoc baseDir, String JavaDoc pathname)
47     {
48         super(baseDir, pathname);
49         this.baseDir = baseDir;
50         this.pathname = pathname;
51     }
52
53     public String JavaDoc getBaseDir()
54     {
55         return baseDir;
56     }
57
58     public String JavaDoc getPathname()
59     {
60         return pathname;
61     }
62
63     /**
64      * @return True if file has an extension that matches one of the
65      * standard java archives, false otherwise.
66      */

67     boolean isArchive()
68     {
69         if (!isFile())
70         {
71             return false;
72         }
73         return ArchiveUtil.isArchive(pathname);
74     }
75
76     /**
77      * @return True if file has "class" as its extension,
78      * false otherwise.
79      */

80     boolean isClass()
81     {
82         return isFile() && pathname.endsWith(".class");
83     }
84
85     public String JavaDoc toString()
86     {
87         return "pathname=" + pathname + " and baseDir=" + baseDir;
88     }
89
90 }
91
Popular Tags