use of org.xwiki.component.manager.ComponentManager 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.ComponentManager 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.ComponentManager in project xwiki-platform by xwiki.
the class ComponentScriptServiceTest method getComponentManagerForNamespaceWhenProgrammingRights.
@Test
public void getComponentManagerForNamespaceWhenProgrammingRights() throws Exception {
when(this.dab.hasProgrammingRights()).thenReturn(true);
ComponentManager wikiComponentManager = mock(ComponentManager.class);
when(this.componentManagerManager.getComponentManager("wiki:chess", false)).thenReturn(wikiComponentManager);
assertSame(wikiComponentManager, this.mocker.getComponentUnderTest().getComponentManager("wiki:chess"));
}
use of org.xwiki.component.manager.ComponentManager in project xwiki-platform by xwiki.
the class AbstractEnityComponentManagerFactory method createComponentManager.
@Override
public ComponentManager createComponentManager(String namespace, ComponentManager parentComponentManager) {
// Get entity reference
EntityReference reference = this.resolver.resolve(namespace.substring(getEntityType().getLowerCase().length() + 1), getEntityType());
// Get parent reference
EntityReference parentReference = reference.getParent();
ComponentManager parent;
if (parentReference != null) {
// Get parent namespace
String parentNamespace = parentReference.getType().getLowerCase() + ':' + this.serializer.serialize(parentReference);
// Get parent component manager
parent = this.manager.getComponentManager(parentNamespace, true);
} else {
parent = parentComponentManager;
}
return this.defaultFactory.createComponentManager(namespace, parent);
}
use of org.xwiki.component.manager.ComponentManager in project xwiki-platform by xwiki.
the class AbstractEntityComponentManager method getComponentManagerInternal.
@Override
protected ComponentManager getComponentManagerInternal() {
// Get current user reference
EntityReference entityReference = getCurrentReference();
if (entityReference == null) {
return null;
}
ExecutionContext econtext = this.execution.getContext();
// If there is no context don't try to find or register the component manager
if (econtext == null) {
return super.getComponentManagerInternal();
}
// Try to find the user component manager in the context
EntityComponentManagerInstance contextComponentManager = (EntityComponentManagerInstance) econtext.getProperty(this.contextKey);
if (contextComponentManager != null && contextComponentManager.entityReference.equals(entityReference)) {
return contextComponentManager.componentManager;
}
// Fallback on regular user component manager search
ComponentManager componentManager = super.getComponentManagerInternal();
// Cache the component manager
econtext.setProperty(this.contextKey, new EntityComponentManagerInstance(entityReference, componentManager));
return componentManager;
}
Aggregations