use of org.apache.commons.lang3.reflect.ConstructorUtils.invokeConstructor in project webanno by webanno.
the class ApplicationPageBase method commonInit.
private void commonInit() {
Properties settings = SettingsUtil.getSettings();
// Override locale to be used by application
String locale = settings.getProperty(SettingsUtil.CFG_LOCALE, "en");
switch(locale) {
case "auto":
// Do nothing - locale is picked up from browser
break;
default:
// Override the locale in the session
getSession().setLocale(Locale.forLanguageTag(locale));
break;
}
// Add menubar
try {
Class<? extends Component> menubarClass = getApplication().getMetaData(MENUBAR_CLASS);
if (menubarClass == null) {
menubarClass = MenuBar.class;
}
add(ConstructorUtils.invokeConstructor(menubarClass, "menubar"));
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException | InstantiationException e1) {
throw new RuntimeException(e1);
}
feedbackPanel = new BootstrapFeedbackPanel("feedbackPanel");
feedbackPanel.setOutputMarkupId(true);
feedbackPanel.setFilter((IFeedbackMessageFilter) aMessage -> {
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
String username = auth != null ? auth.getName() : "SYSTEM";
if (aMessage.isFatal()) {
LOG.error("{}: {}", username, aMessage.getMessage());
} else if (aMessage.isError()) {
LOG.error("{}: {}", username, aMessage.getMessage());
} else if (aMessage.isWarning()) {
LOG.warn("{}: {}", username, aMessage.getMessage());
} else if (aMessage.isInfo()) {
LOG.info("{}: {}", username, aMessage.getMessage());
} else if (aMessage.isDebug()) {
LOG.debug("{}: {}", username, aMessage.getMessage());
}
return true;
});
add(feedbackPanel);
versionLabel = new Label("version", SettingsUtil.getVersionString());
add(versionLabel);
// set up warnings shown when using an embedded DB or some unsupported browser
boolean isBrowserWarningVisible = isBrowserWarningVisible(settings);
boolean isDatabaseWarningVisible = isDatabaseWarningVisible(settings);
embeddedDbWarning = new Label("embeddedDbWarning", new ResourceModel("warning.database"));
embeddedDbWarning.setVisible(isDatabaseWarningVisible);
add(embeddedDbWarning);
browserWarning = new Label("browserWarning", new ResourceModel("warning.browser"));
browserWarning.setVisible(isBrowserWarningVisible);
add(browserWarning);
WebMarkupContainer warningsContainer = new WebMarkupContainer("warnings");
warningsContainer.setVisible(isBrowserWarningVisible || isDatabaseWarningVisible);
add(warningsContainer);
}
use of org.apache.commons.lang3.reflect.ConstructorUtils.invokeConstructor in project commons-lang by apache.
the class ConstructorUtilsTest method testInvokeConstructor.
@Test
public void testInvokeConstructor() throws Exception {
assertEquals("()", ConstructorUtils.invokeConstructor(TestBean.class, (Object[]) ArrayUtils.EMPTY_CLASS_ARRAY).toString());
assertEquals("()", ConstructorUtils.invokeConstructor(TestBean.class, (Object[]) null).toString());
assertEquals("()", ConstructorUtils.invokeConstructor(TestBean.class).toString());
assertEquals("(String)", ConstructorUtils.invokeConstructor(TestBean.class, "").toString());
assertEquals("(Object)", ConstructorUtils.invokeConstructor(TestBean.class, new Object()).toString());
assertEquals("(Object)", ConstructorUtils.invokeConstructor(TestBean.class, Boolean.TRUE).toString());
assertEquals("(Integer)", ConstructorUtils.invokeConstructor(TestBean.class, NumberUtils.INTEGER_ONE).toString());
assertEquals("(int)", ConstructorUtils.invokeConstructor(TestBean.class, NumberUtils.BYTE_ONE).toString());
assertEquals("(double)", ConstructorUtils.invokeConstructor(TestBean.class, NumberUtils.LONG_ONE).toString());
assertEquals("(double)", ConstructorUtils.invokeConstructor(TestBean.class, NumberUtils.DOUBLE_ONE).toString());
ConstructorUtils.invokeConstructor(TestBean.class, NumberUtils.INTEGER_ONE).verify("(Integer)", null);
ConstructorUtils.invokeConstructor(TestBean.class, "a", "b").verify("(String...)", new String[] { "a", "b" });
ConstructorUtils.invokeConstructor(TestBean.class, NumberUtils.INTEGER_ONE, "a", "b").verify("(Integer, String...)", new String[] { "a", "b" });
ConstructorUtils.invokeConstructor(TestBean.class, new SubClass(), new String[] { "a", "b" }).verify("(BaseClass, String...)", new String[] { "a", "b" });
}
Aggregations