View Javadoc

1   /*
2    * EL4J, the Extension Library for the J2EE, adds incremental enhancements to
3    * the spring framework, http://el4j.sf.net
4    * Copyright (C) 2006 by ELCA Informatique SA, Av. de la Harpe 22-24,
5    * 1000 Lausanne, Switzerland, http://www.elca.ch
6    *
7    * EL4J is published under the GNU Lesser General Public License (LGPL)
8    * Version 2.1. See http://www.gnu.org/licenses/
9    *
10   * This program 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
13   * GNU Lesser General Public License for more details.
14   *
15   * For alternative licensing, please contact info@elca.ch
16   */
17  package ch.elca.el4j.core.io;
18  
19  import java.io.IOException;
20  import java.io.InputStream;
21  import java.net.URL;
22  
23  import org.springframework.core.io.ClassPathResource;
24  import org.springframework.util.Assert;
25  
26  /**
27   * This is an explicit class path resource. A normal class path resource has
28   * only a path that can point to multiple resources. By using the given url too
29   * this resource explicitly points to one resource.
30   *
31   * @svnLink $Revision: 4010 $;$Date: 2009-12-01 10:59:54 +0100 (Di, 01. Dez 2009) $;$Author: jonasha $;$URL: https://el4j.svn.sourceforge.net/svnroot/el4j/branches/el4j_3_1/el4j/framework/modules/core/src/main/java/ch/elca/el4j/core/io/ExplicitClassPathResource.java $
32   *
33   * @author Martin Zeltner (MZE)
34   */
35  public class ExplicitClassPathResource extends ClassPathResource {
36  	/**
37  	 * See {@link #getURL()}.
38  	 */
39  	private URL m_url;
40  
41  	/**
42  	 * Constructor with an explicit url for the given class path resource.
43  	 *
44  	 * @param url
45  	 *            The explicit url for this class path resource.
46  	 * @param path
47  	 *            The path to get this resource from class loader. This path can
48  	 *            return a different resource than the given url points to.
49  	 * @param classLoader
50  	 *            The class loader used to load the given url.
51  	 */
52  	public ExplicitClassPathResource(URL url, String path,
53  		ClassLoader classLoader) {
54  		super(path, classLoader);
55  		Assert.notNull(url);
56  		m_url = url;
57  	}
58  	
59  	/**
60  	 * @return Returns the explicit url for this class path resource.
61  	 */
62  	@Override
63  	public URL getURL() throws IOException {
64  		return m_url;
65  	}
66  	
67  	/**
68  	 * @return Returns the input stream of the given url.
69  	 */
70  	@Override
71  	public InputStream getInputStream() throws IOException {
72  		return m_url.openStream();
73  	}
74  	
75  	/**
76  	 * {@inheritDoc}
77  	 */
78  	@Override
79  	public boolean equals(Object obj) {
80  		// just to make clear that it is intended to use the method of the superclass
81  		return super.equals(obj);
82  	}
83  	
84  	@Override
85  	public int hashCode() {
86  		// just to make clear that it is intended to use the method of the superclass
87  		return super.hashCode();
88  	}
89  	
90  }