use of org.springframework.roo.classpath.details.annotations.AnnotationMetadata in project spring-roo by spring-projects.
the class JpaFieldCreatorProvider method createChildEntityFactory.
/**
* Creates the Factory class of the child entity of relationship, only if parent entity has JPA unit tests.
*
* @param childType
* @param parentType
*/
private void createChildEntityFactory(JavaType childType, JavaType parentType) {
// Find current JPA unit tests
Set<JavaType> unitTestTypes = typeLocationService.findTypesWithAnnotation(RooJavaType.ROO_JPA_UNIT_TEST);
for (JavaType unitTestType : unitTestTypes) {
// Get the annotation @RooJpaUnitTest
ClassOrInterfaceTypeDetails cid = typeLocationService.getTypeDetails(unitTestType);
AnnotationMetadata rooUnitTestAnnotation = cid.getAnnotation(RooJavaType.ROO_JPA_UNIT_TEST);
// Check if parent entity has JPA unit test class
AnnotationAttributeValue<Object> targetClass = rooUnitTestAnnotation.getAttribute("targetClass");
Validate.notNull(targetClass, String.format("'targetClass' attribute can't be found for annotation @RooJpaUnitTest in class %s", unitTestType.getSimpleTypeName()));
if (parentType.equals(targetClass.getValue())) {
if (jpaEntityFactoryLocator.getFirstJpaEntityFactoryForEntity(childType) == null) {
// Create factory class for child entity if doesn't exist
dataOnDemandCreatorProvider.createEntityFactory(childType);
}
break;
}
}
}
use of org.springframework.roo.classpath.details.annotations.AnnotationMetadata in project spring-roo by spring-projects.
the class JpaDataOnDemandCreator method newDataOnDemandClass.
/**
* Creates a new data-on-demand provider for an entity. Silently returns
* if the DoD class already exists.
*
* @param entity to produce a DoD provider for
* @param name the name of the new DoD class
*/
private JavaType newDataOnDemandClass(JavaType entity, JavaType name) {
Validate.notNull(entity, "Entity to produce a data on demand provider for is required");
Validate.notNull(name, "Name of the new data on demand provider is required");
final LogicalPath path = LogicalPath.getInstance(Path.SRC_TEST_JAVA, name.getModule());
Validate.notNull(path, "Location of the new data on demand provider is required");
// Add javax validation dependency
projectOperations.addDependency(name.getModule(), VALIDATION_API_DEPENDENCY);
// Verify the requested entity actually exists as a class and is not
// abstract
final ClassOrInterfaceTypeDetails cid = getEntityDetails(entity);
Validate.isTrue(cid.getPhysicalTypeCategory() == PhysicalTypeCategory.CLASS, "Type %s is not a class", entity.getFullyQualifiedTypeName());
Validate.isTrue(!Modifier.isAbstract(cid.getModifier()), "Type %s is abstract", entity.getFullyQualifiedTypeName());
// Check if the requested entity is a JPA @Entity
final MemberDetails memberDetails = memberDetailsScanner.getMemberDetails(JpaDataOnDemandCreator.class.getName(), cid);
final AnnotationMetadata entityAnnotation = memberDetails.getAnnotation(ENTITY);
Validate.isTrue(entityAnnotation != null, "Type %s must be a JPA entity type", entity.getFullyQualifiedTypeName());
// Everything is OK to proceed
final String declaredByMetadataId = PhysicalTypeIdentifier.createIdentifier(name, path);
if (metadataService.get(declaredByMetadataId) != null) {
// The file already exists
return new ClassOrInterfaceTypeDetailsBuilder(declaredByMetadataId).getName();
}
final List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>();
final List<AnnotationAttributeValue<?>> dodConfig = new ArrayList<AnnotationAttributeValue<?>>();
dodConfig.add(new ClassAttributeValue(new JavaSymbolName("entity"), entity));
annotations.add(new AnnotationMetadataBuilder(RooJavaType.ROO_JPA_DATA_ON_DEMAND, dodConfig));
final ClassOrInterfaceTypeDetailsBuilder cidBuilder = new ClassOrInterfaceTypeDetailsBuilder(declaredByMetadataId, Modifier.PUBLIC, name, PhysicalTypeCategory.CLASS);
cidBuilder.setAnnotations(annotations);
// Write changes on disk
final ClassOrInterfaceTypeDetails dodClassCid = cidBuilder.build();
typeManagementService.createOrUpdateTypeOnDisk(dodClassCid);
return cid.getName();
}
use of org.springframework.roo.classpath.details.annotations.AnnotationMetadata in project spring-roo by spring-projects.
the class JavaBeanMetadata method processGaeAnnotations.
private void processGaeAnnotations(final FieldMetadata field) {
for (final AnnotationMetadata annotation : field.getAnnotations()) {
if (annotation.getAnnotationType().equals(ONE_TO_ONE) || annotation.getAnnotationType().equals(MANY_TO_ONE) || annotation.getAnnotationType().equals(ONE_TO_MANY) || annotation.getAnnotationType().equals(MANY_TO_MANY)) {
builder.addFieldAnnotation(new DeclaredFieldAnnotationDetails(field, new AnnotationMetadataBuilder(annotation.getAnnotationType()).build(), true));
builder.addFieldAnnotation(new DeclaredFieldAnnotationDetails(field, new AnnotationMetadataBuilder(TRANSIENT).build()));
break;
}
}
}
use of org.springframework.roo.classpath.details.annotations.AnnotationMetadata in project spring-roo by spring-projects.
the class JavaBeanMetadataProviderImpl method getIdentifierAccessorMethodName.
private JavaSymbolName getIdentifierAccessorMethodName(final FieldMetadata field, final String metadataIdentificationString) {
if (projectOperations == null) {
projectOperations = getProjectOperations();
}
Validate.notNull(projectOperations, "ProjectOperations is required");
final LogicalPath path = PhysicalTypeIdentifier.getPath(field.getDeclaredByMetadataId());
final String moduleNme = path.getModule();
if (projectOperations.isProjectAvailable(moduleNme) || !projectOperations.isFeatureInstalled(FeatureNames.GAE)) {
return null;
}
// @javax.persistence.Transient
for (final AnnotationMetadata annotationMetadata : field.getAnnotations()) {
if (annotationMetadata.getAnnotationType().equals(TRANSIENT)) {
return null;
}
}
JavaType fieldType = field.getFieldType();
// type
if (fieldType.isCommonCollectionType()) {
if (fieldType.getParameters().isEmpty()) {
return null;
}
fieldType = fieldType.getParameters().get(0);
}
final MethodMetadata identifierAccessor = getPersistenceMemberLocator().getIdentifierAccessor(fieldType);
if (identifierAccessor != null) {
getMetadataDependencyRegistry().registerDependency(identifierAccessor.getDeclaredByMetadataId(), metadataIdentificationString);
return identifierAccessor.getMethodName();
}
return null;
}
use of org.springframework.roo.classpath.details.annotations.AnnotationMetadata in project spring-roo by spring-projects.
the class EqualsMetadataProviderImpl method getMetadata.
@Override
protected ItdTypeDetailsProvidingMetadataItem getMetadata(final String metadataIdentificationString, final JavaType aspectName, final PhysicalTypeMetadata governorPhysicalTypeMetadata, final String itdFilename) {
final EqualsAnnotationValues annotationValues = new EqualsAnnotationValues(governorPhysicalTypeMetadata);
if (!annotationValues.isAnnotationFound()) {
return null;
}
final MemberDetails memberDetails = getMemberDetails(governorPhysicalTypeMetadata);
if (memberDetails == null) {
return null;
}
AnnotationMetadata javaBeanAnnotation = memberDetails.getAnnotation(ROO_JAVA_BEAN);
if (javaBeanAnnotation != null) {
// Return an empty metadata as @RooJavaBean do the work
return new EqualsMetadata(metadataIdentificationString, aspectName, governorPhysicalTypeMetadata, annotationValues, new ArrayList<FieldMetadata>(), null, true);
}
final JavaType javaType = governorPhysicalTypeMetadata.getMemberHoldingTypeDetails().getName();
final List<FieldMetadata> equalityFields = locateFields(javaType, annotationValues.getExcludeFields(), memberDetails.getFields(), metadataIdentificationString);
FieldMetadata identifierField = getIdentifier(governorPhysicalTypeMetadata);
return new EqualsMetadata(metadataIdentificationString, aspectName, governorPhysicalTypeMetadata, annotationValues, equalityFields, identifierField, false);
}
Aggregations