001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */
019: package org.apache.axis2.classloader;
020:
021: import java.io.File;
022: import java.io.IOException;
023: import java.io.InputStream;
024: import java.net.JarURLConnection;
025: import java.net.MalformedURLException;
026: import java.net.URL;
027: import java.net.URLConnection;
028: import java.net.URLStreamHandler;
029: import java.security.Permission;
030: import java.security.cert.Certificate;
031: import java.util.jar.Attributes;
032: import java.util.jar.JarEntry;
033: import java.util.jar.JarFile;
034: import java.util.jar.Manifest;
035:
036: /**
037: * @version $Rev: 476049 $ $Date: 2006-11-16 23:35:17 -0500 (Thu, 16 Nov 2006) $
038: */
039: public class JarFileUrlConnection extends JarURLConnection {
040: public static final URL DUMMY_JAR_URL;
041: static {
042: try {
043: DUMMY_JAR_URL = new URL("jar", "", -1, "file:dummy!/",
044: new URLStreamHandler() {
045: protected URLConnection openConnection(URL u) {
046: throw new UnsupportedOperationException();
047: }
048: });
049: } catch (Exception e) {
050: throw new ExceptionInInitializerError(e);
051: }
052: }
053:
054: private final URL url;
055: private final JarFile jarFile;
056: private final JarEntry jarEntry;
057: private final URL jarFileUrl;
058:
059: public JarFileUrlConnection(URL url, JarFile jarFile,
060: JarEntry jarEntry) throws MalformedURLException {
061: super (DUMMY_JAR_URL);
062:
063: if (url == null)
064: throw new NullPointerException("url is null");
065: if (jarFile == null)
066: throw new NullPointerException("jarFile is null");
067: if (jarEntry == null)
068: throw new NullPointerException("jarEntry is null");
069:
070: this .url = url;
071: this .jarFile = jarFile;
072: this .jarEntry = jarEntry;
073: jarFileUrl = new File(jarFile.getName()).toURL();
074: }
075:
076: public JarFile getJarFile() throws IOException {
077: return jarFile;
078: }
079:
080: public synchronized void connect() {
081: }
082:
083: public URL getJarFileURL() {
084: return jarFileUrl;
085: }
086:
087: public String getEntryName() {
088: return getJarEntry().getName();
089: }
090:
091: public Manifest getManifest() throws IOException {
092: return jarFile.getManifest();
093: }
094:
095: public JarEntry getJarEntry() {
096: return jarEntry;
097: }
098:
099: public Attributes getAttributes() throws IOException {
100: return getJarEntry().getAttributes();
101: }
102:
103: public Attributes getMainAttributes() throws IOException {
104: return getManifest().getMainAttributes();
105: }
106:
107: public Certificate[] getCertificates() throws IOException {
108: return getJarEntry().getCertificates();
109: }
110:
111: public URL getURL() {
112: return url;
113: }
114:
115: public int getContentLength() {
116: long size = getJarEntry().getSize();
117: if (size > Integer.MAX_VALUE) {
118: return -1;
119: }
120: return (int) size;
121: }
122:
123: public long getLastModified() {
124: return getJarEntry().getTime();
125: }
126:
127: public synchronized InputStream getInputStream() throws IOException {
128: return jarFile.getInputStream(jarEntry);
129: }
130:
131: public Permission getPermission() throws IOException {
132: URL jarFileUrl = new File(jarFile.getName()).toURL();
133: return jarFileUrl.openConnection().getPermission();
134: }
135:
136: public String toString() {
137: return JarFileUrlConnection.class.getName() + ":" + url;
138: }
139: }
|