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     */
017    package org.apache.geronimo.deployment.util;
018    
019    import java.util.jar.JarEntry;
020    import java.util.jar.Attributes;
021    import java.util.jar.Manifest;
022    import java.util.zip.ZipEntry;
023    import java.io.IOException;
024    import java.io.File;
025    import java.security.cert.Certificate;
026    
027    /**
028     * @version $Rev: 476049 $ $Date: 2006-11-16 23:35:17 -0500 (Thu, 16 Nov 2006) $
029     */
030    public class UnpackedJarEntry extends JarEntry {
031        private final File file;
032        private final Manifest manifest;
033    
034        public UnpackedJarEntry(String name, File file, Manifest manifest) {
035            super(name);
036            this.file = file;
037            this.manifest = manifest;
038        }
039    
040        public File getFile() {
041            return file;
042        }
043    
044        public Attributes getAttributes() throws IOException {
045            if (manifest == null) {
046                return null;
047            }
048            return manifest.getAttributes(getName());
049        }
050    
051        /**
052         * Always return null.  This could be implementd by verifing the signatures
053         * in the manifest file against the actual file, but we don't need this for
054         * Geronimo.
055         * @return null
056         */
057        public Certificate[] getCertificates() {
058            return null;
059        }
060    
061        /**
062         * An unpacked jar is read only, so this method always throws an UnsupportedOperationException.
063         * @param time ignored
064         * @throws UnsupportedOperationException always
065         */
066        public void setTime(long time) throws UnsupportedOperationException {
067            throw new UnsupportedOperationException("Can not change the time of unpacked jar entry");
068        }
069    
070        public long getTime() {
071            return file.lastModified();
072        }
073    
074        /**
075         * An unpacked jar is read only, so this method always throws an UnsupportedOperationException.
076         * @param size ignored
077         * @throws UnsupportedOperationException always
078         */
079        public void setSize(long size) throws UnsupportedOperationException {
080            throw new UnsupportedOperationException("Can not change the size of unpacked jar entry");
081        }
082    
083        public long getSize() {
084            if (file.isDirectory()) {
085                return -1;
086            } else {
087                return file.length();
088            }
089        }
090    
091        /**
092         * An unpacked jar is not compressed, so this method returns getSize().
093         * @return getSize()
094         */
095        public long getCompressedSize() {
096            return getSize();
097        }
098    
099        /**
100         * An unpacked jar is read only, so this method always throws an UnsupportedOperationException.
101         * @param compressedSize ignored
102         * @throws UnsupportedOperationException always
103         */
104        public void setCompressedSize(long compressedSize) {
105            throw new UnsupportedOperationException("Can not change the compressed size of unpacked jar entry");
106        }
107    
108        public long getCrc() {
109            return super.getCrc();    //To change body of overridden methods use File | Settings | File Templates.
110        }
111    
112        /**
113         * An unpacked jar is read only, so this method always throws an UnsupportedOperationException.
114         * @param crc ignored
115         * @throws UnsupportedOperationException always
116         */
117        public void setCrc(long crc) {
118            throw new UnsupportedOperationException("Can not change the crc of unpacked jar entry");
119        }
120    
121        public int getMethod() {
122            return ZipEntry.STORED;
123        }
124    
125        /**
126         * An unpacked jar is read only, so this method always throws an UnsupportedOperationException.
127         * @param method ignored
128         * @throws UnsupportedOperationException always
129         */
130        public void setMethod(int method) {
131            throw new UnsupportedOperationException("Can not change the method of unpacked jar entry");
132        }
133    
134        /**
135         * Always returns null.
136         * @return null
137         */
138        public byte[] getExtra() {
139            return null;
140        }
141    
142        /**
143         * An unpacked jar is read only, so this method always throws an UnsupportedOperationException.
144         * @param extra ignored
145         * @throws UnsupportedOperationException always
146         */
147        public void setExtra(byte[] extra) {
148            throw new UnsupportedOperationException("Can not change the extra data of unpacked jar entry");
149        }
150    
151        /**
152         * Always returns null.
153         * @return null
154         */
155        public String getComment() {
156            return null;
157        }
158    
159        /**
160         * An unpacked jar is read only, so this method always throws an UnsupportedOperationException.
161         * @param comment ignored
162         * @throws UnsupportedOperationException always
163         */
164        public void setComment(String comment) {
165            throw new UnsupportedOperationException("Can not change the comment of unpacked jar entry");
166        }
167    
168        public boolean isDirectory() {
169            return file.isDirectory();
170        }
171    
172        public Object clone() {
173            return new UnpackedJarEntry(getName(), file, manifest);
174        }
175    }