use of org.springframework.roo.model.JavaType in project spring-roo by spring-projects.
the class DomainModelModuleMetadata method getConstructor.
private ConstructorMetadata getConstructor() {
InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder();
// Generating constructor
ConstructorMetadataBuilder constructor = new ConstructorMetadataBuilder(getId());
constructor.setModifier(Modifier.PUBLIC);
bodyBuilder.appendFormalLine("// Mixin registration");
bodyBuilder.newLine();
// Generating body
for (Entry<JavaType, JavaType> item : mixins.entrySet()) {
bodyBuilder.appendFormalLine("setMixInAnnotation(%s.class, %s.class);", getNameOfJavaType(item.getKey()), getNameOfJavaType(item.getValue()));
}
// Adding body
constructor.setBodyBuilder(bodyBuilder);
return constructor.build();
}
use of org.springframework.roo.model.JavaType in project spring-roo by spring-projects.
the class DomainModelModuleMetadataProviderImpl method getGovernorPhysicalTypeIdentifier.
@Override
protected String getGovernorPhysicalTypeIdentifier(final String metadataIdentificationString) {
final JavaType javaType = DomainModelModuleMetadata.getJavaType(metadataIdentificationString);
final LogicalPath path = DomainModelModuleMetadata.getPath(metadataIdentificationString);
return PhysicalTypeIdentifier.createIdentifier(javaType, path);
}
use of org.springframework.roo.model.JavaType in project spring-roo by spring-projects.
the class DomainModelModuleMetadataProviderImpl method getLocalMidToRequest.
@Override
protected String getLocalMidToRequest(final ItdTypeDetails itdTypeDetails) {
// Determine the governor for this ITD, and whether any metadata is even
// hoping to hear about changes to that JavaType and its ITDs
final JavaType governor = itdTypeDetails.getName();
final String localMid = domainTypeToServiceMidMap.get(governor);
if (localMid != null) {
return localMid;
}
final MemberHoldingTypeDetails memberHoldingTypeDetails = getTypeLocationService().getTypeDetails(governor);
if (memberHoldingTypeDetails != null) {
for (final JavaType type : memberHoldingTypeDetails.getLayerEntities()) {
final String localMidType = domainTypeToServiceMidMap.get(type);
if (localMidType != null) {
return localMidType;
}
}
}
return null;
}
use of org.springframework.roo.model.JavaType in project spring-roo by spring-projects.
the class EntityDeserializerMetadata method getDeserializeMethod.
private MethodMetadata getDeserializeMethod() {
// Define methodName
final JavaSymbolName methodName = new JavaSymbolName("deserializeObject");
// Adding parameter types
List<AnnotatedJavaType> parameterTypes = new ArrayList<AnnotatedJavaType>();
parameterTypes.add(AnnotatedJavaType.convertFromJavaType(JSON_PARSER));
parameterTypes.add(AnnotatedJavaType.convertFromJavaType(DESERIALIZATION_CONTEXT));
parameterTypes.add(AnnotatedJavaType.convertFromJavaType(OBJECT_CODEC));
parameterTypes.add(AnnotatedJavaType.convertFromJavaType(JSON_NODE));
MethodMetadata existingMethod = getGovernorMethod(methodName, AnnotatedJavaType.convertFromAnnotatedJavaTypes(parameterTypes));
if (existingMethod != null) {
return existingMethod;
}
// Adding parameter names
final List<JavaSymbolName> parameterNames = new ArrayList<JavaSymbolName>();
parameterNames.add(new JavaSymbolName("jsonParser"));
parameterNames.add(new JavaSymbolName("context"));
parameterNames.add(new JavaSymbolName("codec"));
parameterNames.add(new JavaSymbolName("tree"));
// Adding annotations
final List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>();
// Generate body
InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder();
final JavaType idType = getTypeToUseAsIdentifier(entityMetadata.getCurrentIndentifierField().getFieldType());
// String idText = tree.asText();
bodyBuilder.appendFormalLine("String idText = tree.asText();");
// Long id = conversionService.convert(idText, Long.class);
bodyBuilder.appendFormalLine("%s %s = %s.convert(idText, %s.class);", getNameOfJavaType(idType), entityMetadata.getCurrentIndentifierField().getFieldName(), conversionServiceField.getFieldName(), getNameOfJavaType(idType));
final String entityItemName = StringUtils.uncapitalize(entityMetadata.getDestination().getSimpleTypeName());
// Product product = productSercie.findOne(id);
bodyBuilder.appendFormalLine("%s %s = %s.%s(%s);", getNameOfJavaType(entityMetadata.getDestination()), entityItemName, serviceField.getFieldName(), serviceMetadata.getCurrentFindOneMethod().getMethodName(), entityMetadata.getCurrentIndentifierField().getFieldName());
// if (product == null) {
bodyBuilder.appendFormalLine("if (%s == null) {", entityItemName);
// throw new NotFoundException("Product not found");
bodyBuilder.indent();
bodyBuilder.appendFormalLine("throw new %s(\"%s not found\");", getNameOfJavaType(SpringletsJavaType.SPRINGLETS_NOT_FOUND_EXCEPTION), entityMetadata.getDestination().getSimpleTypeName());
bodyBuilder.indentRemove();
// }
bodyBuilder.appendFormalLine("}");
// return product;
bodyBuilder.appendFormalLine("return %s;", entityItemName);
MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder(getId(), Modifier.PUBLIC, methodName, entityMetadata.getDestination(), parameterTypes, parameterNames, bodyBuilder);
methodBuilder.setAnnotations(annotations);
methodBuilder.addThrowsType(IO_EXCEPTION);
return methodBuilder.build();
}
use of org.springframework.roo.model.JavaType in project spring-roo by spring-projects.
the class EntityDeserializerMetadataProviderImpl method getGovernorPhysicalTypeIdentifier.
@Override
protected String getGovernorPhysicalTypeIdentifier(final String metadataIdentificationString) {
final JavaType javaType = EntityDeserializerMetadata.getJavaType(metadataIdentificationString);
final LogicalPath path = EntityDeserializerMetadata.getPath(metadataIdentificationString);
return PhysicalTypeIdentifier.createIdentifier(javaType, path);
}
Aggregations