use of org.xwiki.component.util.DefaultParameterizedType in project xwiki-platform by xwiki.
the class AbstractResourceReferenceResolver method findResourceResolver.
/**
* Find the right Resolver for the passed Resource type and call it.
*/
protected ResourceReferenceResolver<ExtendedURL> findResourceResolver(String hintPrefix, ResourceType type) throws UnsupportedResourceReferenceException {
ResourceReferenceResolver<ExtendedURL> resolver;
Type roleType = new DefaultParameterizedType(null, ResourceReferenceResolver.class, ExtendedURL.class);
String roleHint = computeResolverHint(hintPrefix, type.getId());
// Step 1: Look for a Resolver specific to the scheme and specific to the Resource Type
if (this.componentManager.hasComponent(roleType, roleHint)) {
try {
resolver = this.componentManager.getInstance(roleType, roleHint);
} catch (ComponentLookupException cle) {
// There's no Resolver registered for the passed Resource Type
throw new UnsupportedResourceReferenceException(String.format("Failed to lookup Resource Reference Resolver for hint [%s]", roleHint), cle);
}
} else {
// schemes
try {
resolver = this.componentManager.getInstance(roleType, type.getId());
} catch (ComponentLookupException cle) {
// There's no Resolver registered for the passed Resource Type
throw new UnsupportedResourceReferenceException(String.format("Failed to lookup Resource Reference Resolver for type [%s]", type), cle);
}
}
return resolver;
}
use of org.xwiki.component.util.DefaultParameterizedType in project xwiki-platform by xwiki.
the class DefaultResourceReferenceSerializer method serialize.
@Override
public ExtendedURL serialize(ResourceReference resource) throws SerializeResourceReferenceException, UnsupportedResourceReferenceException {
ResourceReferenceSerializer<ResourceReference, ExtendedURL> serializer;
ParameterizedType type = new DefaultParameterizedType(null, ResourceReferenceSerializer.class, ResourceReference.class, ExtendedURL.class);
try {
serializer = this.componentManager.getInstance(type, this.urlContextManager.getURLFormatId());
} catch (ComponentLookupException e) {
throw new UnsupportedResourceReferenceException(String.format("Invalid URL format id [%s]. Cannot serialize Resource Reference [%s].", this.urlContextManager.getURLFormatId(), resource), e);
}
return serializer.serialize(resource);
}
use of org.xwiki.component.util.DefaultParameterizedType in project xwiki-platform by xwiki.
the class ComponentScriptServiceTest method configure.
@Before
public void configure() throws Exception {
this.dab = this.mocker.getInstance(DocumentAccessBridge.class);
this.contextComponentManager = this.mocker.registerMockComponent(ComponentManager.class, "context");
Provider<ComponentManager> contextComponentManagerProvider = this.mocker.registerMockComponent(new DefaultParameterizedType(null, Provider.class, ComponentManager.class), "context");
when(contextComponentManagerProvider.get()).thenReturn(this.contextComponentManager);
this.contextrootComponentManager = this.mocker.registerMockComponent(ComponentManager.class, "context/root");
Provider<ComponentManager> contextrootComponentManagerProvider = this.mocker.registerMockComponent(new DefaultParameterizedType(null, Provider.class, ComponentManager.class), "context/root");
when(contextrootComponentManagerProvider.get()).thenReturn(this.contextrootComponentManager);
this.rootComponentManager = this.mocker.registerMockComponent(ComponentManager.class, "root");
this.componentManagerManager = this.mocker.getInstance(ComponentManagerManager.class);
when(this.componentManagerManager.getComponentManager(null, false)).thenReturn(this.rootComponentManager);
this.execution = this.mocker.getInstance(Execution.class);
}
use of org.xwiki.component.util.DefaultParameterizedType in project xwiki-platform by xwiki.
the class DefaultTranslationBundleContextTest method before.
@Before
public void before() throws Exception {
this.mockExecutionContext = new ExecutionContext();
Execution mockExecution = this.mocker.getInstance(Execution.class);
when(mockExecution.getContext()).thenReturn(mockExecutionContext);
this.mockModelContext = this.mocker.getInstance(ModelContext.class);
when(this.mockModelContext.getCurrentEntityReference()).thenReturn(new WikiReference("currentWiki"));
this.mockContextComponentManagerProvider = this.mocker.registerMockComponent(new DefaultParameterizedType(null, Provider.class, ComponentManager.class), "context");
}
use of org.xwiki.component.util.DefaultParameterizedType in project xwiki-platform by xwiki.
the class LocalizationScriptServiceTest method setUp.
@Before
public void setUp() throws Exception {
componentManager = mock(ComponentManager.class);
Provider<ComponentManager> componentManagerProvider = mocker.registerMockComponent(new DefaultParameterizedType(null, Provider.class, ComponentManager.class), "context");
when(componentManagerProvider.get()).thenReturn(componentManager);
renderer = mock(BlockRenderer.class, Syntax.PLAIN_1_0.toIdString());
when(componentManager.getInstance(BlockRenderer.class, Syntax.PLAIN_1_0.toIdString())).thenReturn(renderer);
localizationContext = mocker.getInstance(LocalizationContext.class);
localizationManager = mocker.getInstance(LocalizationManager.class);
localizationScriptService = (LocalizationScriptService) mocker.getComponentUnderTest();
translation = mock(Translation.class);
doAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
WikiPrinter printer = (WikiPrinter) invocation.getArguments()[1];
printer.print("print result");
return null;
}
}).when(renderer).render(eq(new WordBlock("message")), any(WikiPrinter.class));
when(translation.render(Locale.ROOT, ArrayUtils.EMPTY_OBJECT_ARRAY)).thenReturn(new WordBlock("message"));
when(localizationManager.getTranslation("key", Locale.ROOT)).thenReturn(translation);
when(localizationContext.getCurrentLocale()).thenReturn(Locale.ROOT);
environment = mocker.getInstance(Environment.class);
}
Aggregations