Search in sources :

Example 96 with ComponentLookupException

use of org.xwiki.component.manager.ComponentLookupException in project xwiki-platform by xwiki.

the class DefaultWikiComponentManager method unregisterWikiComponent.

private void unregisterWikiComponent(Iterator<WikiComponent> iterator) throws WikiComponentException {
    WikiComponent wikiComponent = iterator.next();
    // Save current context information
    DocumentReference currentUserReference = this.wikiComponentManagerContext.getCurrentUserReference();
    EntityReference currentEntityReference = this.wikiComponentManagerContext.getCurrentEntityReference();
    try {
        // Set the proper information so the component manager use the proper keys to find components to
        // unregister
        this.wikiComponentManagerContext.setCurrentUserReference(wikiComponent.getAuthorReference());
        this.wikiComponentManagerContext.setCurrentEntityReference(wikiComponent.getEntityReference());
        // Remove from the Component Manager
        getComponentManager(wikiComponent.getScope()).unregisterComponent(wikiComponent.getRoleType(), wikiComponent.getRoleHint());
        // Remove from the wiki component cache
        iterator.remove();
    } catch (ComponentLookupException e) {
        throw new WikiComponentException(String.format("Failed to find a component manager for scope [%s]", wikiComponent.getScope()), e);
    } finally {
        this.wikiComponentManagerContext.setCurrentUserReference(currentUserReference);
        this.wikiComponentManagerContext.setCurrentEntityReference(currentEntityReference);
    }
}
Also used : WikiComponentException(org.xwiki.component.wiki.WikiComponentException) WikiComponent(org.xwiki.component.wiki.WikiComponent) EntityReference(org.xwiki.model.reference.EntityReference) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) DocumentReference(org.xwiki.model.reference.DocumentReference)

Example 97 with ComponentLookupException

use of org.xwiki.component.manager.ComponentLookupException in project xwiki-platform by xwiki.

the class DefaultWikiComponentManager method registerWikiComponent.

@Override
public void registerWikiComponent(WikiComponent component) throws WikiComponentException {
    // Save current context information
    DocumentReference currentUserReference = this.wikiComponentManagerContext.getCurrentUserReference();
    EntityReference currentEntityReference = this.wikiComponentManagerContext.getCurrentEntityReference();
    try {
        // Get the component role interface
        Type roleType = component.getRoleType();
        Class<?> roleTypeClass = ReflectionUtils.getTypeClass(roleType);
        ComponentDescriptor componentDescriptor = createComponentDescriptor(roleType, component.getRoleHint());
        // Set the proper information so the component manager use the proper keys to find components to register
        this.wikiComponentManagerContext.setCurrentUserReference(component.getAuthorReference());
        this.wikiComponentManagerContext.setCurrentEntityReference(component.getEntityReference());
        // Since we are responsible to create the component instance, we also are responsible of its initialization
        if (this.isInitializable(component.getClass().getInterfaces())) {
            try {
                ((Initializable) component).initialize();
            } catch (InitializationException e) {
                this.logger.error("Failed to initialize wiki component", e);
            }
        }
        // Register the wiki component against the Component Manager
        getComponentManager(component.getScope()).registerComponent(componentDescriptor, roleTypeClass.cast(component));
        // And add it the wiki component cache so that we can remove it later on. We need to do this since we need
        // to be able to unregister a wiki component associated with a wiki page
        cacheWikiComponent(component);
    } catch (ComponentLookupException e) {
        throw new WikiComponentException(String.format("Failed to find a component manager for scope [%s] wiki " + "component registration failed", component.getScope()), e);
    } catch (ComponentRepositoryException e) {
        throw new WikiComponentException("Failed to register wiki component against component repository", e);
    } finally {
        this.wikiComponentManagerContext.setCurrentUserReference(currentUserReference);
        this.wikiComponentManagerContext.setCurrentEntityReference(currentEntityReference);
    }
}
Also used : Type(java.lang.reflect.Type) WikiComponentException(org.xwiki.component.wiki.WikiComponentException) Initializable(org.xwiki.component.phase.Initializable) ComponentDescriptor(org.xwiki.component.descriptor.ComponentDescriptor) DefaultComponentDescriptor(org.xwiki.component.descriptor.DefaultComponentDescriptor) EntityReference(org.xwiki.model.reference.EntityReference) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) ComponentRepositoryException(org.xwiki.component.manager.ComponentRepositoryException) InitializationException(org.xwiki.component.phase.InitializationException) DocumentReference(org.xwiki.model.reference.DocumentReference)

Example 98 with ComponentLookupException

use of org.xwiki.component.manager.ComponentLookupException in project xwiki-platform by xwiki.

the class InstanceInputFilterStreamFactory method getFilterInterfaces.

