package pt.ist.renderers.servlets; import java.util.Set; import javax.servlet.ServletContainerInitializer; import javax.servlet.ServletContext; import javax.servlet.ServletException; import javax.servlet.annotation.HandlesTypes; import org.apache.struts.util.RequestUtils; import pt.ist.renderers.annotation.Renderer; import pt.ist.renderers.annotation.RenderersConfiguration; import pt.ist.renderers.model.MetaObjectFactory; import pt.ist.renderers.model.SchemaFactory; import pt.ist.renderers.model.UserIdentityFactory; import pt.ist.renderers.plugin.ConfigurationReader; @HandlesTypes({ RenderersConfiguration.class, Renderer.class }) public class RenderersFrameworkInitializer implements ServletContainerInitializer { @Override public void onStartup(Set> classes, ServletContext context) throws ServletException { if (classes != null) { for (Class clazz : classes) { RenderersConfiguration config = clazz.getAnnotation(RenderersConfiguration.class); if (config != null) { ConfigurationReader reader = new ConfigurationReader(config.renderers(), config.schemas()); reader.readAll(context); if (!config.metaObjectFactory().equals(MetaObjectFactory.class)) { try { MetaObjectFactory metaObjectFactory = (MetaObjectFactory) RequestUtils.applicationInstance(config .metaObjectFactory().getName()); MetaObjectFactory.setCurrentFactory(metaObjectFactory); } catch (ClassNotFoundException | IllegalAccessException | InstantiationException e) { throw new ServletException(e); } } if (!config.userIdentityFactory().equals(UserIdentityFactory.class)) { try { UserIdentityFactory userIdFactory = (UserIdentityFactory) RequestUtils.applicationInstance(config .userIdentityFactory().getName()); UserIdentityFactory.setCurrentFactory(userIdFactory); } catch (ClassNotFoundException | IllegalAccessException | InstantiationException e) { throw new ServletException(e); } } if (!config.schemaFactory().equals(SchemaFactory.class)) { try { SchemaFactory schemaFactory = (SchemaFactory) RequestUtils.applicationInstance(config.schemaFactory() .getName()); SchemaFactory.setCurrentFactory(schemaFactory); } catch (ClassNotFoundException | IllegalAccessException | InstantiationException e) { throw new ServletException(e); } } } } } } }