Search in sources :

Example 21 with InitializationException

use of org.xwiki.component.phase.InitializationException in project xwiki-platform by xwiki.

the class DefaultRenderingCache method initialize.

@Override
public void initialize() throws InitializationException {
    if (this.configuration.isEnabled()) {
        CacheConfiguration cacheConfiguration = new CacheConfiguration();
        cacheConfiguration.setConfigurationId(NAME);
        LRUEvictionConfiguration lru = new LRUEvictionConfiguration();
        lru.setMaxEntries(this.configuration.getSize());
        lru.setLifespan(this.configuration.getDuration());
        cacheConfiguration.put(LRUEvictionConfiguration.CONFIGURATIONID, lru);
        try {
            this.cache.create(cacheConfiguration);
        } catch (CacheException e) {
            throw new InitializationException("Failed to initialize core rendering cache", e);
        }
    }
}
Also used : CacheException(org.xwiki.cache.CacheException) LRUEvictionConfiguration(org.xwiki.cache.eviction.LRUEvictionConfiguration) InitializationException(org.xwiki.component.phase.InitializationException) CacheConfiguration(org.xwiki.cache.config.CacheConfiguration)

Example 22 with InitializationException

use of org.xwiki.component.phase.InitializationException in project xwiki-platform by xwiki.

the class AbstractDataMigrationManager method initialize.

@Override
public void initialize() throws InitializationException {
    try {
        SortedMap<XWikiDBVersion, XWikiMigration> availableMigrations = new TreeMap<>();
        Map<XWikiDBVersion, XWikiMigration> forcedMigrations = getForcedMigrations();
        if (!forcedMigrations.isEmpty()) {
            availableMigrations.putAll(forcedMigrations);
        } else {
            Set<String> ignoredMigrations = new HashSet<String>(Arrays.asList(getXWikiConfig().getPropertyAsList("xwiki.store.migration.ignored")));
            for (DataMigration migrator : getAllMigrations()) {
                if (ignoredMigrations.contains(migrator.getClass().getName()) || ignoredMigrations.contains(migrator.getVersion().toString())) {
                    continue;
                }
                XWikiMigration migration = new XWikiMigration(migrator, false);
                availableMigrations.put(migrator.getVersion(), migration);
            }
        }
        this.targetVersion = (availableMigrations.size() > 0) ? availableMigrations.lastKey() : new XWikiDBVersion(0);
        this.migrations = availableMigrations.values();
    } catch (Exception e) {
        throw new InitializationException("Migration Manager initialization failed", e);
    }
    this.observationManager.addListener(new WikiDeletedEventListener());
}
Also used : TreeMap(java.util.TreeMap) InitializationException(org.xwiki.component.phase.InitializationException) XWikiException(com.xpn.xwiki.XWikiException) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) InitializationException(org.xwiki.component.phase.InitializationException) HashSet(java.util.HashSet)

Example 23 with InitializationException

use of org.xwiki.component.phase.InitializationException 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 24 with InitializationException

use of org.xwiki.component.phase.InitializationException 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

InitializationException (org.xwiki.component.phase.InitializationException)24 ComponentLookupException (org.xwiki.component.manager.ComponentLookupException)9 CacheException (org.xwiki.cache.CacheException)8 CacheConfiguration (org.xwiki.cache.config.CacheConfiguration)8 IOException (java.io.IOException)4 CacheFactory (org.xwiki.cache.CacheFactory)4 InputStream (java.io.InputStream)3 LRUEvictionConfiguration (org.xwiki.cache.eviction.LRUEvictionConfiguration)3 DefaultComponentDescriptor (org.xwiki.component.descriptor.DefaultComponentDescriptor)2 ComponentRepositoryException (org.xwiki.component.manager.ComponentRepositoryException)2 CompositeFilterStreamDescriptor (org.xwiki.filter.descriptor.CompositeFilterStreamDescriptor)2 FilterStreamDescriptor (org.xwiki.filter.descriptor.FilterStreamDescriptor)2 EntityReference (org.xwiki.model.reference.EntityReference)2 XWikiContext (com.xpn.xwiki.XWikiContext)1 XWikiException (com.xpn.xwiki.XWikiException)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 StringReader (java.io.StringReader)1 Type (java.lang.reflect.Type)1 ArrayList (java.util.ArrayList)1