Source Code Cross Referenced for PatternSearchJob.java in  » IDE-Eclipse » jdt » org » eclipse » jdt » internal » core » search » 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.core.search 
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.internal.core.search;
011:
012:        import java.io.IOException;
013:
014:        import org.eclipse.core.runtime.IPath;
015:        import org.eclipse.core.runtime.IProgressMonitor;
016:        import org.eclipse.core.runtime.OperationCanceledException;
017:        import org.eclipse.jdt.core.search.*;
018:        import org.eclipse.jdt.internal.core.JavaModelManager;
019:        import org.eclipse.jdt.internal.core.index.Index;
020:        import org.eclipse.jdt.internal.core.search.indexing.IndexManager;
021:        import org.eclipse.jdt.internal.core.search.indexing.ReadWriteMonitor;
022:        import org.eclipse.jdt.internal.core.search.matching.MatchLocator;
023:        import org.eclipse.jdt.internal.core.search.processing.IJob;
024:        import org.eclipse.jdt.internal.core.search.processing.JobManager;
025:        import org.eclipse.jdt.internal.core.util.Util;
026:
027:        public class PatternSearchJob implements  IJob {
028:
029:            protected SearchPattern pattern;
030:            protected IJavaSearchScope scope;
031:            protected SearchParticipant participant;
032:            protected IndexQueryRequestor requestor;
033:            protected boolean areIndexesReady;
034:            protected long executionTime = 0;
035:
036:            public PatternSearchJob(SearchPattern pattern,
037:                    SearchParticipant participant, IJavaSearchScope scope,
038:                    IndexQueryRequestor requestor) {
039:                this .pattern = pattern;
040:                this .participant = participant;
041:                this .scope = scope;
042:                this .requestor = requestor;
043:            }
044:
045:            public boolean belongsTo(String jobFamily) {
046:                return true;
047:            }
048:
049:            public void cancel() {
050:                // search job is cancelled through progress 
051:            }
052:
053:            public void ensureReadyToRun() {
054:                if (!this .areIndexesReady)
055:                    getIndexes(null/*progress*/); // may trigger some index recreation
056:            }
057:
058:            public boolean execute(IProgressMonitor progressMonitor) {
059:                if (progressMonitor != null && progressMonitor.isCanceled())
060:                    throw new OperationCanceledException();
061:
062:                boolean isComplete = COMPLETE;
063:                executionTime = 0;
064:                Index[] indexes = getIndexes(progressMonitor);
065:                try {
066:                    int max = indexes.length;
067:                    if (progressMonitor != null)
068:                        progressMonitor.beginTask("", max); //$NON-NLS-1$
069:                    for (int i = 0; i < max; i++) {
070:                        isComplete &= search(indexes[i], progressMonitor);
071:                        if (progressMonitor != null) {
072:                            if (progressMonitor.isCanceled())
073:                                throw new OperationCanceledException();
074:                            progressMonitor.worked(1);
075:                        }
076:                    }
077:                    if (JobManager.VERBOSE)
078:                        Util
079:                                .verbose("-> execution time: " + executionTime + "ms - " + this );//$NON-NLS-1$//$NON-NLS-2$
080:                    return isComplete;
081:                } finally {
082:                    if (progressMonitor != null)
083:                        progressMonitor.done();
084:                }
085:            }
086:
087:            public Index[] getIndexes(IProgressMonitor progressMonitor) {
088:                // acquire the in-memory indexes on the fly
089:                IPath[] indexLocations = this .participant.selectIndexes(
090:                        this .pattern, this .scope);
091:                int length = indexLocations.length;
092:                Index[] indexes = new Index[length];
093:                int count = 0;
094:                IndexManager indexManager = JavaModelManager.getIndexManager();
095:                for (int i = 0; i < length; i++) {
096:                    if (progressMonitor != null && progressMonitor.isCanceled())
097:                        throw new OperationCanceledException();
098:                    // may trigger some index recreation work
099:                    IPath indexLocation = indexLocations[i];
100:                    Index index = indexManager.getIndex(indexLocation);
101:                    if (index == null) {
102:                        // only need containerPath if the index must be built
103:                        IPath containerPath = (IPath) indexManager.indexLocations
104:                                .keyForValue(indexLocation);
105:                        if (containerPath != null) // sanity check
106:                            index = indexManager.getIndex(containerPath,
107:                                    indexLocation, true /*reuse index file*/,
108:                                    false /*do not create if none*/);
109:                    }
110:                    if (index != null)
111:                        indexes[count++] = index; // only consider indexes which are ready
112:                }
113:                if (count == length)
114:                    this .areIndexesReady = true;
115:                else
116:                    System.arraycopy(indexes, 0, indexes = new Index[count], 0,
117:                            count);
118:                return indexes;
119:            }
120:
121:            public boolean search(Index index, IProgressMonitor progressMonitor) {
122:                if (index == null)
123:                    return COMPLETE;
124:                if (progressMonitor != null && progressMonitor.isCanceled())
125:                    throw new OperationCanceledException();
126:
127:                ReadWriteMonitor monitor = index.monitor;
128:                if (monitor == null)
129:                    return COMPLETE; // index got deleted since acquired
130:                try {
131:                    monitor.enterRead(); // ask permission to read
132:                    long start = System.currentTimeMillis();
133:                    MatchLocator.findIndexMatches(this .pattern, index,
134:                            requestor, this .participant, this .scope,
135:                            progressMonitor);
136:                    executionTime += System.currentTimeMillis() - start;
137:                    return COMPLETE;
138:                } catch (IOException e) {
139:                    if (e instanceof  java.io.EOFException)
140:                        e.printStackTrace();
141:                    return FAILED;
142:                } finally {
143:                    monitor.exitRead(); // finished reading
144:                }
145:            }
146:
147:            public String toString() {
148:                return "searching " + pattern.toString(); //$NON-NLS-1$
149:            }
150:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.