KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > core > sourcelookup > AbstractSourceLookupParticipant


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.debug.core.sourcelookup;
12
13 import java.util.ArrayList JavaDoc;
14 import java.util.List JavaDoc;
15
16 import org.eclipse.core.runtime.CoreException;
17 import org.eclipse.core.runtime.IStatus;
18 import org.eclipse.core.runtime.MultiStatus;
19 import org.eclipse.debug.core.DebugPlugin;
20 import org.eclipse.debug.internal.core.sourcelookup.SourceLookupMessages;
21
22
23 /**
24  * Common super class for implementations of source lookup participants.
25  * <p>
26  * Clients implementing source lookup participants should subclass this class.
27  * </p>
28  * @since 3.0
29  */

30 public abstract class AbstractSourceLookupParticipant implements ISourceLookupParticipant {
31     
32     private ISourceLookupDirector fDirector;
33     
34     protected static final Object JavaDoc[] EMPTY = new Object JavaDoc[0];
35     
36     /* (non-Javadoc)
37      * @see org.eclipse.debug.core.sourcelookup.ISourceLookupParticipant#init(org.eclipse.debug.core.sourcelookup.ISourceLookupDirector)
38      */

39     public void init(ISourceLookupDirector director) {
40         fDirector = director;
41     }
42
43     /* (non-Javadoc)
44      * @see org.eclipse.debug.core.sourcelookup.ISourceLookupParticipant#dispose()
45      */

46     public void dispose() {
47         fDirector = null;
48     }
49     
50     /* (non-Javadoc)
51      * @see org.eclipse.debug.core.sourcelookup.ISourceLookupParticipant#findSourceElements(java.lang.Object)
52      */

53     public Object JavaDoc[] findSourceElements(Object JavaDoc object) throws CoreException {
54         List JavaDoc results = null;
55         CoreException single = null;
56         MultiStatus multiStatus = null;
57         if (isFindDuplicates()) {
58             results = new ArrayList JavaDoc();
59         }
60         String JavaDoc name = getSourceName(object);
61         if (name != null) {
62             ISourceContainer[] containers = getSourceContainers();
63             for (int i = 0; i < containers.length; i++) {
64                 try {
65                     ISourceContainer container = getDelegateContainer(containers[i]);
66                     if (container != null) {
67                         Object JavaDoc[] objects = container.findSourceElements(name);
68                         if (objects.length > 0) {
69                             if (isFindDuplicates()) {
70                                 for (int j = 0; j < objects.length; j++) {
71                                     results.add(objects[j]);
72                                 }
73                             } else {
74                                 if (objects.length == 1) {
75                                     return objects;
76                                 }
77                                 return new Object JavaDoc[]{objects[0]};
78                             }
79                         }
80                     }
81                 } catch (CoreException e) {
82                     if (single == null) {
83                         single = e;
84                     } else if (multiStatus == null) {
85                         multiStatus = new MultiStatus(DebugPlugin.getUniqueIdentifier(), DebugPlugin.INTERNAL_ERROR, new IStatus[]{single.getStatus()}, SourceLookupMessages.CompositeSourceContainer_0, null);
86                         multiStatus.add(e.getStatus());
87                     } else {
88                         multiStatus.add(e.getStatus());
89                     }
90                 }
91             }
92         }
93         if (results == null) {
94             if (multiStatus != null) {
95                 throw new CoreException(multiStatus);
96             } else if (single != null) {
97                 throw single;
98             }
99             return EMPTY;
100         }
101         return results.toArray();
102     }
103     
104     /**
105      * Returns the source container to search in place of the given source
106      * container, or <code>null</code> if the given source container is not
107      * to be searched. The default implementation does not translate source
108      * containers. Subclasses should override if required.
109      *
110      * @param container the source container about to be searched (proxy)
111      * @return the source container to be searched (delegate), or <code>null</code>
112      * if the source container should not be searched
113      */

114     protected ISourceContainer getDelegateContainer(ISourceContainer container) {
115         return container;
116     }
117     
118     /**
119      * Returns the source lookup director this participant is registered with
120      * or <code>null</code> if none.
121      *
122      * @return the source lookup director this participant is registered with
123      * or <code>null</code> if none
124      */

125     protected ISourceLookupDirector getDirector() {
126         return fDirector;
127     }
128     
129     /**
130      * Returns whether this participant's source lookup director is configured
131      * to search for duplicate source elements.
132      *
133      * @return whether this participant's source lookup director is configured
134      * to search for duplicate source elements
135      */

136     protected boolean isFindDuplicates() {
137         ISourceLookupDirector director = getDirector();
138         if (director != null) {
139             return director.isFindDuplicates();
140         }
141         return false;
142     }
143     
144     /**
145      * Returns the source containers currently registered with this participant's
146      * source lookup director.
147      *
148      * @return the source containers currently registered with this participant's
149      * source lookup director
150      */

151     protected ISourceContainer[] getSourceContainers() {
152         ISourceLookupDirector director = getDirector();
153         if (director != null) {
154             return director.getSourceContainers();
155         }
156         return new ISourceContainer[0];
157     }
158     
159     /* (non-Javadoc)
160      * @see org.eclipse.debug.core.sourcelookup.ISourceLookupParticipant#sourceContainersChanged(org.eclipse.debug.core.sourcelookup.ISourceLookupDirector)
161      */

162     public void sourceContainersChanged(ISourceLookupDirector director) {
163     }
164 }
165
Popular Tags