use of org.xwiki.component.manager.ComponentLookupException in project xwiki-platform by xwiki.
the class ComponentScriptService method getInstance.
/**
* Find a component instance that implements that passed type. If the component has a singleton lifecycle then this
* method always return the same instance.
*
* @param <T> the component role type
* @param roleType the class (aka role) that the component implements
* @return the component instance or null if not found
* @since 4.0RC1 and modified in 6.1M2 to be public (had package visibility)
*/
public <T> T getInstance(Type roleType) {
T result = null;
ComponentManager cm = getContextComponentManager();
if (cm != null) {
try {
result = cm.getInstance(roleType);
} catch (ComponentLookupException e) {
setError(e);
}
}
return result;
}
use of org.xwiki.component.manager.ComponentLookupException in project xwiki-platform by xwiki.
the class ComponentScriptService method getInstance.
/**
* Find a component instance that implements that passed interface class. If the component has a singleton lifecycle
* then this method always return the same instance.
*
* @param <T> the component role type
* @param roleType the class (aka role) that the component implements
* @param roleHint the hint that differentiates a component implementation from another one (each component is
* registered with a hint; the "default" hint being the default)
* @return the component instance or null if not found
* @since 4.0RC1 and modified in 6.1M2 to be public (had package visibility)
*/
public <T> T getInstance(Type roleType, String roleHint) {
T result = null;
ComponentManager cm = getContextComponentManager();
if (cm != null) {
try {
result = cm.getInstance(roleType, roleHint);
} catch (ComponentLookupException e) {
setError(e);
}
}
return result;
}
use of org.xwiki.component.manager.ComponentLookupException in project xwiki-platform by xwiki.
the class DefaultChartGenerator method generate.
@Override
public byte[] generate(ChartModel model, Map<String, String> parameters) throws ChartGeneratorException {
setDefaultParams(parameters);
String type = parameters.get(TYPE_PARAM);
String title = parameters.get(TITLE_PARAM);
PlotGenerator generator;
try {
generator = contextComponentManager.get().getInstance(PlotGenerator.class, type);
} catch (ComponentLookupException e) {
throw new ChartGeneratorException(String.format("No such chart type : [%s].", type), e);
}
Plot plot = generator.generate(model, parameters);
JFreeChart jfchart = new JFreeChart(title, plot);
// Run customizations
for (ChartCustomizer customizer : this.customizerProvider.get()) {
customizer.customize(jfchart, parameters);
}
int width = Integer.parseInt(parameters.get(WIDTH_PARAM));
int height = Integer.parseInt(parameters.get(HEIGHT_PARAM));
try {
return ChartUtilities.encodeAsPNG(jfchart.createBufferedImage(width, height));
} catch (IOException ex) {
throw new ChartGeneratorException("Error while png encoding the chart image.");
}
}
use of org.xwiki.component.manager.ComponentLookupException in project xwiki-platform by xwiki.
the class DefaultNotificationFilterManager method saveFilterPreferences.
@Override
public void saveFilterPreferences(Set<NotificationFilterPreference> filterPreferences) {
Map<String, Set<NotificationFilterPreference>> preferencesMapping = new HashMap<>();
for (NotificationFilterPreference filterPreference : filterPreferences) {
// Try to get the corresponding provider, if no provider can be found, discard the save of the preference
String providerHint = filterPreference.getProviderHint();
if (componentManager.hasComponent(NotificationFilterPreferenceProvider.class, providerHint)) {
if (!preferencesMapping.containsKey(providerHint)) {
preferencesMapping.put(providerHint, new HashSet<>());
}
preferencesMapping.get(providerHint).add(filterPreference);
}
}
// Once we have created the mapping, save all the preferences using their correct providers
for (String providerHint : preferencesMapping.keySet()) {
try {
NotificationFilterPreferenceProvider provider = componentManager.getInstance(NotificationFilterPreferenceProvider.class, providerHint);
provider.saveFilterPreferences(preferencesMapping.get(providerHint));
} catch (ComponentLookupException e) {
logger.error("Unable to retrieve the notification filter preference provider for hint [{}]: [{}]", providerHint, e);
} catch (NotificationException e) {
logger.warn("Unable save the filter preferences [{}] against the provider [{}]: [{}]", preferencesMapping.get(providerHint), providerHint, ExceptionUtils.getRootCauseMessage(e));
}
}
}
use of org.xwiki.component.manager.ComponentLookupException in project xwiki-platform by xwiki.
the class ModelScriptServiceTest method createDocumentReferenceWhenInvalidHint.
@Test
public void createDocumentReferenceWhenInvalidHint() throws Exception {
when(this.componentManager.getInstance(DocumentReferenceResolver.TYPE_REFERENCE, "invalid")).thenThrow(new ComponentLookupException("error"));
// Make sure backward compatibility is preserved.
when(this.componentManager.getInstance(DocumentReferenceResolver.class, "invalid")).thenThrow(new ComponentLookupException("error"));
Assert.assertNull(this.service.createDocumentReference("wiki", "space", "page", "invalid"));
}
Aggregations