KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jaspersoft > jasperserver > api > engine > jasperreports > util > RepositoryResourceClassLoader


1 /*
2  * Copyright (C) 2006 JasperSoft http://www.jaspersoft.com
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed WITHOUT ANY WARRANTY; and without the
10  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11  * See the GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, see http://www.gnu.org/licenses/gpl.txt
15  * or write to:
16  *
17  * Free Software Foundation, Inc.,
18  * 59 Temple Place - Suite 330,
19  * Boston, MA USA 02111-1307
20  */

21 package com.jaspersoft.jasperserver.api.engine.jasperreports.util;
22
23 import java.net.URL JavaDoc;
24 import java.util.Enumeration JavaDoc;
25 import java.util.Map JavaDoc;
26
27 import com.jaspersoft.jasperserver.api.engine.jasperreports.util.repo.RepositoryURLHandlerFactory;
28
29
30 /**
31  * @author Lucian Chirita (lucianc@users.sourceforge.net)
32  * @version $Id: RepositoryResourceClassLoader.java 2995 2006-04-07 14:05:32Z tdanciu $
33  */

34 public class RepositoryResourceClassLoader extends ClassLoader JavaDoc {
35
36     private final Map JavaDoc resourceKeys;
37     private final boolean localURLs;
38
39     public RepositoryResourceClassLoader(ClassLoader JavaDoc parent, Map JavaDoc resourceKeys, boolean localURLs) {
40         super(parent);
41         
42         this.resourceKeys = resourceKeys;
43         this.localURLs = localURLs;
44     }
45
46     protected URL JavaDoc findResource(String JavaDoc name) {
47         return getRepositoryURL(name);
48     }
49
50     protected URL JavaDoc getRepositoryURL(String JavaDoc name) {
51         URL JavaDoc url = null;
52         RepositoryResourceKey resourceKey = (RepositoryResourceKey) resourceKeys.get(name);
53         if (resourceKey != null) {
54             if (localURLs) {
55                 url = RepositoryURLHandlerFactory.createRepoURL(name);
56             } else {
57                 url = RepositoryURLHandlerFactory.createRepoURL(resourceKey.getUri());
58             }
59         }
60         return url;
61     }
62
63     protected Enumeration JavaDoc findResources(String JavaDoc name) {
64         final URL JavaDoc url = getRepositoryURL(name);
65         return new Enumeration JavaDoc() {
66             private Object JavaDoc obj = url;
67
68             public boolean hasMoreElements() {
69                 return obj != null;
70             }
71
72             public Object JavaDoc nextElement() {
73                 Object JavaDoc next = obj;
74                 obj = null;
75                 return next;
76             }
77         };
78     }
79 }
80
Popular Tags