Search in sources :

Example 1 with InitializationHandler

use of com.axway.ats.agent.core.model.InitializationHandler in project ats-framework by Axway.

the class ComponentRepository method initializeAllComponents.

public void initializeAllComponents() {
    //initialize the components
    List<Component> components = getAllComponents();
    for (Component component : components) {
        ComponentActionMap actionMap = component.getActionMap();
        Class<? extends InitializationHandler> initClass = actionMap.getInitializationHandler();
        //skip the initialization phase if the component has not declared a handler
        if (initClass != null) {
            String initClassName = initClass.getName();
            try {
                InitializationHandler initHandler = initClass.newInstance();
                initHandler.initializeComponent();
                log.info("Component '" + actionMap.getComponentName() + "' initialized successfully");
            } catch (IllegalAccessException iae) {
                log.error("Could not instantiate initialization handler '" + initClassName + "' - it should have a no-argument public constructor");
            } catch (InstantiationException ie) {
                log.error("Could not instantiate initialization handler '" + initClassName + "' - it should have a no-argument public constructor");
            } catch (Exception e) {
                log.error("Exception during initialization for component '" + actionMap.getComponentName() + "'", e);
            }
        } else {
            log.debug("Component '" + actionMap.getComponentName() + "' does not have an initialization handler");
        }
        //create the component backup if it does not exist yet
        try {
            List<ComponentEnvironment> componentEnvironments = component.getEnvironments();
            if (componentEnvironments != null) {
                for (ComponentEnvironment componentEnvironment : componentEnvironments) {
                    componentEnvironment.backupOnlyIfNotAlreadyDone();
                }
            }
        } catch (AgentException ae) {
            log.error(ae.getMessage(), ae);
        }
    }
}
Also used : AgentException(com.axway.ats.agent.core.exceptions.AgentException) InitializationHandler(com.axway.ats.agent.core.model.InitializationHandler) NoSuchEnvironmentException(com.axway.ats.agent.core.exceptions.NoSuchEnvironmentException) AgentException(com.axway.ats.agent.core.exceptions.AgentException) NoSuchComponentException(com.axway.ats.agent.core.exceptions.NoSuchComponentException) ComponentAlreadyDefinedException(com.axway.ats.agent.core.exceptions.ComponentAlreadyDefinedException)

Aggregations

AgentException (com.axway.ats.agent.core.exceptions.AgentException)1 ComponentAlreadyDefinedException (com.axway.ats.agent.core.exceptions.ComponentAlreadyDefinedException)1 NoSuchComponentException (com.axway.ats.agent.core.exceptions.NoSuchComponentException)1 NoSuchEnvironmentException (com.axway.ats.agent.core.exceptions.NoSuchEnvironmentException)1 InitializationHandler (com.axway.ats.agent.core.model.InitializationHandler)1