KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > speedo > generation > start > ListResourceLocator


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

18
19 package org.objectweb.speedo.generation.start;
20
21 import org.objectweb.speedo.generation.api.SpeedoCompilerParameter;
22
23 import java.io.File JavaDoc;
24 import java.io.IOException JavaDoc;
25 import java.io.InputStream JavaDoc;
26 import java.io.PrintWriter JavaDoc;
27 import java.net.URL JavaDoc;
28 import java.util.ArrayList JavaDoc;
29 import java.util.Collection JavaDoc;
30 import java.util.Iterator JavaDoc;
31 import java.util.List JavaDoc;
32
33
34 /**
35  * Searches resources among a set of files.
36  */

37 public class ListResourceLocator
38     extends ResourceLocatorBase
39     implements ResourceLocator
40 {
41     /**
42      * The map of jdo files.
43      */

44     final ArrayList JavaDoc files = new ArrayList JavaDoc();
45
46     /**
47      * Creates an intsance.
48      */

49     public ListResourceLocator(PrintWriter JavaDoc out,
50                                boolean verbose,
51                                List JavaDoc fileNames,
52                                String JavaDoc dir,
53                                SpeedoCompilerParameter scp)
54         throws IOException JavaDoc
55     {
56         super(out, verbose);
57         Assertion.assertion(fileNames != null);
58         
59         // hash the file objects by their canonical name
60
for (Iterator JavaDoc i = fileNames.iterator(); i.hasNext();) {
61             final String JavaDoc s = (String JavaDoc)i.next();
62
63             // canonicalize file name
64
final File JavaDoc file = new File JavaDoc(dir+File.separator+s);
65             final URL JavaDoc url = file.toURL();
66             final String JavaDoc canonicalName = url.toString();
67
68             Assertion.assertion(canonicalName != null);
69             // ensure file is readable
70
if (!file.canRead()) {
71                 final String JavaDoc msg = getI18N("enhancer.cannot_read_resource", file.toString());
72                 throw new IOException JavaDoc(msg);
73             }
74
75             files.add(file.toString().substring(dir.length()+1));
76
77
78             printMessage(getI18N("enhancer.using_resource",
79                                  canonicalName));
80         }
81     }
82     
83     public Collection JavaDoc getCollectionOfFiles() {
84         ArrayList JavaDoc res = new ArrayList JavaDoc();
85         for (Iterator JavaDoc i = files.iterator();i.hasNext();){
86             String JavaDoc f = (String JavaDoc) i.next();
87             res.add(f);
88         }
89         return res;
90     }
91     
92     
93     /**
94      * Finds a resource with a given name.
95      */

96     public InputStream JavaDoc getInputStreamForResource(String JavaDoc resourceName)
97     {
98         return null; // unused
99
}
100 }
101
Popular Tags