/** * Gets a formatter component instance for supplied UPL descriptor and using * application locale. * * @param formatterUpl * the formatter UPL descriptor * @return the formatter component instance * @throws UnifyException * if descriptor refers to unknown formatter type. If an error * occurs */ protected Formatter<?> getApplicationLocaleFormatter(String formatterUpl) throws UnifyException { return (Formatter<?>) getUplComponent(getApplicationLocale(), formatterUpl, true); }
@Override public String getApplicationMessage(String messageKey, Object... params) throws UnifyException { return super.getApplicationMessage(messageKey, params); }
/** * Returns a container setting. * * @param clazz * the setting value type * @param name * the setting name * @return the setting value * @throws UnifyException * if an error occurs */ protected <T> T getContainerSetting(Class<T> clazz, String name) throws UnifyException { return getContainerSetting(clazz, name, null); }
/** * Gets a formatter component instance for supplied UPL descriptor and using * session locale. * * @param formatterUpl * the formatter UPL descriptor * @return the formatter component instance * @throws UnifyException * if descriptor refers to unknown formatter type. If an error * occurs */ protected Formatter<?> getSessionLocaleFormatter(String formatterUpl) throws UnifyException { return (Formatter<?>) getUplComponent(getSessionLocale(), formatterUpl, true); }
/** * Resolves a message string using application locale. A message is resolved by * checking if it is a value enclosed with a tag. If enclosed with a message tag * <em>$m{<value>}</em>, the value is used as a key to obtain a message * resource from the messages component. The obtained message is returned as the * resolved string. If enclosed with a string tag <em>$s{<value>}</em>, * the value is extracted and returned as the resolved string. For any other * condition, the string is returned as is. * * @param message * the message to resolve. * @param params * parameters * @return the resolved string or null if supplied string is null * @throws UnifyException * If an error occurs */ protected String resolveApplicationMessage(String message, Object... params) throws UnifyException { return resolveMessage(getLocale(LocaleType.APPLICATION), message, params); }
@Override public void initialize(UnifyComponentContext unifyComponentContext) throws UnifyException { if (this.unifyComponentContext != null) { throw new UnifyException(UnifyCoreErrorConstants.COMPONENT_ALREADY_INITIALIZED, getName()); } this.unifyComponentContext = unifyComponentContext; onInitialize(); }
/** * Gets a formatted message using application locale. Obtains a message from * application messages component using supplied messageKey and then formats * using supplied parameters. Uses the locale based on localeType. * * @param messageKey * the message key * @param params * the formatting parameters * @return the formatted message * @throws UnifyException * if message with supplied key is missing from the messages * component. */ protected String getApplicationMessage(String messageKey, Object... params) throws UnifyException { return unifyComponentContext.getMessages().getMessage(getLocale(LocaleType.APPLICATION), messageKey, params); }
/** * Creates a value store using supplied storage object. * * @param storageObject * the storage object to use * @return ValueStore new instance of a value store * @throws UnifyException * if an error occurs */ protected ValueStore createValueStore(Object storageObject) throws UnifyException { return ((ValueStoreFactory) getComponent(ApplicationComponents.APPLICATION_VALUESTOREFACTORY)) .getValueStore(storageObject); }
/** * Throws a component unsupported operation unify exception. * * @throws UnifyException * always thrown */ protected void throwUnsupportedOperationException() throws UnifyException { Exception e = new UnsupportedOperationException(); throw new UnifyException(e, UnifyCoreErrorConstants.COMPONENT_OPERATION_ERROR, getName(), e.getMessage()); }
@Override public String getMessage(Locale locale, String messageKey, Object... params) throws UnifyException { return super.getMessage(locale, messageKey, params); }
/** * Converts value to a specific collection type using an optional formatter. * * @param collectionClazz * the target collection type to convert to * @param dataClass * the collation data type * @param value * the value to convert * @param formatterUpl * the formatter UPL descriptor if any * @return the converted value * @throws UnifyException * if an error occurs */ protected <T, U extends Collection<T>> U convert(Class<U> collectionClazz, Class<T> dataClass, Object value, String formatterUpl) throws UnifyException { if (formatterUpl == null) { return DataUtils.convert(collectionClazz, dataClass, value, null); } else { return DataUtils.convert(collectionClazz, dataClass, value, getSessionLocaleFormatter(formatterUpl)); } }
private void log(LoggingLevel loggingLevel, Exception exception) { try { Logger logger = unifyComponentContext.getLogger(); if (logger.isEnabled(loggingLevel)) { logger.log(loggingLevel, getExceptionMessage(LocaleType.APPLICATION, exception), exception); } } catch (UnifyException e) { e.printStackTrace(); } } }
/** * Resolves a message string using current session's locale. A message is * resolved by checking if it is a value enclosed with a tag. If enclosed with a * message tag <em>$m{<value>}</em>, the value is used as a key to obtain * a message resource from the messages component. The obtained message is * returned as the resolved string. If enclosed with a string tag * <em>$s{<value>}</em>, the value is extracted and returned as the * resolved string. For any other condition, the string is returned as is. * * @param message * the message to resolve. * @param params * parameters * @return the resolved string or null if supplied string is null * @throws UnifyException * If an error occurs */ protected String resolveSessionMessage(String message, Object... params) throws UnifyException { return resolveMessage(getLocale(LocaleType.SESSION), message, params); }
/** * Gets a list based on supplied parameters. * * @param localeType * the locale type * @param listName * the list name * @param params * the list parameters * @return a list object containing listable items * @throws UnifyException * if an error occurs */ protected List<? extends Listable> getList(LocaleType localeType, String listName, Object... params) throws UnifyException { return unifyComponentContext.getListManager().getList(getLocale(localeType), listName, params); }
/** * Creates a value store with index information using supplied storage object. * * @param storageObject * the storage object to use * @param dataIndex * the data index * @return ValueStore new instance of a value store * @throws UnifyException * if an error occurs */ protected ValueStore createValueStore(Object storageObject, int dataIndex) throws UnifyException { return ((ValueStoreFactory) getComponent(ApplicationComponents.APPLICATION_VALUESTOREFACTORY)) .getValueStore(storageObject, dataIndex); }
/** * Throws a component operation error unify exception. Wraps the supplied * exception in a unify exception with component operation error code. * * @param e * the exception to warp * @throws UnifyException * always thrown */ protected void throwOperationErrorException(Exception e) throws UnifyException { Throwable t = e.getCause(); if (t instanceof UnifyException) { throw ((UnifyException) t); } throw new UnifyException(e, UnifyCoreErrorConstants.COMPONENT_OPERATION_ERROR, getName(), e.getMessage()); }
@Override public String getMessage(Locale locale, String messageKey) throws UnifyException { return super.getMessage(locale, messageKey); }
/** * Converts value to a specific type using an optional formatter. * * @param targetClazz * the target type to convert to * @param value * the value to convert * @param formatterUpl * the formatter UPL descriptor if any * @return the converted value * @throws UnifyException * if an error occurs */ protected <T> T convert(Class<T> targetClazz, Object value, String formatterUpl) throws UnifyException { if (formatterUpl == null) { return DataUtils.convert(targetClazz, value, null); } else { return DataUtils.convert(targetClazz, value, getSessionLocaleFormatter(formatterUpl)); } }
/** * Gets the description of a list item. A list is obtained from component's list * manager using the supplied listName then supplied itemKey is applied to the * list to obtain the item description. * * @param localeType * the locale type * @param listName * the name of the list * @param itemKey * the list key to the list item * @return the list item description or null if item with key is not found * @throws UnifyException * if list with supplied name is unknown by the list manager */ protected String getListItemDescription(LocaleType localeType, String listName, String itemKey) throws UnifyException { return unifyComponentContext.getListManager().getListKeyDescription(getLocale(localeType), itemKey, listName); }
/** * Creates a array value store with index information using supplied storage * object. * * @param storageObject * the storage object to use * @param dataIndex * the data index * @return ValueStore new instance of a value store * @throws UnifyException * if an error occurs */ protected ValueStore createArrayValueStore(Object[] storageObject, int dataIndex) throws UnifyException { return ((ValueStoreFactory) getComponent(ApplicationComponents.APPLICATION_VALUESTOREFACTORY)) .getArrayValueStore(storageObject, dataIndex); }