use of com.haulmont.cuba.core.sys.BeanLocatorAware in project cuba by cuba-platform.
the class ExceptionHandlers method createByConfiguration.
/**
* Create all Web handlers defined by <code>ExceptionHandlersConfiguration</code> beans in spring.xml and
* GUI handlers defined as Spring-beans.
*/
public void createByConfiguration() {
removeAll();
// Web handlers
Map<String, ExceptionHandlersConfiguration> map = beanLocator.getAll(ExceptionHandlersConfiguration.class);
// Project-level handlers must run before platform-level
List<ExceptionHandlersConfiguration> configurations = new ArrayList<>(map.values());
Collections.reverse(configurations);
for (ExceptionHandlersConfiguration conf : configurations) {
for (Class aClass : conf.getHandlerClasses()) {
try {
ExceptionHandler handler = ReflectionHelper.<ExceptionHandler>newInstance(aClass);
if (handler instanceof BeanLocatorAware) {
((BeanLocatorAware) handler).setBeanLocator(beanLocator);
}
addHandler(handler);
} catch (NoSuchMethodException e) {
log.error("Unable to instantiate {}", aClass, e);
}
}
}
// GUI handlers
Map<String, UiExceptionHandler> handlerMap = beanLocator.getAll(UiExceptionHandler.class);
List<UiExceptionHandler> handlers = new ArrayList<>(handlerMap.values());
handlers.sort(new OrderComparator());
for (UiExceptionHandler handler : handlers) {
addHandler(handler);
}
}
use of com.haulmont.cuba.core.sys.BeanLocatorAware in project cuba by cuba-platform.
the class ValueBinder method bind.
public <V> ValueBinding<V> bind(HasValue<V> component, ValueSource<V> valueSource) {
if (valueSource instanceof BeanLocatorAware) {
((BeanLocatorAware) valueSource).setBeanLocator(beanLocator);
}
ValueBindingImpl<V> binding = new ValueBindingImpl<>(component, valueSource);
if (component instanceof Component.Editable) {
((Component.Editable) component).setEditable(!valueSource.isReadOnly());
}
if (valueSource instanceof EntityValueSource) {
EntityValueSource entityValueSource = (EntityValueSource) valueSource;
MetaPropertyPath metaPropertyPath = entityValueSource.getMetaPropertyPath();
if (component instanceof Field) {
initRequired((Field) component, metaPropertyPath);
initBeanValidator((Field<?>) component, metaPropertyPath);
}
if (entityValueSource.isDataModelSecurityEnabled()) {
if (component instanceof Component.Editable) {
MetaClass metaClass = entityValueSource.getEntityMetaClass();
boolean permittedIfEmbedded = true;
if (entityValueSource instanceof ContainerValueSource) {
InstanceContainer container = ((ContainerValueSource) entityValueSource).getContainer();
if (container instanceof Nested && metadataTools.isEmbeddable(metaClass)) {
String embeddedProperty = ((Nested) container).getProperty();
MetaClass masterMetaClass = ((Nested) container).getMaster().getEntityMetaClass();
permittedIfEmbedded = security.isEntityAttrUpdatePermitted(masterMetaClass, embeddedProperty);
}
if (permittedIfEmbedded && metaPropertyPath.length() > 1) {
for (MetaProperty property : metaPropertyPath.getMetaProperties()) {
if (metadataTools.isEmbedded(property) && !security.isEntityAttrUpdatePermitted(property.getDomain(), property.getName())) {
permittedIfEmbedded = false;
break;
}
}
}
}
if (!security.isEntityAttrUpdatePermitted(metaPropertyPath) || !permittedIfEmbedded) {
((Component.Editable) component).setEditable(false);
}
}
if (!security.isEntityAttrReadPermitted(metaPropertyPath)) {
component.setVisible(false);
}
}
}
binding.bind();
return binding;
}
Aggregations