KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > edu > umd > cs > findbugs > classfile > impl > FilesystemCodeBaseLocator


1 /*
2  * FindBugs - Find Bugs in Java programs
3  * Copyright (C) 2006, University of Maryland
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  */

19
20 package edu.umd.cs.findbugs.classfile.impl;
21
22 import java.io.File JavaDoc;
23 import java.io.IOException JavaDoc;
24
25 import edu.umd.cs.findbugs.classfile.ICodeBase;
26 import edu.umd.cs.findbugs.classfile.ICodeBaseLocator;
27
28 /**
29  * Codebase locator for files and directories in the filesystem.
30  *
31  * @author David Hovemeyer
32  */

33 public class FilesystemCodeBaseLocator implements ICodeBaseLocator {
34     private final String JavaDoc pathName;
35     
36     public FilesystemCodeBaseLocator(String JavaDoc pathName) {
37         this.pathName = pathName;
38     }
39     
40     /**
41      * @return Returns the pathName.
42      */

43     public String JavaDoc getPathName() {
44         return pathName;
45     }
46
47     /* (non-Javadoc)
48      * @see edu.umd.cs.findbugs.classfile.ICodeBaseLocator#createRelativeCodeBaseLocator(java.lang.String)
49      */

50     public ICodeBaseLocator createRelativeCodeBaseLocator(String JavaDoc relativePath) {
51         File JavaDoc path = new File JavaDoc(pathName);
52         if (!path.isDirectory()) {
53             path = path.getParentFile();
54         }
55         File JavaDoc relativeFile = new File JavaDoc(path, relativePath);
56         return new FilesystemCodeBaseLocator(relativeFile.getPath());
57     }
58
59     /* (non-Javadoc)
60      * @see edu.umd.cs.findbugs.classfile.ICodeBaseLocator#openCodeBase()
61      */

62     public ICodeBase openCodeBase() throws IOException JavaDoc {
63         return ClassFactory.createFilesystemCodeBase(this);
64     }
65
66     /* (non-Javadoc)
67      * @see java.lang.Object#toString()
68      */

69     @Override JavaDoc
70     public String JavaDoc toString() {
71         return "filesystem:" + pathName;
72     }
73     
74     /* (non-Javadoc)
75      * @see java.lang.Object#equals(java.lang.Object)
76      */

77     @Override JavaDoc
78     public boolean equals(Object JavaDoc obj) {
79         if (obj == null || obj.getClass() != this.getClass()) {
80             return false;
81         }
82         FilesystemCodeBaseLocator other = (FilesystemCodeBaseLocator) obj;
83         return this.pathName.equals(other.pathName);
84     }
85     
86     /* (non-Javadoc)
87      * @see java.lang.Object#hashCode()
88      */

89     @Override JavaDoc
90     public int hashCode() {
91         return pathName.hashCode();
92     }
93 }
94
Popular Tags