Source Code Cross Referenced for ArchiveFileObject.java in  » IDE-Eclipse » jdt » org » eclipse » jdt » internal » compiler » tool » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » IDE Eclipse » jdt » org.eclipse.jdt.internal.compiler.tool 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*******************************************************************************
002:         * Copyright (c) 2006 IBM Corporation and others.
003:         * All rights reserved. This program and the accompanying materials
004:         * are made available under the terms of the Eclipse Public License v1.0
005:         * which accompanies this distribution, and is available at
006:         * http://www.eclipse.org/legal/epl-v10.html
007:         *
008:         * Contributors:
009:         *     IBM Corporation - initial API and implementation
010:         *******************************************************************************/package org.eclipse.jdt.internal.compiler.tool;
011:
012:        import java.io.File;
013:        import java.io.IOException;
014:        import java.io.InputStream;
015:        import java.io.OutputStream;
016:        import java.io.Reader;
017:        import java.io.Writer;
018:        import java.net.URI;
019:        import java.net.URISyntaxException;
020:        import java.nio.charset.Charset;
021:        import java.util.zip.ZipEntry;
022:        import java.util.zip.ZipFile;
023:
024:        import javax.lang.model.element.Modifier;
025:        import javax.lang.model.element.NestingKind;
026:        import javax.tools.JavaFileObject;
027:
028:        import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
029:        import org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader;
030:        import org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException;
031:
032:        /**
033:         * Implementation of a Java file object that corresponds to an entry in a zip/jar file
034:         */
035:        public class ArchiveFileObject implements  JavaFileObject {
036:            private ZipEntry zipEntry;
037:            private ZipFile zipFile;
038:            private String entryName;
039:            private File file;
040:            private Charset charset;
041:
042:            public ArchiveFileObject(File file, ZipFile zipFile,
043:                    String entryName, Charset charset) {
044:                this .zipFile = zipFile;
045:                this .zipEntry = zipFile.getEntry(entryName);
046:                this .entryName = entryName;
047:                this .file = file;
048:                this .charset = charset;
049:            }
050:
051:            /* (non-Javadoc)
052:             * @see javax.tools.JavaFileObject#getAccessLevel()
053:             */
054:            public Modifier getAccessLevel() {
055:                // cannot express multiple modifier
056:                if (getKind() != Kind.CLASS) {
057:                    return null;
058:                }
059:                ClassFileReader reader = null;
060:                try {
061:                    reader = ClassFileReader.read(this .zipFile, this .entryName);
062:                } catch (ClassFormatException e) {
063:                    // ignore
064:                } catch (IOException e) {
065:                    // ignore
066:                }
067:                if (reader == null) {
068:                    return null;
069:                }
070:                final int accessFlags = reader.accessFlags();
071:                if ((accessFlags & ClassFileConstants.AccPublic) != 0) {
072:                    return Modifier.PUBLIC;
073:                }
074:                if ((accessFlags & ClassFileConstants.AccAbstract) != 0) {
075:                    return Modifier.ABSTRACT;
076:                }
077:                if ((accessFlags & ClassFileConstants.AccFinal) != 0) {
078:                    return Modifier.FINAL;
079:                }
080:                return null;
081:            }
082:
083:            /* (non-Javadoc)
084:             * @see javax.tools.JavaFileObject#getKind()
085:             */
086:            public Kind getKind() {
087:                String name = this .entryName.toLowerCase();
088:                if (name.endsWith(Kind.CLASS.extension)) {
089:                    return Kind.CLASS;
090:                } else if (name.endsWith(Kind.SOURCE.extension)) {
091:                    return Kind.SOURCE;
092:                } else if (name.endsWith(Kind.HTML.extension)) {
093:                    return Kind.HTML;
094:                }
095:                return Kind.OTHER;
096:            }
097:
098:            /* (non-Javadoc)
099:             * @see javax.tools.JavaFileObject#getNestingKind()
100:             */
101:            public NestingKind getNestingKind() {
102:                switch (getKind()) {
103:                case SOURCE:
104:                    return NestingKind.TOP_LEVEL;
105:                case CLASS:
106:                    ClassFileReader reader = null;
107:                    try {
108:                        reader = ClassFileReader.read(this .zipFile,
109:                                this .entryName);
110:                    } catch (ClassFormatException e) {
111:                        // ignore
112:                    } catch (IOException e) {
113:                        // ignore
114:                    }
115:                    if (reader == null) {
116:                        return null;
117:                    }
118:                    if (reader.isAnonymous()) {
119:                        return NestingKind.ANONYMOUS;
120:                    }
121:                    if (reader.isLocal()) {
122:                        return NestingKind.LOCAL;
123:                    }
124:                    if (reader.isMember()) {
125:                        return NestingKind.MEMBER;
126:                    }
127:                    return NestingKind.TOP_LEVEL;
128:                default:
129:                    return null;
130:                }
131:            }
132:
133:            /* (non-Javadoc)
134:             * @see javax.tools.JavaFileObject#isNameCompatible(java.lang.String, javax.tools.JavaFileObject.Kind)
135:             */
136:            public boolean isNameCompatible(String simpleName, Kind kind) {
137:                return this .zipEntry.getName().endsWith(
138:                        simpleName + kind.extension);
139:            }
140:
141:            /* (non-Javadoc)
142:             * @see javax.tools.FileObject#delete()
143:             */
144:            public boolean delete() {
145:                throw new UnsupportedOperationException();
146:            }
147:
148:            public boolean equals(Object o) {
149:                if (!(o instanceof  ArchiveFileObject)) {
150:                    return false;
151:                }
152:                ArchiveFileObject archiveFileObject = (ArchiveFileObject) o;
153:                return archiveFileObject.toUri().equals(this .toUri());
154:            }
155:
156:            /* (non-Javadoc)
157:             * @see javax.tools.FileObject#getCharContent(boolean)
158:             */
159:            public CharSequence getCharContent(boolean ignoreEncodingErrors)
160:                    throws IOException {
161:                if (getKind() == Kind.SOURCE) {
162:                    return Util.getCharContents(this , ignoreEncodingErrors,
163:                            org.eclipse.jdt.internal.compiler.util.Util
164:                                    .getZipEntryByteContent(this .zipEntry,
165:                                            this .zipFile), this .charset
166:                                    .toString());
167:                }
168:                return null;
169:            }
170:
171:            /* (non-Javadoc)
172:             * @see javax.tools.FileObject#getLastModified()
173:             */
174:            public long getLastModified() {
175:                return this .zipEntry.getTime(); // looks the closest from the last modification
176:            }
177:
178:            /* (non-Javadoc)
179:             * @see javax.tools.FileObject#getName()
180:             */
181:            public String getName() {
182:                return this .zipEntry.getName();
183:            }
184:
185:            /* (non-Javadoc)
186:             * @see javax.tools.FileObject#openInputStream()
187:             */
188:            public InputStream openInputStream() throws IOException {
189:                return this .zipFile.getInputStream(this .zipEntry);
190:            }
191:
192:            /* (non-Javadoc)
193:             * @see javax.tools.FileObject#openOutputStream()
194:             */
195:            public OutputStream openOutputStream() throws IOException {
196:                throw new UnsupportedOperationException();
197:            }
198:
199:            /* (non-Javadoc)
200:             * @see javax.tools.FileObject#openReader(boolean)
201:             */
202:            public Reader openReader(boolean ignoreEncodingErrors)
203:                    throws IOException {
204:                throw new UnsupportedOperationException();
205:            }
206:
207:            /* (non-Javadoc)
208:             * @see javax.tools.FileObject#openWriter()
209:             */
210:            public Writer openWriter() throws IOException {
211:                throw new UnsupportedOperationException();
212:            }
213:
214:            /* (non-Javadoc)
215:             * @see javax.tools.FileObject#toUri()
216:             */
217:            public URI toUri() {
218:                try {
219:                    return new URI(
220:                            "jar:"  + this .file.toURI().getPath() + "!" + this .zipEntry.getName()); //$NON-NLS-1$//$NON-NLS-2$
221:                } catch (URISyntaxException e) {
222:                    return null;
223:                }
224:            }
225:
226:            @Override
227:            public String toString() {
228:                return this .file.getAbsolutePath()
229:                        + "[" + this .zipEntry.getName() + "]";//$NON-NLS-1$//$NON-NLS-2$
230:            }
231:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.