View | Details | Raw Unified | Return to bug 129940 | Differences between
and this patch

Collapse All | Expand All

(-)core/framework/org/eclipse/osgi/framework/internal/core/PackageAdminImpl.java (-1 / +30 lines)
Lines 15-20 Link Here
15
import java.security.AccessController;
15
import java.security.AccessController;
16
import java.security.PrivilegedAction;
16
import java.security.PrivilegedAction;
17
import java.util.ArrayList;
17
import java.util.ArrayList;
18
import java.util.HashMap;
18
import org.eclipse.osgi.framework.adaptor.BundleClassLoader;
19
import org.eclipse.osgi.framework.adaptor.BundleClassLoader;
19
import org.eclipse.osgi.framework.adaptor.BundleData;
20
import org.eclipse.osgi.framework.adaptor.BundleData;
20
import org.eclipse.osgi.framework.debug.Debug;
21
import org.eclipse.osgi.framework.debug.Debug;
Lines 49-55 Link Here
49
public class PackageAdminImpl implements PackageAdmin {
50
public class PackageAdminImpl implements PackageAdmin {
50
	/** framework object */
51
	/** framework object */
51
	protected Framework framework;
52
	protected Framework framework;
52
53
	private HashMap multiSourceCache = new HashMap(5);
53
	/**
54
	/**
54
	 * Constructor.
55
	 * Constructor.
55
	 *
56
	 *
Lines 188-193 Link Here
188
				}
189
				}
189
			}
190
			}
190
			StateDelta stateDelta = framework.adaptor.getState().resolve(descriptions);
191
			StateDelta stateDelta = framework.adaptor.getState().resolve(descriptions);
192
			clearMultiSourceCache();
191
			refreshedBundles = processDelta(stateDelta.getChanges(), refreshPackages);
193
			refreshedBundles = processDelta(stateDelta.getChanges(), refreshPackages);
192
			if (refreshPackages) {
194
			if (refreshPackages) {
193
				AbstractBundle[] allBundles = framework.getAllBundles();
195
				AbstractBundle[] allBundles = framework.getAllBundles();
Lines 586-589 Link Here
586
			}
588
			}
587
		FrameworkProperties.setProperty(Constants.OSGI_IMPL_VERSION_KEY, systemBundle.getVersion().toString());
589
		FrameworkProperties.setProperty(Constants.OSGI_IMPL_VERSION_KEY, systemBundle.getVersion().toString());
588
	}
590
	}
591
592
	MultiSourcePackage createMultiSourcePackage(String id, SingleSourcePackage[] suppliers) {
593
		synchronized (multiSourceCache) {
594
			MultiSourcePackage[] multiSources = (MultiSourcePackage[]) multiSourceCache.get(id);
595
			if (multiSources == null) {
596
				multiSources = new MultiSourcePackage[1];
597
				multiSources[0] = new MultiSourcePackage(id, suppliers);
598
				multiSourceCache.put(id, multiSources);
599
				return multiSources[0];
600
			}
601
			for (int i = 0; i < multiSources.length; i++)
602
				if (multiSources[i].equals(id, suppliers))
603
					return multiSources[i];
604
			MultiSourcePackage[] temp = multiSources;
605
			multiSources = new MultiSourcePackage[temp.length + 1];
606
			System.arraycopy(temp, 0, multiSources, 0, temp.length);
607
			multiSources[temp.length] = new MultiSourcePackage(id, suppliers);
608
			multiSourceCache.put(id, multiSources);
609
			return multiSources[temp.length];
610
		}
611
	}
612
613
	private void clearMultiSourceCache() {
614
		synchronized (multiSourceCache) {
615
			multiSourceCache.clear();
616
		}
617
	}
589
}
618
}
(-)core/framework/org/eclipse/osgi/framework/internal/core/MultiSourcePackage.java (-5 / +22 lines)
Lines 11-21 Link Here
11
package org.eclipse.osgi.framework.internal.core;
11
package org.eclipse.osgi.framework.internal.core;
12
12
13
import java.net.URL;
13
import java.net.URL;
14
import java.util.Enumeration;
14
import java.util.*;
15
import java.util.Vector;
16
15
17
public class MultiSourcePackage extends PackageSource {
16
public class MultiSourcePackage extends PackageSource {
18
	SingleSourcePackage[] suppliers;
17
	private SingleSourcePackage[] suppliers;
18
	private Hashtable cache = new Hashtable(10);
19
19
20
	MultiSourcePackage(String id, SingleSourcePackage[] suppliers) {
20
	MultiSourcePackage(String id, SingleSourcePackage[] suppliers) {
21
		super(id);
21
		super(id);
Lines 27-37 Link Here
27
	}
27
	}
28
28
29
	public Class loadClass(String name) {
29
	public Class loadClass(String name) {
30
		Class result = null;
30
		Class result = (Class) cache.get(name);
31
		if (result != null)
32
			return result;
31
		for (int i = 0; i < suppliers.length; i++) {
33
		for (int i = 0; i < suppliers.length; i++) {
32
			result = suppliers[i].loadClass(name);
34
			result = suppliers[i].loadClass(name);
33
			if (result != null)
35
			if (result != null) {
36
				cache.put(name, result);
34
				return result;
37
				return result;
38
			}
35
		}
39
		}
36
		return result;
40
		return result;
37
	}
41
	}
Lines 67-70 Link Here
67
		}
71
		}
68
		return compoundResults == null ? firstResult : compoundResults.elements();
72
		return compoundResults == null ? firstResult : compoundResults.elements();
69
	}
73
	}
74
75
	public boolean equals(String name, SingleSourcePackage[] sources) {
76
		if (!getId().equals(id))
77
			return false;
78
		if (suppliers == sources)
79
			return true;  // this is really only true if both are null
80
		if (suppliers == null || sources == null || suppliers.length != sources.length)
81
			return false;
82
		for (int i = 0; i < suppliers.length; i++)
83
			if (suppliers[i] != sources[i])
84
				return false; // single source packages are shared; so ref check is good enough
85
		return true;
86
	}
70
}
87
}
(-)core/framework/org/eclipse/osgi/framework/internal/core/BundleLoader.java (-2 / +2 lines)
Lines 218-224 Link Here
218
		return createMultiSource(export.getName(), new PackageSource[] {requiredSource, exportSource});
218
		return createMultiSource(export.getName(), new PackageSource[] {requiredSource, exportSource});
219
	}
219
	}
220
220
221
	private static PackageSource createMultiSource(String packageName, PackageSource[] sources) {
221
	private PackageSource createMultiSource(String packageName, PackageSource[] sources) {
222
		if (sources.length == 1)
222
		if (sources.length == 1)
223
			return sources[0];
223
			return sources[0];
224
		ArrayList sourceList = new ArrayList(sources.length);
224
		ArrayList sourceList = new ArrayList(sources.length);
Lines 228-234 Link Here
228
				if (!sourceList.contains(innerSources[j]))
228
				if (!sourceList.contains(innerSources[j]))
229
					sourceList.add(innerSources[j]);
229
					sourceList.add(innerSources[j]);
230
		}
230
		}
231
		return new MultiSourcePackage(packageName, (SingleSourcePackage[]) sourceList.toArray(new SingleSourcePackage[sourceList.size()]));
231
		return bundle.framework.packageAdmin.createMultiSourcePackage(packageName, (SingleSourcePackage[]) sourceList.toArray(new SingleSourcePackage[sourceList.size()]));
232
	}
232
	}
233
233
234
	/*
234
	/*

Return to bug 129940