1 11 package org.eclipse.debug.core.sourcelookup.containers; 12 13 import java.util.ArrayList ; 14 import java.util.List ; 15 import org.eclipse.core.runtime.CoreException; 16 import org.eclipse.core.runtime.IStatus; 17 import org.eclipse.core.runtime.MultiStatus; 18 import org.eclipse.debug.core.DebugPlugin; 19 import org.eclipse.debug.core.sourcelookup.ISourceContainer; 20 import org.eclipse.debug.internal.core.sourcelookup.SourceLookupMessages; 21 22 30 public abstract class CompositeSourceContainer extends AbstractSourceContainer { 31 32 private ISourceContainer[] fContainers; 33 34 37 public boolean isComposite() { 38 return true; 39 } 40 41 44 public Object [] findSourceElements(String name) throws CoreException { 45 return findSourceElements(name, getSourceContainers()); 46 } 47 48 68 protected Object [] findSourceElements(String name, ISourceContainer[] containers) throws CoreException { 69 List results = null; 70 CoreException single = null; 71 MultiStatus multiStatus = null; 72 if (isFindDuplicates()) { 73 results = new ArrayList (); 74 } 75 for (int i = 0; i < containers.length; i++) { 76 ISourceContainer container = containers[i]; 77 try { 78 Object [] objects = container.findSourceElements(name); 79 if (objects.length > 0) { 80 if (isFindDuplicates()) { 81 for (int j = 0; j < objects.length; j++) { 82 results.add(objects[j]); 83 } 84 } else { 85 if (objects.length == 1) { 86 return objects; 87 } 88 return new Object []{objects[0]}; 89 } 90 } 91 } catch (CoreException e) { 92 if (single == null) { 93 single = e; 94 } else if (multiStatus == null) { 95 multiStatus = new MultiStatus(DebugPlugin.getUniqueIdentifier(), DebugPlugin.INTERNAL_ERROR, new IStatus[]{single.getStatus()}, SourceLookupMessages.CompositeSourceContainer_0, null); 96 multiStatus.add(e.getStatus()); 97 } else { 98 multiStatus.add(e.getStatus()); 99 } 100 } 101 } 102 if (results == null) { 103 if (multiStatus != null) { 104 throw new CoreException(multiStatus); 105 } else if (single != null) { 106 throw single; 107 } 108 return EMPTY; 109 } 110 return results.toArray(); 111 } 112 113 119 protected abstract ISourceContainer[] createSourceContainers() throws CoreException; 120 121 124 public synchronized ISourceContainer[] getSourceContainers() throws CoreException { 125 if (fContainers == null) { 126 fContainers = createSourceContainers(); 127 for (int i = 0; i < fContainers.length; i++) { 128 ISourceContainer container = fContainers[i]; 129 container.init(getDirector()); 130 } 131 } 132 return fContainers; 133 } 134 135 138 public void dispose() { 139 super.dispose(); 140 if (fContainers != null) { 141 for (int i = 0; i < fContainers.length; i++) { 142 ISourceContainer container = fContainers[i]; 143 container.dispose(); 144 } 145 } 146 fContainers = null; 147 } 148 } 149 | Popular Tags |