/** * Creates a chained exception. * * @param action Action being performed at the time of the exception. * @param newException Exception just thrown. * @param previousException Previous exception (may be null). * @return Top level exception in chain. */ private PluginException createChainedException(String action, Throwable newException, PluginException previousException) { String msg = action + " event generated an error."; log.error(msg, newException); PluginException wrapper = new PluginException(msg, previousException == null ? newException : previousException, null); wrapper.setStackTrace(newException.getStackTrace()); return wrapper; }
@Override protected void beforeAddChild(ElementBase child) { super.beforeAddChild(child); if (child instanceof ElementTriggerAction) { if (action != null && action != child) { throw new PluginException("This trigger already has an action."); } } else if (child instanceof ElementTriggerCondition) { if (condition != null && condition != child) { throw new PluginException("This trigger already has a condition."); } } }
/** * Lookup a plugin definition by its id. Raises a runtime exception if the plugin is not found. * * @param id Plugin id. * @return The plugin definition. */ private PluginDefinition pluginById(String id) { PluginDefinition def = pluginRegistry.get(id); if (def == null) { throw new PluginException(EXC_UNKNOWN_PLUGIN, null, null, id); } return def; }
/** * Registers a helper bean with this container. * * @param beanId The bean's id. * @param isRequired If true and the bean is not found, an exception is raised. */ public void registerBean(String beanId, boolean isRequired) { if (beanId == null || beanId.isEmpty()) { return; } Object bean = SpringUtil.getBean(beanId); if (bean == null && isRequired) { throw new PluginException("Required bean resouce not found: " + beanId); } Object oldBean = getAssociatedBean(beanId); if (bean == oldBean) { return; } if (registeredBeans == null) { registeredBeans = new HashMap<>(); } tryRegisterListener(oldBean, false); if (bean == null) { registeredBeans.remove(beanId); } else { registeredBeans.put(beanId, bean); tryRegisterListener(bean, true); tryRegisterController(bean); } }