01: /*
02: * This file is part of PFIXCORE.
03: *
04: * PFIXCORE is free software; you can redistribute it and/or modify
05: * it under the terms of the GNU Lesser General Public License as published by
06: * the Free Software Foundation; either version 2 of the License, or
07: * (at your option) any later version.
08: *
09: * PFIXCORE 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
12: * GNU Lesser General Public License for more details.
13: *
14: * You should have received a copy of the GNU Lesser General Public License
15: * along with PFIXCORE; if not, write to the Free Software
16: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17: *
18: */
19:
20: package de.schlund.pfixcore.beans.metadata;
21:
22: import java.io.IOException;
23: import java.net.URL;
24: import java.util.ArrayList;
25: import java.util.Enumeration;
26: import java.util.List;
27:
28: /**
29: * @author mleidig@schlund.de
30: */
31: public class DefaultLocator implements Locator {
32:
33: private final static String DEFAULT_FILE = "beanmetadata.xml";
34: private final static String DEFAULT_LOCATION = "META-INF";
35:
36: List<URL> resources;
37:
38: public DefaultLocator() {
39: resources = getResourcesFromClasspath();
40: }
41:
42: public DefaultLocator(URL additionalResource) {
43: resources = getResourcesFromClasspath();
44: resources.add(additionalResource);
45: }
46:
47: public DefaultLocator(List<URL> additionalResources) {
48: resources = getResourcesFromClasspath();
49: resources.addAll(additionalResources);
50: }
51:
52: public List<URL> getMetadataResources() {
53: return resources;
54: }
55:
56: private List<URL> getResourcesFromClasspath() {
57: try {
58: Enumeration<URL> urls = getClass()
59: .getClassLoader()
60: .getResources(DEFAULT_LOCATION + "/" + DEFAULT_FILE);
61: List<URL> urlList = new ArrayList<URL>();
62: while (urls.hasMoreElements())
63: urlList.add(urls.nextElement());
64: return urlList;
65: } catch (IOException x) {
66: throw new RuntimeException(
67: "Can't get metadata resources from classpath.", x);
68: }
69: }
70:
71: }
|