@Override
public Collection<Class<?>> getFilterInterfaces() throws FilterException {
    List<InstanceInputEventGenerator> eventGenerators;
    try {
        eventGenerators = this.componentManagerProvider.get().getInstanceList(InstanceInputEventGenerator.class);
    } catch (ComponentLookupException e) {
        throw new FilterException("Failed to get registered instance of InstanceInputEventGenerator components", e);
    }
    Set<Class<?>> filters = new HashSet<Class<?>>();
    filters.addAll(super.getFilterInterfaces());
    for (InstanceInputEventGenerator generator : eventGenerators) {
        filters.addAll(generator.getFilterInterfaces());
    }
    return filters;
}
Also used : ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) FilterException(org.xwiki.filter.FilterException) InstanceInputEventGenerator(org.xwiki.filter.instance.input.InstanceInputEventGenerator) HashSet(java.util.HashSet)

Example 99 with ComponentLookupException

use of org.xwiki.component.manager.ComponentLookupException in project xwiki-platform by xwiki.

the class InstanceOutputFilterStream method setProperties.

@Override
public void setProperties(InstanceOutputProperties properties) throws FilterException {
    super.setProperties(properties);
    List<OutputInstanceFilterStreamFactory> factories;
    try {
        factories = this.componentManager.get().getInstanceList(OutputInstanceFilterStreamFactory.class);
    } catch (ComponentLookupException e) {
        throw new FilterException("Failed to get regsitered instance of OutputInstanceFilterStreamFactory components", e);
    }
    Object[] filters = new Object[factories.size()];
    int i = 0;
    for (OutputInstanceFilterStreamFactory factory : factories) {
        filters[i++] = factory.createOutputFilterStream(properties).getFilter();
    }
    this.filter = this.filterManager.createCompositeFilter(filters);
}
Also used : OutputInstanceFilterStreamFactory(org.xwiki.filter.instance.output.OutputInstanceFilterStreamFactory) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) FilterException(org.xwiki.filter.FilterException)

Example 100 with ComponentLookupException

use of org.xwiki.component.manager.ComponentLookupException in project xwiki-platform by xwiki.

the class InstanceOutputFilterStreamFactory method initialize.

@Override
public void initialize() throws InitializationException {
    super.initialize();
    List<OutputInstanceFilterStreamFactory> factories;
    try {
        factories = this.componentManagerProvider.get().getInstanceList(OutputInstanceFilterStreamFactory.class);
    } catch (ComponentLookupException e) {
        throw new InitializationException("Failed to get registered instance of OutputInstanceFilterStreamFactory components", e);
    }
    FilterStreamDescriptor[] descriptors = new FilterStreamDescriptor[factories.size() + 1];
    descriptors[0] = this.descriptor;
    for (int i = 0; i < factories.size(); ++i) {
        descriptors[i + 1] = factories.get(i).getDescriptor();
    }
    setDescriptor(new CompositeFilterStreamDescriptor(this.descriptor.getName(), this.descriptor.getDescription(), descriptors));
}
Also used : CompositeFilterStreamDescriptor(org.xwiki.filter.descriptor.CompositeFilterStreamDescriptor) OutputInstanceFilterStreamFactory(org.xwiki.filter.instance.output.OutputInstanceFilterStreamFactory) CompositeFilterStreamDescriptor(org.xwiki.filter.descriptor.CompositeFilterStreamDescriptor) FilterStreamDescriptor(org.xwiki.filter.descriptor.FilterStreamDescriptor) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) InitializationException(org.xwiki.component.phase.InitializationException)

Aggregations

ComponentLookupException (org.xwiki.component.manager.ComponentLookupException)104 ComponentManager (org.xwiki.component.manager.ComponentManager)24 Test (org.junit.Test)15 DocumentReference (org.xwiki.model.reference.DocumentReference)12 XWikiContext (com.xpn.xwiki.XWikiContext)10 DefaultParameterizedType (org.xwiki.component.util.DefaultParameterizedType)10 InitializationException (org.xwiki.component.phase.InitializationException)8 ArrayList (java.util.ArrayList)7 XWikiException (com.xpn.xwiki.XWikiException)5 HashMap (java.util.HashMap)5 DefaultComponentDescriptor (org.xwiki.component.descriptor.DefaultComponentDescriptor)5 NamespacedComponentManager (org.xwiki.component.manager.NamespacedComponentManager)5 FilterException (org.xwiki.filter.FilterException)5 ExtendedURL (org.xwiki.url.ExtendedURL)5 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)4 Type (java.lang.reflect.Type)4 HashSet (java.util.HashSet)4 WikiComponentException (org.xwiki.component.wiki.WikiComponentException)4 ExecutionContext (org.xwiki.context.ExecutionContext)4 WikiReference (org.xwiki.model.reference.WikiReference)4