use of java.lang.reflect.AnnotatedElement in project cuba by cuba-platform.
the class MetadataTools method isLazyFetchedLocalAttribute.
/**
* Determine whether the given property is a local property with a LAZY fetch type.
*/
public boolean isLazyFetchedLocalAttribute(MetaProperty metaProperty) {
Objects.requireNonNull(metaProperty, "metaProperty is null");
AnnotatedElement annotatedElement = metaProperty.getAnnotatedElement();
Basic annotation = annotatedElement.getAnnotation(Basic.class);
return annotation != null && annotation.fetch() == FetchType.LAZY;
}
use of java.lang.reflect.AnnotatedElement in project cuba by cuba-platform.
the class EntityRestore method buildLayout.
protected void buildLayout() {
Object value = entities.getValue();
if (value != null) {
MetaClass metaClass = (MetaClass) value;
MetaProperty deleteTsMetaProperty = metaClass.getProperty("deleteTs");
if (deleteTsMetaProperty != null) {
if (entitiesTable != null) {
tablePanel.remove(entitiesTable);
}
if (filter != null) {
tablePanel.remove(filter);
}
entitiesTable = uiComponents.create(Table.NAME);
entitiesTable.setFrame(frame);
restoreButton = uiComponents.create(Button.class);
restoreButton.setId("restore");
restoreButton.setCaption(getMessage("entityRestore.restore"));
ButtonsPanel buttonsPanel = uiComponents.create(ButtonsPanel.class);
buttonsPanel.add(restoreButton);
entitiesTable.setButtonsPanel(buttonsPanel);
RowsCount rowsCount = uiComponents.create(RowsCount.class);
entitiesTable.setRowsCount(rowsCount);
SimpleDateFormat dateTimeFormat = new SimpleDateFormat(getMessage("dateTimeFormat"));
Function<Object, String> dateTimeFormatter = propertyValue -> {
if (propertyValue == null) {
return StringUtils.EMPTY;
}
return dateTimeFormat.format(propertyValue);
};
// collect properties in order to add non-system columns first
LinkedList<Table.Column<Entity>> nonSystemPropertyColumns = new LinkedList<>();
LinkedList<Table.Column<Entity>> systemPropertyColumns = new LinkedList<>();
List<MetaProperty> metaProperties = new ArrayList<>();
for (MetaProperty metaProperty : metaClass.getProperties()) {
// don't show embedded, transient & multiple referred entities
Range range = metaProperty.getRange();
if (isEmbedded(metaProperty) || metadataTools.isNotPersistent(metaProperty) || range.getCardinality().isMany() || metadataTools.isSystemLevel(metaProperty) || (range.isClass() && metadataTools.isSystemLevel(range.asClass()))) {
continue;
}
metaProperties.add(metaProperty);
Table.Column<Entity> column = new Table.Column<>(metaClass.getPropertyPath(metaProperty.getName()));
if (!metadataTools.isSystem(metaProperty)) {
column.setCaption(getPropertyCaption(metaClass, metaProperty));
nonSystemPropertyColumns.add(column);
} else {
column.setCaption(metaProperty.getName());
column.setDescription(getSystemAttributeDescription(metaClass, metaProperty));
systemPropertyColumns.add(column);
}
if (range.isDatatype() && range.asDatatype().getJavaClass().equals(Date.class)) {
column.setFormatter(dateTimeFormatter);
}
}
for (Table.Column<Entity> column : nonSystemPropertyColumns) {
entitiesTable.addColumn(column);
}
for (Table.Column<Entity> column : systemPropertyColumns) {
entitiesTable.addColumn(column);
}
DsContext dsContext = getDsContext();
if (entitiesDs != null) {
((DsContextImplementation) dsContext).unregister(entitiesDs);
}
entitiesDs = DsBuilder.create(dsContext).setId("entitiesDs").setMetaClass(metaClass).setView(buildView(metaClass, metaProperties)).buildGroupDatasource();
entitiesDs.setQuery("select e from " + metaClass.getName() + " e " + "where e.deleteTs is not null order by e.deleteTs");
entitiesDs.setSoftDeletion(false);
entitiesDs.refresh();
entitiesTable.setDatasource(entitiesDs);
String filterId = metaClass.getName().replace("$", "") + "GenericFilter";
filter = uiComponents.create(Filter.class);
filter.setId(filterId);
filter.setFrame(getFrame());
StringBuilder sb = new StringBuilder();
for (MetaProperty property : metaClass.getProperties()) {
AnnotatedElement annotatedElement = property.getAnnotatedElement();
if (annotatedElement.getAnnotation(com.haulmont.chile.core.annotations.MetaProperty.class) != null) {
sb.append(property.getName()).append("|");
}
}
Element filterElement = dom4JTools.readDocument(String.format("<filter id=\"%s\">\n" + " <properties include=\".*\" exclude=\"\"/>\n" + "</filter>", filterId)).getRootElement();
String excludedProperties = sb.toString();
if (StringUtils.isNotEmpty(excludedProperties)) {
Element properties = filterElement.element("properties");
properties.attribute("exclude").setValue(excludedProperties.substring(0, excludedProperties.lastIndexOf("|")));
}
((HasXmlDescriptor) filter).setXmlDescriptor(filterElement);
filter.setUseMaxResults(true);
filter.setDatasource(entitiesDs);
entitiesTable.setSizeFull();
entitiesTable.setMultiSelect(true);
Action restoreAction = new ItemTrackingAction("restore").withCaption(getMessage("entityRestore.restore")).withPrimary(true).withHandler(event -> showRestoreDialog());
entitiesTable.addAction(restoreAction);
restoreButton.setAction(restoreAction);
tablePanel.add(filter);
tablePanel.add(entitiesTable);
tablePanel.expand(entitiesTable, "100%", "100%");
entitiesTable.refresh();
((FilterImplementation) filter).loadFiltersAndApplyDefault();
}
}
}
use of java.lang.reflect.AnnotatedElement in project cuba by cuba-platform.
the class CompanionDependencyInjector method inject.
public void inject() {
Map<AnnotatedElement, Class> toInject = new HashMap<>();
List<Class<?>> classes = ClassUtils.getAllSuperclasses(companion.getClass());
classes.add(0, companion.getClass());
Collections.reverse(classes);
for (Field field : getAllFields(classes)) {
Class aClass = injectionAnnotation(field);
if (aClass != null) {
toInject.put(field, aClass);
}
}
for (Method method : companion.getClass().getMethods()) {
Class aClass = injectionAnnotation(method);
if (aClass != null) {
toInject.put(method, aClass);
}
}
for (Map.Entry<AnnotatedElement, Class> entry : toInject.entrySet()) {
doInjection(entry.getKey(), entry.getValue());
}
}
use of java.lang.reflect.AnnotatedElement in project junit5 by junit-team.
the class TempDirectory method getPathOrFile.
private Object getPathOrFile(AnnotatedElement sourceElement, Class<?> type, CleanupMode cleanupMode, ExtensionContext extensionContext) {
Namespace namespace = //
getScope(extensionContext) == Scope.PER_DECLARATION ? //
NAMESPACE.append(sourceElement) : NAMESPACE;
Path path = //
extensionContext.getStore(namespace).getOrComputeIfAbsent(KEY, __ -> createTempDir(cleanupMode, extensionContext), //
CloseablePath.class).get();
return (type == Path.class) ? path : path.toFile();
}
use of java.lang.reflect.AnnotatedElement in project jersey by jersey.
the class ParamInjectionResolver method hasEncodedAnnotation.
private boolean hasEncodedAnnotation(Injectee injectee) {
AnnotatedElement element = injectee.getParent();
final boolean isConstructor = element instanceof Constructor;
final boolean isMethod = element instanceof Method;
// if injectee is method or constructor, check its parameters
if (isConstructor || isMethod) {
Annotation[] annotations;
if (isMethod) {
annotations = ((Method) element).getParameterAnnotations()[injectee.getPosition()];
} else {
annotations = ((Constructor) element).getParameterAnnotations()[injectee.getPosition()];
}
for (Annotation annotation : annotations) {
if (annotation.annotationType().equals(Encoded.class)) {
return true;
}
}
}
// check injectee itself (method, constructor or field)
if (element.isAnnotationPresent(Encoded.class)) {
return true;
}
// check class which contains injectee
Class<?> clazz = injectee.getInjecteeClass();
return clazz.isAnnotationPresent(Encoded.class);
}
Aggregations