KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > virtual > plugins > context > AbstractURLHandler


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2006, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

22 package org.jboss.virtual.plugins.context;
23
24 import java.io.IOException JavaDoc;
25 import java.io.InputStream JavaDoc;
26 import java.net.MalformedURLException JavaDoc;
27 import java.net.URI JavaDoc;
28 import java.net.URISyntaxException JavaDoc;
29 import java.net.URL JavaDoc;
30 import java.net.URLConnection JavaDoc;
31
32 import org.jboss.virtual.VFSUtils;
33 import org.jboss.virtual.spi.VFSContext;
34 import org.jboss.virtual.spi.VirtualFileHandler;
35
36 /**
37  * URLHandler.
38  *
39  * @author <a HREF="adrian@jboss.com">Adrian Brock</a>
40  * @version $Revision: 1.1 $
41  */

42 public abstract class AbstractURLHandler extends AbstractVirtualFileHandler
43 {
44    /** serialVersionUID */
45    private static final long serialVersionUID = 1L;
46
47    /** The url */
48    private final URL JavaDoc url;
49
50    /**
51     * Create a newURLHandler.
52     *
53     * @param context the context
54     * @param parent the parent
55     * @param url the url
56     * @param name the name
57     * @throws IllegalArgumentException for a null context, vfsPath or url
58     */

59    public AbstractURLHandler(VFSContext context, VirtualFileHandler parent, URL JavaDoc url, String JavaDoc name)
60    {
61       super(context, parent, name);
62       if (url == null)
63          throw new IllegalArgumentException JavaDoc("Null url");
64       this.url = url;
65    }
66    
67    /**
68     * Get the url
69     *
70     * @return the url
71     */

72    public URL JavaDoc getURL()
73    {
74       return url;
75    }
76
77    public URL JavaDoc toURL() throws MalformedURLException JavaDoc, URISyntaxException JavaDoc
78    {
79       return getURL();
80    }
81
82    public long getLastModified() throws IOException JavaDoc
83    {
84       checkClosed();
85       URLConnection JavaDoc c = url.openConnection();
86       return c.getLastModified();
87    }
88
89    public long getSize() throws IOException JavaDoc
90    {
91       checkClosed();
92       URLConnection JavaDoc c = url.openConnection();
93       return c.getContentLength();
94    }
95
96    public boolean isHidden() throws IOException JavaDoc
97    {
98       checkClosed();
99       return false;
100    }
101
102    public InputStream JavaDoc openStream() throws IOException JavaDoc
103    {
104       checkClosed();
105       return url.openStream();
106    }
107
108    public URI JavaDoc toURI() throws URISyntaxException JavaDoc
109    {
110       return VFSUtils.toURI(url);
111    }
112 }
113
Popular Tags