KickJava   Java API By Example, From Geeks To Geeks.

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


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.IOException JavaDoc;
23
24 import edu.umd.cs.findbugs.classfile.ICodeBase;
25 import edu.umd.cs.findbugs.classfile.ICodeBaseLocator;
26 import edu.umd.cs.findbugs.classfile.IScannableCodeBase;
27 import edu.umd.cs.findbugs.classfile.ResourceNotFoundException;
28
29 /**
30  * Codebase locator for a zip/jar archive nested inside a parent codebase.
31  *
32  * @author David Hovemeyer
33  */

34 public class NestedZipFileCodeBaseLocator implements ICodeBaseLocator {
35     private final ICodeBase parentCodeBase;
36     private final String JavaDoc resourceName;
37     
38     public NestedZipFileCodeBaseLocator(ICodeBase parentCodeBase, String JavaDoc resourceName) {
39         this.parentCodeBase = parentCodeBase;
40         this.resourceName = resourceName;
41     }
42     
43     /**
44      * @return Returns the parentCodeBase.
45      */

46     public ICodeBase getParentCodeBase() {
47         return parentCodeBase;
48     }
49     
50     /**
51      * @return Returns the resourceName.
52      */

53     public String JavaDoc getResourceName() {
54         return resourceName;
55     }
56
57     /* (non-Javadoc)
58      * @see edu.umd.cs.findbugs.classfile.ICodeBaseLocator#createRelativeCodeBaseLocator(java.lang.String)
59      */

60     public ICodeBaseLocator createRelativeCodeBaseLocator(String JavaDoc relativePath) {
61         // The relative path indicates another codebase (archive) in the same parent codebase
62
return new NestedZipFileCodeBaseLocator(parentCodeBase, relativePath);
63     }
64
65     /* (non-Javadoc)
66      * @see edu.umd.cs.findbugs.classfile.ICodeBaseLocator#openCodeBase()
67      */

68     public ICodeBase openCodeBase() throws ResourceNotFoundException, IOException JavaDoc {
69         return ClassFactory.createNestedZipFileCodeBase(this);
70     }
71
72     /* (non-Javadoc)
73      * @see java.lang.Object#toString()
74      */

75     @Override JavaDoc
76     public String JavaDoc toString() {
77         return "nested:[" + parentCodeBase.getCodeBaseLocator() + "]" + resourceName;
78     }
79     
80     /* (non-Javadoc)
81      * @see java.lang.Object#equals(java.lang.Object)
82      */

83     @Override JavaDoc
84     public boolean equals(Object JavaDoc obj) {
85         if (obj == null || obj.getClass() != this.getClass()) {
86             return false;
87         }
88         NestedZipFileCodeBaseLocator other = (NestedZipFileCodeBaseLocator) obj;
89         return this.parentCodeBase.equals(other.parentCodeBase)
90             && this.resourceName.equals(other.resourceName);
91     }
92     
93     /* (non-Javadoc)
94      * @see java.lang.Object#hashCode()
95      */

96     @Override JavaDoc
97     public int hashCode() {
98         return 7919 * parentCodeBase.hashCode() + resourceName.hashCode();
99     }
100 }
101
Popular Tags