001/**
002 *  Licensed to the Apache Software Foundation (ASF) under one or more
003 *  contributor license agreements.  See the NOTICE file distributed with
004 *  this work for additional information regarding copyright ownership.
005 *  The ASF licenses this file to You under the Apache License, Version 2.0
006 *  (the "License"); you may not use this file except in compliance with
007 *  the License.  You may obtain a copy of the License at
008 *
009 *     http://www.apache.org/licenses/LICENSE-2.0
010 *
011 *  Unless required by applicable law or agreed to in writing, software
012 *  distributed under the License is distributed on an "AS IS" BASIS,
013 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 *  See the License for the specific language governing permissions and
015 *  limitations under the License.
016 */
017package org.apache.xbean.osgi.bundle.util.jar;
018
019import java.io.IOException;
020import java.net.URL;
021import java.security.cert.Certificate;
022import java.util.jar.Attributes;
023import java.util.jar.JarEntry;
024import java.util.jar.Manifest;
025import java.util.zip.ZipEntry;
026
027/**
028 * @version $Rev: 937957 $ $Date: 2010-04-26 10:00:08 +0200 (lun. 26 avril 2010) $
029 */
030public class BundleJarEntry extends JarEntry {
031    private final URL entryURL;
032    private final Manifest manifest;
033
034    public BundleJarEntry(String name, URL entryURL, Manifest manifest) {
035        super(removeSlash(name));
036        this.entryURL = entryURL;
037        this.manifest = manifest;
038    }
039
040    private static String removeSlash(String name) {
041        if (name.startsWith("/")) {
042            name = name.substring(1);
043        }
044        return name;
045    }
046    
047    public URL getEntryURL() {
048        return entryURL;
049    }
050    
051    public Attributes getAttributes() throws IOException {
052        if (manifest == null) {
053            return null;
054        }
055        return manifest.getAttributes(getName());
056    }
057
058    public Certificate[] getCertificates() {
059        return null;
060    }
061
062    public void setTime(long time) throws UnsupportedOperationException {
063        throw new UnsupportedOperationException("Can not change the time of unpacked jar entry");
064    }
065
066    public long getTime() {
067        return -1;
068    }
069
070    public void setSize(long size) throws UnsupportedOperationException {
071        throw new UnsupportedOperationException("Can not change the size of unpacked jar entry");
072    }
073
074    public long getSize() {
075        return -1;
076    }
077
078    public long getCompressedSize() {
079        return getSize();
080    }
081
082    public void setCompressedSize(long compressedSize) {
083        throw new UnsupportedOperationException("Can not change the compressed size of unpacked jar entry");
084    }
085
086    public long getCrc() {
087        return super.getCrc();  
088    }
089
090    public void setCrc(long crc) {
091        throw new UnsupportedOperationException("Can not change the crc of unpacked jar entry");
092    }
093
094    public int getMethod() {
095        return ZipEntry.STORED;
096    }
097
098    public void setMethod(int method) {
099        throw new UnsupportedOperationException("Can not change the method of unpacked jar entry");
100    }
101
102    public byte[] getExtra() {
103        return null;
104    }
105
106    public void setExtra(byte[] extra) {
107        throw new UnsupportedOperationException("Can not change the extra data of unpacked jar entry");
108    }
109
110    public String getComment() {
111        return null;
112    }
113
114    public void setComment(String comment) {
115        throw new UnsupportedOperationException("Can not change the comment of unpacked jar entry");
116    }
117
118    public boolean isDirectory() {
119        return entryURL.getPath().endsWith("/");
120    }
121
122}