Source Code Cross Referenced for DirectorySourceLocation.java in  » IDE-Eclipse » jdt » org » eclipse » jdt » launching » sourcelookup » 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.launching.sourcelookup 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*******************************************************************************
002:         * Copyright (c) 2000, 2007 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.launching.sourcelookup;
011:
012:        import java.io.File;
013:        import java.io.IOException;
014:        import java.io.StringReader;
015:
016:        import javax.xml.parsers.DocumentBuilder;
017:        import javax.xml.parsers.DocumentBuilderFactory;
018:        import javax.xml.parsers.ParserConfigurationException;
019:
020:        import org.eclipse.core.runtime.CoreException;
021:        import org.eclipse.core.runtime.IPath;
022:        import org.eclipse.core.runtime.IStatus;
023:        import org.eclipse.core.runtime.Path;
024:        import org.eclipse.core.runtime.PlatformObject;
025:        import org.eclipse.core.runtime.Status;
026:        import org.eclipse.debug.core.DebugPlugin;
027:        import org.eclipse.jdt.core.IJavaModelStatusConstants;
028:        import org.eclipse.jdt.core.JavaModelException;
029:        import org.eclipse.jdt.internal.launching.LaunchingMessages;
030:        import org.eclipse.jdt.internal.launching.LaunchingPlugin;
031:        import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
032:        import org.w3c.dom.Document;
033:        import org.w3c.dom.Element;
034:        import org.xml.sax.InputSource;
035:        import org.xml.sax.SAXException;
036:        import org.xml.sax.helpers.DefaultHandler;
037:
038:        import com.ibm.icu.text.MessageFormat;
039:
040:        /**
041:         * Locates source elements in a directory in the local
042:         * file system. Returns instances of <code>LocalFileStorage</code>.
043:         * <p>
044:         * This class may be instantiated; it is not intended to be subclassed.
045:         * </p>
046:         * @see IJavaSourceLocation
047:         * @since 2.0
048:         * @deprecated In 3.0, the debug platform provides source lookup facilities that
049:         *  should be used in place of the Java source lookup support provided in 2.0.
050:         *  The new facilities provide a source lookup director that coordinates source
051:         *  lookup among a set of participants, searching a set of source containers.
052:         *  See the following packages: <code>org.eclipse.debug.core.sourcelookup</code>
053:         *  and <code>org.eclipse.debug.core.sourcelookup.containers</code>. This class
054:         *  has been replaced by
055:         *  <code>org.eclipse.debug.core.sourcelookup.containers.DirectorySourceContainer</code>.
056:         */
057:        public class DirectorySourceLocation extends PlatformObject implements 
058:                IJavaSourceLocation {
059:
060:            /**
061:             * The directory associated with this source location
062:             */
063:            private File fDirectory;
064:
065:            /**
066:             * Constructs a new empty source location to be initialized from
067:             * a memento.
068:             */
069:            public DirectorySourceLocation() {
070:            }
071:
072:            /**
073:             * Constructs a new source location that will retrieve source
074:             * elements from the given directory.
075:             * 
076:             * @param directory a directory
077:             */
078:            public DirectorySourceLocation(File directory) {
079:                setDirectory(directory);
080:            }
081:
082:            /* (non-Javadoc)
083:             * @see org.eclipse.jdt.launching.sourcelookup.IJavaSourceLocation#findSourceElement(java.lang.String)
084:             */
085:            public Object findSourceElement(String name) throws CoreException {
086:                if (getDirectory() == null) {
087:                    return null;
088:                }
089:
090:                String pathStr = name.replace('.', '/');
091:                int lastSlash = pathStr.lastIndexOf('/');
092:                try {
093:                    IPath root = new Path(getDirectory().getCanonicalPath());
094:                    boolean possibleInnerType = false;
095:                    String typeName = pathStr;
096:                    do {
097:                        IPath filePath = root.append(new Path(typeName
098:                                + ".java")); //$NON-NLS-1$
099:                        File file = filePath.toFile();
100:                        if (file.exists()) {
101:                            return new LocalFileStorage(file);
102:                        }
103:                        int index = typeName.lastIndexOf('$');
104:                        if (index > lastSlash) {
105:                            typeName = typeName.substring(0, index);
106:                            possibleInnerType = true;
107:                        } else {
108:                            possibleInnerType = false;
109:                        }
110:                    } while (possibleInnerType);
111:                } catch (IOException e) {
112:                    throw new JavaModelException(e,
113:                            IJavaModelStatusConstants.IO_EXCEPTION);
114:                }
115:                return null;
116:            }
117:
118:            /**
119:             * Sets the directory in which source elements will
120:             * be searched for.
121:             * 
122:             * @param directory a directory
123:             */
124:            private void setDirectory(File directory) {
125:                fDirectory = directory;
126:            }
127:
128:            /**
129:             * Returns the directory associated with this source
130:             * location.
131:             * 
132:             * @return directory
133:             */
134:            public File getDirectory() {
135:                return fDirectory;
136:            }
137:
138:            /* (non-Javadoc)
139:             * @see java.lang.Object#equals(java.lang.Object)
140:             */
141:            public boolean equals(Object object) {
142:                return object instanceof  DirectorySourceLocation
143:                        && getDirectory().equals(
144:                                ((DirectorySourceLocation) object)
145:                                        .getDirectory());
146:            }
147:
148:            /* (non-Javadoc)
149:             * @see java.lang.Object#hashCode()
150:             */
151:            public int hashCode() {
152:                return getDirectory().hashCode();
153:            }
154:
155:            /* (non-Javadoc)
156:             * @see org.eclipse.jdt.launching.sourcelookup.IJavaSourceLocation#getMemento()
157:             */
158:            public String getMemento() throws CoreException {
159:                Document doc = DebugPlugin.newDocument();
160:                Element node = doc.createElement("directorySourceLocation"); //$NON-NLS-1$
161:                doc.appendChild(node);
162:                node.setAttribute("path", getDirectory().getAbsolutePath()); //$NON-NLS-1$
163:                return DebugPlugin.serializeDocument(doc);
164:            }
165:
166:            /* (non-Javadoc)
167:             * @see org.eclipse.jdt.launching.sourcelookup.IJavaSourceLocation#initializeFrom(java.lang.String)
168:             */
169:            public void initializeFrom(String memento) throws CoreException {
170:                Exception ex = null;
171:                try {
172:                    Element root = null;
173:                    DocumentBuilder parser = DocumentBuilderFactory
174:                            .newInstance().newDocumentBuilder();
175:                    parser.setErrorHandler(new DefaultHandler());
176:                    StringReader reader = new StringReader(memento);
177:                    InputSource source = new InputSource(reader);
178:                    root = parser.parse(source).getDocumentElement();
179:
180:                    String path = root.getAttribute("path"); //$NON-NLS-1$
181:                    if (isEmpty(path)) {
182:                        abort(
183:                                LaunchingMessages.DirectorySourceLocation_Unable_to_initialize_source_location___missing_directory_path_3,
184:                                null);
185:                    } else {
186:                        File dir = new File(path);
187:                        if (dir.exists() && dir.isDirectory()) {
188:                            setDirectory(dir);
189:                        } else {
190:                            abort(
191:                                    MessageFormat
192:                                            .format(
193:                                                    LaunchingMessages.DirectorySourceLocation_Unable_to_initialize_source_location___directory_does_not_exist___0__4,
194:                                                    new String[] { path }),
195:                                    null);
196:                        }
197:                    }
198:                    return;
199:                } catch (ParserConfigurationException e) {
200:                    ex = e;
201:                } catch (SAXException e) {
202:                    ex = e;
203:                } catch (IOException e) {
204:                    ex = e;
205:                }
206:                abort(
207:                        LaunchingMessages.DirectorySourceLocation_Exception_occurred_initializing_source_location__5,
208:                        ex);
209:            }
210:
211:            private boolean isEmpty(String string) {
212:                return string == null || string.length() == 0;
213:            }
214:
215:            /*
216:             * Throws an internal error exception
217:             */
218:            private void abort(String message, Throwable e)
219:                    throws CoreException {
220:                IStatus s = new Status(IStatus.ERROR, LaunchingPlugin
221:                        .getUniqueIdentifier(),
222:                        IJavaLaunchConfigurationConstants.ERR_INTERNAL_ERROR,
223:                        message, e);
224:                throw new CoreException(s);
225:            }
226:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.