View Javadoc

1   /**
2    *
3    * Copyright 2004 The Apache Software Foundation
4    *
5    *  Licensed under the Apache License, Version 2.0 (the "License");
6    *  you may not use this file except in compliance with the License.
7    *  You may obtain a copy of the License at
8    *
9    *     http://www.apache.org/licenses/LICENSE-2.0
10   *
11   *  Unless required by applicable law or agreed to in writing, software
12   *  distributed under the License is distributed on an "AS IS" BASIS,
13   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   *  See the License for the specific language governing permissions and
15   *  limitations under the License.
16   */
17  package org.apache.geronimo.deployment.util;
18  
19  import java.util.jar.JarEntry;
20  import java.util.jar.Attributes;
21  import java.util.jar.Manifest;
22  import java.util.zip.ZipEntry;
23  import java.io.IOException;
24  import java.io.File;
25  import java.security.cert.Certificate;
26  
27  /**
28   * @version $Rev: 355877 $ $Date: 2005-12-10 18:48:27 -0800 (Sat, 10 Dec 2005) $
29   */
30  public class UnpackedJarEntry extends JarEntry {
31      private final File file;
32      private final Manifest manifest;
33  
34      public UnpackedJarEntry(String name, File file, Manifest manifest) {
35          super(name);
36          this.file = file;
37          this.manifest = manifest;
38      }
39  
40      public File getFile() {
41          return file;
42      }
43  
44      public Attributes getAttributes() throws IOException {
45          if (manifest == null) {
46              return null;
47          }
48          return manifest.getAttributes(getName());
49      }
50  
51      /**
52       * Always return null.  This could be implementd by verifing the signatures
53       * in the manifest file against the actual file, but we don't need this for
54       * Geronimo.
55       * @return null
56       */
57      public Certificate[] getCertificates() {
58          return null;
59      }
60  
61      /**
62       * An unpacked jar is read only, so this method always throws an UnsupportedOperationException.
63       * @param time ignored
64       * @throws UnsupportedOperationException always
65       */
66      public void setTime(long time) throws UnsupportedOperationException {
67          throw new UnsupportedOperationException("Can not change the time of unpacked jar entry");
68      }
69  
70      public long getTime() {
71          return file.lastModified();
72      }
73  
74      /**
75       * An unpacked jar is read only, so this method always throws an UnsupportedOperationException.
76       * @param size ignored
77       * @throws UnsupportedOperationException always
78       */
79      public void setSize(long size) throws UnsupportedOperationException {
80          throw new UnsupportedOperationException("Can not change the size of unpacked jar entry");
81      }
82  
83      public long getSize() {
84          if (file.isDirectory()) {
85              return -1;
86          } else {
87              return file.length();
88          }
89      }
90  
91      /**
92       * An unpacked jar is not compressed, so this method returns getSize().
93       * @return getSize()
94       */
95      public long getCompressedSize() {
96          return getSize();
97      }
98  
99      /**
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 }