001package jmri.util.startup; 002 003import java.util.List; 004import javax.annotation.Nonnull; 005 006import jmri.JmriException; 007 008import javax.annotation.CheckForNull; 009 010/** 011 * Startup object models all need to implement this interface. This allows the 012 * {@link StartupActionsManager} to handle lists of different model 013 * classes. 014 * 015 * @author Randall Wood Copyright 2015, 2020 016 */ 017public interface StartupModel { 018 019 /** 020 * Return the name of of the model or its controlled object. 021 * 022 * @return the name, an empty string, or null 023 */ 024 @CheckForNull 025 String getName(); 026 027 /** 028 * Set the name of the model. 029 * 030 * @param name the name, an empty string, or null 031 */ 032 void setName(@CheckForNull String name); 033 034 /** 035 * Test is model is a valid model. Invalid models will not be shown or saved 036 * by the Startup Actions Preferences panel. 037 * 038 * @return true if valid; false otherwise 039 */ 040 boolean isValid(); 041 042 /** 043 * Set whenether this action is enabled or not. 044 * @param value true if enabled, false otherwise 045 */ 046 void setEnabled(boolean value); 047 048 /** 049 * Get whenether this action is enabled or not. 050 * @return true if enabled, false otherwise 051 */ 052 boolean isEnabled(); 053 054 /** 055 * Perform the startup action. 056 * The caller is responsible to ensure that this startup model is enabled 057 * before calling this method. 058 * 059 * @throws JmriException if there is an exception thrown initializing the 060 * startup item; the original exception should be 061 * available as {@link Exception#getCause()} 062 */ 063 void performAction() throws JmriException; 064 065 /** 066 * Get the exceptions thrown by the startup model. 067 * 068 * @return the list of exceptions thrown during startup in order or an empty 069 * list if no exceptions were thrown 070 */ 071 @Nonnull 072 List<Exception> getExceptions(); 073 074 /** 075 * Add an exception to the list of exceptions thrown when loading the model 076 * or performing the action. 077 * 078 * @param exception the exception to retain with the model 079 */ 080 void addException(@Nonnull Exception exception); 081}