use of org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails in project spring-roo by spring-projects.
the class EntityDeserializerMetadataProviderImpl method getMetadata.
@Override
protected ItdTypeDetailsProvidingMetadataItem getMetadata(final String metadataIdentificationString, final JavaType aspectName, final PhysicalTypeMetadata governorPhysicalTypeMetadata, final String itdFilename) {
final EntityDeserializerAnnotationValues values = new EntityDeserializerAnnotationValues(governorPhysicalTypeMetadata);
final JavaType deserializerType = governorPhysicalTypeMetadata.getType();
final JavaType entity = values.getEntity();
final ClassOrInterfaceTypeDetails entityDetails = getTypeLocationService().getTypeDetails(entity);
Validate.notNull(entityDetails, "Can't get details of '%s' defined on '%s.@%s.entity'", entity.getFullyQualifiedTypeName(), deserializerType, RooJavaType.ROO_DESERIALIZER.getSimpleTypeName());
Validate.notNull(entityDetails.getAnnotation(RooJavaType.ROO_JPA_ENTITY), "Class '%s' defined on '%s.@%s.entity' has no @%s annotation. Only JPA entities can set as mixin", entity.getFullyQualifiedTypeName(), deserializerType, RooJavaType.ROO_DESERIALIZER.getSimpleTypeName());
// Register JpaEntityMetadata dependency
final String entityId = JpaEntityMetadata.createIdentifier(entityDetails);
final JpaEntityMetadata entityMetadata = getMetadataService().get(entityId);
if (entityMetadata == null) {
// not ready to this metadata yet
return null;
}
registerDependency(entityId, metadataIdentificationString);
// Register JavaBeanMetadata dependency
final String javaBeanId = JavaBeanMetadata.createIdentifier(entityDetails);
final JavaBeanMetadata javaBeanMetadata = getMetadataService().get(javaBeanId);
if (javaBeanMetadata == null) {
// not ready to this metadata yet
return null;
}
registerDependency(javaBeanId, metadataIdentificationString);
// Register ServiceMetadata dependency
ClassOrInterfaceTypeDetails serviceDetails = getServiceLocator().getService(entity);
String serviceMetadataId = ServiceMetadata.createIdentifier(serviceDetails);
ServiceMetadata serviceMetadata = getMetadataService().get(serviceMetadataId);
if (serviceMetadata == null) {
// not ready to this metadata yet
return null;
}
return new EntityDeserializerMetadata(metadataIdentificationString, aspectName, governorPhysicalTypeMetadata, values, entityMetadata, serviceMetadata);
}
use of org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails in project spring-roo by spring-projects.
the class JSONMixinMetadataProviderImpl method getMetadata.
@Override
protected ItdTypeDetailsProvidingMetadataItem getMetadata(final String metadataIdentificationString, final JavaType aspectName, final PhysicalTypeMetadata governorPhysicalTypeMetadata, final String itdFilename) {
final JSONMixinAnnotationValues values = new JSONMixinAnnotationValues(governorPhysicalTypeMetadata);
final JavaType mixinType = governorPhysicalTypeMetadata.getType();
final JavaType entity = values.getEntity();
final ClassOrInterfaceTypeDetails entityDetails = getTypeLocationService().getTypeDetails(entity);
Validate.notNull(entityDetails, "Can't get details of '%s' defined on '%s.@%s.entity'", entity.getFullyQualifiedTypeName(), mixinType, RooJavaType.ROO_JSON_MIXIN.getSimpleTypeName());
Validate.notNull(entityDetails.getAnnotation(RooJavaType.ROO_JPA_ENTITY), "Class '%s' defined on '%s.@%s.entity' has no @%s annotation. Only JPA entities can set as mixin", entity.getFullyQualifiedTypeName(), mixinType, RooJavaType.ROO_JSON_MIXIN.getSimpleTypeName());
final String entityId = JpaEntityMetadata.createIdentifier(entityDetails);
final JpaEntityMetadata entityMetadata = getMetadataService().get(entityId);
if (entityMetadata == null) {
// not ready for this metadata yet
return null;
}
// register metadata dependency
registerDependency(entityId, metadataIdentificationString);
// Register dependency with DomainModelModule
Set<ClassOrInterfaceTypeDetails> domainModelModuleDetails = getTypeLocationService().findClassesOrInterfaceDetailsWithAnnotation(RooJavaType.ROO_DOMAIN_MODEL_MODULE);
if (!domainModelModuleDetails.isEmpty()) {
String domainModelModuleMetadataId = DomainModelModuleMetadata.createIdentifier(domainModelModuleDetails.iterator().next());
registerDependency(metadataIdentificationString, domainModelModuleMetadataId);
}
Map<FieldMetadata, JavaType> jsonDeserializerByEntity = new TreeMap<FieldMetadata, JavaType>(FieldMetadata.COMPARATOR_BY_NAME);
for (FieldMetadata field : entityMetadata.getRelationsAsChild().values()) {
if (isAnyToOneRelation(field)) {
JavaType parentEntity = field.getFieldType().withoutParameters();
JavaType entityDeserializer = getEntityDeserializerFor(parentEntity);
Validate.notNull(entityDeserializer, "Can't locate class with @%s.entity=%s required for %s entity Json Mixin (%s)", RooJavaType.ROO_DESERIALIZER, parentEntity, entity.getFullyQualifiedTypeName(), mixinType.getFullyQualifiedTypeName());
jsonDeserializerByEntity.put(field, entityDeserializer);
}
}
return new JSONMixinMetadata(metadataIdentificationString, aspectName, governorPhysicalTypeMetadata, values, entityMetadata, jsonDeserializerByEntity);
}
use of org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails in project spring-roo by spring-projects.
the class ExceptionsOperationsImpl method addHandlersAnnotations.
/**
* Generates {@link RooExceptionHandlers} and {@link RooExceptionHandler} annotations
* and adds or updates it on specified class.
*
* @param exception
* @param targetClass
* @param errorView
*/
private void addHandlersAnnotations(JavaType exception, JavaType targetClass, String errorView) {
Validate.notNull(targetClass, "Target class is required to add @RooExceptionHandlers annotation");
// Create @RooExceptionHandler Annotation
final AnnotationMetadataBuilder exceptionHandlerAnnotationBuilder = new AnnotationMetadataBuilder(RooJavaType.ROO_EXCEPTION_HANDLER);
final List<AnnotationAttributeValue<?>> exceptionHandlerAnnotationAttributes = new ArrayList<AnnotationAttributeValue<?>>();
exceptionHandlerAnnotationAttributes.add(new ClassAttributeValue(new JavaSymbolName(EXCEPTION), exception));
if (errorView != null) {
exceptionHandlerAnnotationAttributes.add(new StringAttributeValue(new JavaSymbolName(ERROR_VIEW), errorView));
}
exceptionHandlerAnnotationBuilder.setAttributes(exceptionHandlerAnnotationAttributes);
// Check if container annotation already exists
ClassOrInterfaceTypeDetails typeDetails = typeLocationService.getTypeDetails(targetClass);
ClassOrInterfaceTypeDetailsBuilder typeDetailsBuilder = new ClassOrInterfaceTypeDetailsBuilder(typeDetails);
AnnotationMetadata exceptionHandlersAnnotation = typeDetails.getAnnotation(RooJavaType.ROO_EXCEPTION_HANDLERS);
AnnotationMetadataBuilder exceptionHandlersAnnotationBuilder = null;
if (exceptionHandlersAnnotation != null) {
exceptionHandlersAnnotationBuilder = new AnnotationMetadataBuilder(exceptionHandlersAnnotation);
} else {
exceptionHandlersAnnotationBuilder = new AnnotationMetadataBuilder(RooJavaType.ROO_EXCEPTION_HANDLERS);
}
Validate.notNull(exceptionHandlersAnnotationBuilder);
// Add @RooExceptionHandler annotation into @RooExceptionHandlers
final List<NestedAnnotationAttributeValue> exceptionHandlersArrayValues = new ArrayList<NestedAnnotationAttributeValue>();
exceptionHandlersArrayValues.add(new NestedAnnotationAttributeValue(new JavaSymbolName(VALUE), exceptionHandlerAnnotationBuilder.build()));
final List<AnnotationAttributeValue<?>> attributeValues = new ArrayList<AnnotationAttributeValue<?>>();
attributeValues.add(new ArrayAttributeValue<NestedAnnotationAttributeValue>(new JavaSymbolName(VALUE), exceptionHandlersArrayValues));
if (exceptionHandlersAnnotation == null) {
// Add new @RooExceptionHandlers annotation with given values
exceptionHandlersAnnotationBuilder.setAttributes(attributeValues);
typeDetailsBuilder.addAnnotation(exceptionHandlersAnnotationBuilder.build());
} else {
// Get current annotation values from @RooExceptionHandlers annotation
AnnotationAttributeValue<?> currentHandlers = exceptionHandlersAnnotation.getAttribute(VALUE);
if (currentHandlers != null) {
List<?> values = (List<?>) currentHandlers.getValue();
Iterator<?> it = values.iterator();
while (it.hasNext()) {
NestedAnnotationAttributeValue handler = (NestedAnnotationAttributeValue) it.next();
if (handler.getValue() != null) {
// Check if there is a @RooExceptionHandlers with same 'exception' value
if (exceptionHandlerAnnotationBuilder.build().getAttribute(EXCEPTION).getValue().equals(handler.getValue().getAttribute(EXCEPTION).getValue())) {
LOGGER.warning(String.format("There is already a handler for exception %s in class %s", exception.getSimpleTypeName(), targetClass.getSimpleTypeName()));
return;
}
exceptionHandlersArrayValues.add(handler);
}
}
}
// Add found values
attributeValues.add(new ArrayAttributeValue<NestedAnnotationAttributeValue>(new JavaSymbolName(VALUE), exceptionHandlersArrayValues));
exceptionHandlersAnnotationBuilder.setAttributes(attributeValues);
// Update annotation
typeDetailsBuilder.updateTypeAnnotation(exceptionHandlersAnnotationBuilder.build());
}
// Write to disk
getTypeManagementService().createOrUpdateTypeOnDisk(typeDetailsBuilder.build());
}
use of org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails in project spring-roo by spring-projects.
the class ExceptionsOperationsImpl method isExceptionAnnotatedWithResponseStatus.
private boolean isExceptionAnnotatedWithResponseStatus(JavaType exception) {
ClassOrInterfaceTypeDetails exceptionCid = typeLocationService.getTypeDetails(exception);
Validate.notNull(exceptionCid, String.format("Can't found class: %s", exception.getFullyQualifiedTypeName()));
AnnotationMetadata annotation = exceptionCid.getAnnotation(SpringJavaType.RESPONSE_STATUS);
if (annotation == null) {
return false;
}
return true;
}
use of org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails in project spring-roo by spring-projects.
the class TestCommands method getAllEntities.
@CliOptionAutocompleteIndicator(command = "test integration", param = "class", help = "Option `--class` must " + "be a non-abstract valid type. Please, use auto-complete feature to select it.")
public List<String> getAllEntities(ShellContext shellContext) {
// Get current value of class
String currentText = shellContext.getParameters().get("class");
// Create results to return
List<String> results = new ArrayList<String>();
// Look for all valid types for all available test creators
for (TestCreatorProvider creator : getAllTestCreators()) {
if (creator.isIntegrationTestCreationAvailable()) {
for (JavaType annotationType : creator.getValidTypes()) {
// Look for types with this annotation type
Set<ClassOrInterfaceTypeDetails> types = typeLocationService.findClassesOrInterfaceDetailsWithAnnotation(annotationType);
for (ClassOrInterfaceTypeDetails typeCid : types) {
String name = replaceTopLevelPackageString(typeCid.getType(), currentText);
if (!results.contains(name)) {
results.add(name);
}
}
}
}
}
return results;
}
Aggregations