use of org.xwiki.component.manager.ComponentManager in project xwiki-platform by xwiki.
the class MailStorageScriptServiceTest method setUp.
@Before
public void setUp() throws Exception {
Provider<ComponentManager> componentManagerProvider = this.mocker.registerMockComponent(new DefaultParameterizedType(null, Provider.class, ComponentManager.class), "context");
when(componentManagerProvider.get()).thenReturn(this.mocker);
Execution execution = this.mocker.getInstance(Execution.class);
ExecutionContext executionContext = new ExecutionContext();
when(execution.getContext()).thenReturn(executionContext);
}
use of org.xwiki.component.manager.ComponentManager in project xwiki-platform by xwiki.
the class UsersMimeMessageFactoryTest method createMessageWhenNotExistingMimeMessageFactory.
@Test
public void createMessageWhenNotExistingMimeMessageFactory() throws Exception {
DocumentReference userReference = new DocumentReference("wiki", "space", "page");
Map<String, Object> parameters = new HashMap<>();
parameters.put("hint", "factoryHint");
parameters.put("source", "factoryHint");
Provider<ComponentManager> componentManagerProvider = this.mocker.registerMockComponent(new DefaultParameterizedType(null, Provider.class, ComponentManager.class), "context");
when(componentManagerProvider.get()).thenReturn(this.mocker);
try {
this.mocker.getComponentUnderTest().createMessage(Arrays.asList(userReference), parameters);
fail("Should have thrown an exception");
} catch (MessagingException expected) {
assertEquals("Failed to find a [MimeMessageFactory<MimeMessage>] for hint [factoryHint]", expected.getMessage());
}
}
use of org.xwiki.component.manager.ComponentManager in project xwiki-platform by xwiki.
the class DefaultMandatoryDocumentInitializerManager method getMandatoryDocumentInitializer.
@Override
public MandatoryDocumentInitializer getMandatoryDocumentInitializer(DocumentReference documentReference) {
ComponentManager componentManager = this.componentManagerProvider.get();
String fullReference = this.serializer.serialize(documentReference);
try {
if (componentManager.hasComponent(MandatoryDocumentInitializer.class, fullReference)) {
return componentManager.getInstance(MandatoryDocumentInitializer.class, fullReference);
} else {
String localReference = this.localSerializer.serialize(documentReference);
if (componentManager.hasComponent(MandatoryDocumentInitializer.class, localReference)) {
return componentManager.getInstance(MandatoryDocumentInitializer.class, localReference);
}
}
} catch (ComponentLookupException e) {
this.logger.error("Failed to initialize component [{}] for document", MandatoryDocumentInitializer.class, documentReference, e);
}
return null;
}
use of org.xwiki.component.manager.ComponentManager in project xwiki-platform by xwiki.
the class Utils method getComponent.
/**
* Lookup a XWiki component by role and hint.
*
* @param roleType the class (aka role) that the component implements
* @param roleHint a value to differentiate different component implementations for the same role
* @return the component's instance
* @throws RuntimeException if the component cannot be found/initialized, or if the component manager is not
* initialized
* @deprecated starting with 4.1M2 use the Component Script Service instead
*/
@Deprecated
public static <T> T getComponent(Type roleType, String roleHint) {
T component;
ComponentManager componentManager = getContextComponentManager();
if (componentManager != null) {
try {
component = componentManager.getInstance(roleType, roleHint);
} catch (ComponentLookupException e) {
throw new RuntimeException("Failed to load component for type [" + roleType + "] for hint [" + roleHint + "]", e);
}
} else {
throw new RuntimeException("Component manager has not been initialized before lookup for [" + roleType + "] for hint [" + roleHint + "]");
}
return component;
}
use of org.xwiki.component.manager.ComponentManager in project xwiki-platform by xwiki.
the class Utils method getComponentList.
/**
* @param <T> the component type
* @param role the role for which to return implementing components
* @return all components implementing the passed role
* @throws RuntimeException if some of the components cannot be found/initialized, or if the component manager is
* not initialized
* @since 2.0M3
* @deprecated since 4.0M1 use {@link #getComponentManager()} instead
*/
@Deprecated
public static <T> List<T> getComponentList(Class<T> role) {
List<T> components;
ComponentManager componentManager = getContextComponentManager();
if (componentManager != null) {
try {
components = componentManager.getInstanceList(role);
} catch (ComponentLookupException e) {
throw new RuntimeException("Failed to load components with role [" + role.getName() + "]", e);
}
} else {
throw new RuntimeException("Component manager has not been initialized before lookup for role [" + role.getName() + "]");
}
return components;
}
Aggregations