* Collects the installable unit fragments that contain locale data for the given locales.
*/
private static synchronized Collector getLocalizationFragments(Locale locale, List localeVariants) {
SoftReference collectorRef = (SoftReference) LocaleCollectorCache.get(locale);
if (collectorRef != null) {
Collector cached = (Collector) collectorRef.get();
if (cached != null) {
return cached;
}
}
final List locales = localeVariants;
Collector localeFragmentCollector = new Collector() {
public boolean accept(Object object) {
boolean haveLocale = false;
if (object instanceof IInstallableUnitFragment) {
IInstallableUnitFragment fragment = (IInstallableUnitFragment) object;
IProvidedCapability[] provides = fragment.getProvidedCapabilities();
for (int j = 0; j < provides.length && !haveLocale; j++) {
IProvidedCapability nextProvide = provides[j];
if (NAMESPACE_IU_LOCALIZATION.equals(nextProvide.getNamespace())) {
String providedLocale = nextProvide.getName();
if (providedLocale != null) {
for (Iterator iter = locales.iterator(); iter.hasNext();) {
if (providedLocale.equals(iter.next())) {
haveLocale = true;
break;
}
}
}
}
}
}
return (haveLocale ? super.accept(object) : true);
}
};
//Due to performance problems we restrict locale lookup to the current profile (see bug 233958)
IProfileRegistry profileRegistry = null;
try {
profileRegistry = (IProfileRegistry) ServiceHolder.getProfileRegistry();
} catch (ProvisioningException e) {
log.warn("Profile registry unavailable. Default language will be used.");
return new Collector();
}
IProfile profile = profileRegistry.getProfile(IProfileRegistry.SELF);
if (profile == null) {
log.warn("Profile unavailable. Default language will be used.");
return new Collector();
}
IUPropertyQuery iuQuery = new IUPropertyQuery(IInstallableUnit.PROP_TYPE_FRAGMENT, "true"); //$NON-NLS-1$
Collector collected = profile.query(iuQuery, localeFragmentCollector, null);
LocaleCollectorCache.put(locale, new SoftReference(collected));
return collected;
}