KickJava   Java API By Example, From Geeks To Geeks.

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


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 import java.io.InputStream JavaDoc;
24 import java.util.HashMap JavaDoc;
25 import java.util.Iterator JavaDoc;
26 import java.util.Map JavaDoc;
27
28 import edu.umd.cs.findbugs.classfile.ICodeBaseEntry;
29 import edu.umd.cs.findbugs.classfile.ICodeBaseIterator;
30 import edu.umd.cs.findbugs.classfile.ICodeBaseLocator;
31 import edu.umd.cs.findbugs.classfile.IScannableCodeBase;
32 import edu.umd.cs.findbugs.classfile.ResourceNotFoundException;
33
34 /**
35  * Abstract base class for implementations of IScannableCodeBase.
36  * Provides an implementation of the
37  * getCodeBaseLocator(), containsSourceFiles(),
38  * setApplicationCodeBase(), and isApplicationCodeBase() methods.
39  *
40  * @author David Hovemeyer
41  */

42 public abstract class AbstractScannableCodeBase implements IScannableCodeBase {
43     private ICodeBaseLocator codeBaseLocator;
44     private boolean checkedForSourceFiles;
45     private boolean containsSourceFiles;
46     private boolean isAppCodeBase;
47     private int howDiscovered;
48     private long lastModifiedTime;
49     private Map JavaDoc<String JavaDoc, String JavaDoc> resourceNameTranslationMap;
50     
51     public AbstractScannableCodeBase(ICodeBaseLocator codeBaseLocator) {
52         this.codeBaseLocator = codeBaseLocator;
53         this.lastModifiedTime = -1L;
54         this.resourceNameTranslationMap = new HashMap JavaDoc<String JavaDoc, String JavaDoc>();
55     }
56     
57     /* (non-Javadoc)
58      * @see edu.umd.cs.findbugs.classfile.ICodeBase#getCodeBaseLocator()
59      */

60     public ICodeBaseLocator getCodeBaseLocator() {
61         return codeBaseLocator;
62     }
63
64     /* (non-Javadoc)
65      * @see edu.umd.cs.findbugs.classfile.IScannableCodeBase#containsSourceFiles()
66      */

67     public boolean containsSourceFiles() throws InterruptedException JavaDoc {
68         // MUSTFIX
69
if (true) return false;
70         if (!checkedForSourceFiles) {
71             ICodeBaseIterator i = iterator();
72             while (i.hasNext()) {
73                 ICodeBaseEntry entry = i.next();
74                 if (entry.getResourceName().endsWith(".java")) {
75                     containsSourceFiles = true;
76                     break;
77                 }
78             }
79             checkedForSourceFiles = true;
80         }
81         return containsSourceFiles;
82     }
83     
84     /* (non-Javadoc)
85      * @see edu.umd.cs.findbugs.classfile.ICodeBase#setApplicationCodeBase(boolean)
86      */

87     public void setApplicationCodeBase(boolean isAppCodeBase) {
88         this.isAppCodeBase = isAppCodeBase;
89     }
90     
91     /* (non-Javadoc)
92      * @see edu.umd.cs.findbugs.classfile.ICodeBase#isApplicationCodeBase()
93      */

94     public boolean isApplicationCodeBase() {
95         return isAppCodeBase;
96     }
97     
98     /* (non-Javadoc)
99      * @see edu.umd.cs.findbugs.classfile.ICodeBase#setHowDiscovered(int)
100      */

101     public void setHowDiscovered(int howDiscovered) {
102         this.howDiscovered = howDiscovered;
103     }
104     
105     /* (non-Javadoc)
106      * @see edu.umd.cs.findbugs.classfile.ICodeBase#getHowDiscovered()
107      */

108     public int getHowDiscovered() {
109         return howDiscovered;
110     }
111     
112     /* (non-Javadoc)
113      * @see edu.umd.cs.findbugs.classfile.ICodeBase#setLastModifiedTime(long)
114      */

115     public void setLastModifiedTime(long lastModifiedTime) {
116         if (lastModifiedTime > 0) {
117             this.lastModifiedTime = lastModifiedTime;
118         }
119     }
120     
121     /* (non-Javadoc)
122      * @see edu.umd.cs.findbugs.classfile.ICodeBase#getLastModifiedTime()
123      */

124     public long getLastModifiedTime() {
125         return lastModifiedTime;
126     }
127     
128     public void addResourceNameTranslation(String JavaDoc origResourceName, String JavaDoc newResourceName) {
129         resourceNameTranslationMap.put(origResourceName, newResourceName);
130     }
131     
132     public String JavaDoc translateResourceName(String JavaDoc resourceName) {
133         String JavaDoc translatedName = resourceNameTranslationMap.get(resourceName);
134         return translatedName != null ? translatedName : resourceName;
135     }
136 }
137
Popular Tags