use of org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails in project spring-roo by spring-projects.
the class JpaDataOnDemandCreator method getEntityDetails.
/**
* Returns the {@link ClassOrInterfaceTypeDetails} for the provided entity.
*
* @param entity
* the entity to lookup required
* @return the ClassOrInterfaceTypeDetails type details (never null; throws
* an exception if it cannot be obtained or parsed)
*/
private ClassOrInterfaceTypeDetails getEntityDetails(final JavaType entity) {
final ClassOrInterfaceTypeDetails cid = typeLocationService.getTypeDetails(entity);
Validate.notNull(cid, "Java source code details unavailable for type '%s'", entity);
return cid;
}
use of org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails in project spring-roo by spring-projects.
the class JpaDataOnDemandCreator method getEntityFactory.
@Override
public JavaType getEntityFactory(JavaType entity) {
Set<ClassOrInterfaceTypeDetails> dataOnDemandCids = typeLocationService.findClassesOrInterfaceDetailsWithAnnotation(RooJavaType.ROO_JPA_ENTITY_FACTORY);
JavaType typeToReturn = null;
for (ClassOrInterfaceTypeDetails cid : dataOnDemandCids) {
if (entity.equals((JavaType) cid.getAnnotation(RooJavaType.ROO_JPA_ENTITY_FACTORY).getAttribute("entity").getValue())) {
typeToReturn = cid.getName();
break;
}
}
return typeToReturn;
}
use of org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails 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.ClassOrInterfaceTypeDetails in project spring-roo by spring-projects.
the class JavaBeanMetadataProviderImpl method getMetadata.
@Override
protected ItdTypeDetailsProvidingMetadataItem getMetadata(final String metadataIdentificationString, final JavaType aspectName, final PhysicalTypeMetadata governorPhysicalTypeMetadata, final String itdFilename) {
final JavaBeanAnnotationValues annotationValues = new JavaBeanAnnotationValues(governorPhysicalTypeMetadata);
if (!annotationValues.isAnnotationFound()) {
return null;
}
ClassOrInterfaceTypeDetails currentClassDetails = governorPhysicalTypeMetadata.getMemberHoldingTypeDetails();
final Map<FieldMetadata, JavaSymbolName> declaredFields = new LinkedHashMap<FieldMetadata, JavaSymbolName>();
final List<FieldMetadata> declaredFieldsList = new ArrayList<FieldMetadata>();
for (final FieldMetadata field : currentClassDetails.getDeclaredFields()) {
declaredFields.put(field, getIdentifierAccessorMethodName(field, metadataIdentificationString));
declaredFieldsList.add(field);
}
// In order to handle switching between GAE and JPA produced MIDs need
// to be remembered so they can be regenerated on JPA <-> GAE switch
producedMids.add(metadataIdentificationString);
// Getting implements
List<JavaType> interfaces = currentClassDetails.getImplementsTypes();
List<? extends MethodMetadata> interfaceMethods = null;
if (!interfaces.isEmpty()) {
for (JavaType currentInterface : interfaces) {
ClassOrInterfaceTypeDetails currentInterfaceDetails = getTypeLocationService().getTypeDetails(currentInterface);
if (currentInterfaceDetails != null) {
interfaceMethods = currentInterfaceDetails.getDeclaredMethods();
}
}
}
final JavaType target = governorPhysicalTypeMetadata.getType();
// Prepare Equals
final EqualsAnnotationValues equalsAnnotationValues = new EqualsAnnotationValues(governorPhysicalTypeMetadata);
List<FieldMetadata> equalsFields = null;
FieldMetadata identifier = null;
if (equalsAnnotationValues.isAnnotationFound()) {
EqualsMetadataProvider equalsProvider = getEqualsMetadataProvider();
equalsFields = equalsProvider.locateFields(target, equalsAnnotationValues.getExcludeFields(), declaredFieldsList, metadataIdentificationString);
identifier = equalsProvider.getIdentifier(governorPhysicalTypeMetadata);
}
// Prepare ToString
final ToStringAnnotationValues toStringAnnotationValues = new ToStringAnnotationValues(governorPhysicalTypeMetadata);
List<FieldMetadata> toStringFields = null;
if (toStringAnnotationValues.isAnnotationFound()) {
ToStringMetadataProvider toStringProvider = getToStringMetadataProvider();
toStringFields = toStringProvider.getToStringFields(governorPhysicalTypeMetadata, declaredFieldsList);
}
return new JavaBeanMetadata(metadataIdentificationString, aspectName, governorPhysicalTypeMetadata, annotationValues, declaredFields, interfaceMethods, getMemberDetailsScanner(), equalsAnnotationValues, equalsFields, identifier, toStringAnnotationValues, toStringFields);
}
use of org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails in project spring-roo by spring-projects.
the class JpaCommands method getIdentifierTypePossibleValues.
@CliOptionAutocompleteIndicator(command = "entity jpa", param = "identifierType", help = "--identifierType option should be a wrapper of a primitive type or an embeddable class.")
public List<String> getIdentifierTypePossibleValues(ShellContext shellContext) {
String currentText = shellContext.getParameters().get("identifierType");
List<String> allPossibleValues = new ArrayList<String>();
// Add java-lang and java-number classes
allPossibleValues.add(Number.class.getName());
allPossibleValues.add(Short.class.getName());
allPossibleValues.add(Byte.class.getName());
allPossibleValues.add(Integer.class.getName());
allPossibleValues.add(Long.class.getName());
allPossibleValues.add(Float.class.getName());
allPossibleValues.add(Double.class.getName());
allPossibleValues.add(BigDecimal.class.getName());
allPossibleValues.add(BigInteger.class.getName());
// Getting all existing embeddable classes
Set<ClassOrInterfaceTypeDetails> embeddableClassesInProject = typeLocationService.findClassesOrInterfaceDetailsWithAnnotation(JpaJavaType.EMBEDDABLE);
for (ClassOrInterfaceTypeDetails embeddableClass : embeddableClassesInProject) {
String name = replaceTopLevelPackageString(embeddableClass, currentText);
if (!allPossibleValues.contains(name)) {
allPossibleValues.add(name);
}
}
return allPossibleValues;
}
Aggregations