use of org.springframework.roo.classpath.details.annotations.EnumAttributeValue in project spring-roo by spring-projects.
the class ReferenceField method decorateAnnotationsList.
@Override
public void decorateAnnotationsList(final List<AnnotationMetadataBuilder> annotations) {
super.decorateAnnotationsList(annotations);
final List<AnnotationAttributeValue<?>> attributes = new ArrayList<AnnotationAttributeValue<?>>();
// Add cascade if option exists
if (cascadeType != null) {
List<EnumAttributeValue> cascadeValues = new ArrayList<EnumAttributeValue>();
for (Cascade type : cascadeType) {
cascadeValues.add(new EnumAttributeValue(new JavaSymbolName("cascade"), new EnumDetails(CASCADE_TYPE, new JavaSymbolName(type.name()))));
}
attributes.add(new ArrayAttributeValue<EnumAttributeValue>(new JavaSymbolName("cascade"), cascadeValues));
}
// Add orphanRemoval if option exists
if (getOrphanRemoval() != null) {
attributes.add(new BooleanAttributeValue(new JavaSymbolName("orphanRemoval"), getOrphanRemoval().booleanValue()));
}
if (fetch != null) {
JavaSymbolName value = new JavaSymbolName("EAGER");
if (fetch == Fetch.LAZY) {
value = new JavaSymbolName("LAZY");
}
attributes.add(new EnumAttributeValue(new JavaSymbolName("fetch"), new EnumDetails(FETCH_TYPE, value)));
}
if (mappedBy != null) {
attributes.add(new StringAttributeValue(new JavaSymbolName("mappedBy"), mappedBy.getSymbolName()));
}
switch(cardinality) {
case ONE_TO_MANY:
annotations.add(new AnnotationMetadataBuilder(ONE_TO_MANY, attributes));
break;
case MANY_TO_MANY:
annotations.add(new AnnotationMetadataBuilder(MANY_TO_MANY, attributes));
break;
case ONE_TO_ONE:
annotations.add(new AnnotationMetadataBuilder(ONE_TO_ONE, attributes));
break;
default:
annotations.add(new AnnotationMetadataBuilder(MANY_TO_ONE, attributes));
break;
}
// Add additional annotations (if any)
if (additionaAnnotations != null) {
annotations.addAll(additionaAnnotations);
}
}
use of org.springframework.roo.classpath.details.annotations.EnumAttributeValue in project spring-roo by spring-projects.
the class EnumField method decorateAnnotationsList.
@Override
public void decorateAnnotationsList(final List<AnnotationMetadataBuilder> annotations) {
super.decorateAnnotationsList(annotations);
final List<AnnotationAttributeValue<?>> attributes = new ArrayList<AnnotationAttributeValue<?>>();
if (enumType != null) {
JavaSymbolName value = new JavaSymbolName("ORDINAL");
if (enumType == EnumType.STRING) {
value = new JavaSymbolName("STRING");
}
attributes.add(new EnumAttributeValue(new JavaSymbolName("value"), new EnumDetails(ENUM_TYPE, value)));
}
annotations.add(new AnnotationMetadataBuilder(ENUMERATED, attributes));
}
use of org.springframework.roo.classpath.details.annotations.EnumAttributeValue in project spring-roo by spring-projects.
the class JpaEntityMetadataProviderImpl method getCompositionRelationField.
/**
* Gets {@link FieldMetadata} of entity field which declares a composition relationship
*
* @param entity
* @param entityDetails
* @param relationsAsChild
* @return
* @throws ClassNotFoundException
*/
private FieldMetadata getCompositionRelationField(JavaType entity, ClassOrInterfaceTypeDetails entityDetails, Map<String, FieldMetadata> relationsAsChild) throws ClassNotFoundException {
// Try to identify if it's is a child part of a composition.
// It uses details and annotation values instead metadata to
// avoid problems of circular dependencies
ClassOrInterfaceTypeDetails parentDatils;
FieldMetadata compositionRelationField = null;
AnnotationMetadata parentFieldRelationAnnotation;
JpaRelationType type;
String parentMappedBy;
for (FieldMetadata field : relationsAsChild.values()) {
parentDatils = getTypeLocationService().getTypeDetails(field.getFieldType().getBaseType());
for (FieldMetadata parentField : parentDatils.getFieldsWithAnnotation(RooJavaType.ROO_JPA_RELATION)) {
parentFieldRelationAnnotation = parentField.getAnnotation(RooJavaType.ROO_JPA_RELATION);
if (parentFieldRelationAnnotation != null && entity.equals(parentField.getFieldType().getBaseType())) {
parentMappedBy = getFieldMappedByAnnotationValue(parentField);
if (field.getFieldName().getSymbolName().equals(parentMappedBy)) {
// Found parent relation field
// Check composition
EnumDetails value = ((EnumAttributeValue) parentFieldRelationAnnotation.getAttribute(new JavaSymbolName("type"))).getValue();
if (JpaRelationType.COMPOSITION.name().equals(value.getField().getSymbolName())) {
// Found composition
if (compositionRelationField != null) {
throw new IllegalArgumentException(String.format("Found to relations which '%s' is child part of composition relation field: '%s' and '%s'", entity.getFullyQualifiedTypeName(), compositionRelationField.getFieldName(), field.getFieldName()));
}
compositionRelationField = field;
}
}
}
}
}
return compositionRelationField;
}
use of org.springframework.roo.classpath.details.annotations.EnumAttributeValue in project spring-roo by spring-projects.
the class JavaParserAnnotationMetadataBuilder method convert.
@SuppressWarnings("unchecked")
private static MemberValuePair convert(final AnnotationAttributeValue<?> value, CompilationUnitServices compilationUnitServices) {
if (value instanceof NestedAnnotationAttributeValue) {
final NestedAnnotationAttributeValue castValue = (NestedAnnotationAttributeValue) value;
AnnotationExpr annotationExpr;
final AnnotationMetadata nestedAnnotation = castValue.getValue();
if (castValue.getValue().getAttributeNames().size() == 0) {
annotationExpr = new MarkerAnnotationExpr(JavaParserUtils.getNameExpr(nestedAnnotation.getAnnotationType().getSimpleTypeName()));
} else if (castValue.getValue().getAttributeNames().size() == 1 && (castValue.getValue().getAttributeNames().get(0) == null || "value".equals(castValue.getValue().getAttributeNames().get(0).getSymbolName()))) {
annotationExpr = new SingleMemberAnnotationExpr(JavaParserUtils.getNameExpr(nestedAnnotation.getAnnotationType().getSimpleTypeName()), convert(nestedAnnotation.getAttribute(nestedAnnotation.getAttributeNames().get(0)), compilationUnitServices).getValue());
} else {
final List<MemberValuePair> memberValuePairs = new ArrayList<MemberValuePair>();
for (final JavaSymbolName attributeName : nestedAnnotation.getAttributeNames()) {
memberValuePairs.add(convert(nestedAnnotation.getAttribute(attributeName), compilationUnitServices));
}
annotationExpr = new NormalAnnotationExpr(JavaParserUtils.getNameExpr(nestedAnnotation.getAnnotationType().getSimpleTypeName()), memberValuePairs);
}
// Add imports for nested annotation types
JavaParserUtils.importTypeIfRequired(compilationUnitServices.getEnclosingTypeName(), compilationUnitServices.getImports(), nestedAnnotation.getAnnotationType());
// Rely on the nested instance to know its member value pairs
return new MemberValuePair(value.getName().getSymbolName(), annotationExpr);
}
if (value instanceof BooleanAttributeValue) {
final boolean castValue = ((BooleanAttributeValue) value).getValue();
final BooleanLiteralExpr convertedValue = new BooleanLiteralExpr(castValue);
return new MemberValuePair(value.getName().getSymbolName(), convertedValue);
}
if (value instanceof CharAttributeValue) {
final char castValue = ((CharAttributeValue) value).getValue();
final CharLiteralExpr convertedValue = new CharLiteralExpr(new String(new char[] { castValue }));
return new MemberValuePair(value.getName().getSymbolName(), convertedValue);
}
if (value instanceof LongAttributeValue) {
final Long castValue = ((LongAttributeValue) value).getValue();
final LongLiteralExpr convertedValue = new LongLiteralExpr(castValue.toString() + "L");
return new MemberValuePair(value.getName().getSymbolName(), convertedValue);
}
if (value instanceof IntegerAttributeValue) {
final Integer castValue = ((IntegerAttributeValue) value).getValue();
final IntegerLiteralExpr convertedValue = new IntegerLiteralExpr(castValue.toString());
return new MemberValuePair(value.getName().getSymbolName(), convertedValue);
}
if (value instanceof DoubleAttributeValue) {
final DoubleAttributeValue doubleAttributeValue = (DoubleAttributeValue) value;
final Double castValue = doubleAttributeValue.getValue();
DoubleLiteralExpr convertedValue;
if (doubleAttributeValue.isFloatingPrecisionOnly()) {
convertedValue = new DoubleLiteralExpr(castValue.toString() + "F");
} else {
convertedValue = new DoubleLiteralExpr(castValue.toString() + "D");
}
return new MemberValuePair(value.getName().getSymbolName(), convertedValue);
}
if (value instanceof StringAttributeValue) {
final String castValue = ((StringAttributeValue) value).getValue();
final StringLiteralExpr convertedValue = new StringLiteralExpr(castValue.toString());
return new MemberValuePair(value.getName().getSymbolName(), convertedValue);
}
if (value instanceof EnumAttributeValue) {
final EnumDetails castValue = ((EnumAttributeValue) value).getValue();
// This isn't as elegant as it could be (ie loss of type
// parameters), but it will do for now
final FieldAccessExpr convertedValue = new FieldAccessExpr(JavaParserUtils.getNameExpr(castValue.getType().getFullyQualifiedTypeName()), castValue.getField().getSymbolName());
return new MemberValuePair(value.getName().getSymbolName(), convertedValue);
}
if (value instanceof ClassAttributeValue) {
final JavaType castValue = ((ClassAttributeValue) value).getValue();
// This doesn't preserve type parameters
final NameExpr nameExpr = JavaParserUtils.importTypeIfRequired(compilationUnitServices.getEnclosingTypeName(), compilationUnitServices.getImports(), castValue);
final ClassExpr convertedValue = new ClassExpr(JavaParserUtils.getReferenceType(nameExpr));
return new MemberValuePair(value.getName().getSymbolName(), convertedValue);
}
if (value instanceof ArrayAttributeValue) {
final ArrayAttributeValue<AnnotationAttributeValue<?>> castValue = (ArrayAttributeValue<AnnotationAttributeValue<?>>) value;
final List<Expression> arrayElements = new ArrayList<Expression>();
for (final AnnotationAttributeValue<?> v : castValue.getValue()) {
final MemberValuePair converted = convert(v, compilationUnitServices);
if (converted != null) {
arrayElements.add(converted.getValue());
}
}
return new MemberValuePair(value.getName().getSymbolName(), new ArrayInitializerExpr(arrayElements));
}
throw new UnsupportedOperationException("Unsupported attribute value '" + value.getName() + "' of type '" + value.getClass().getName() + "'");
}
use of org.springframework.roo.classpath.details.annotations.EnumAttributeValue in project spring-roo by spring-projects.
the class WsOperationsImpl method getWsClientAnnotation.
/**
* This method provides @RooWsClient annotation with all the necessary attributes
*
* @param endpoint
* @param targetNamespace
* @param bindingType
* @return
*/
private AnnotationMetadataBuilder getWsClientAnnotation(final String endpoint, final String targetNamespace, final SoapBindingType bindingType) {
final List<AnnotationAttributeValue<?>> wsClientAttributes = new ArrayList<AnnotationAttributeValue<?>>();
wsClientAttributes.add(new StringAttributeValue(new JavaSymbolName("endpoint"), endpoint));
wsClientAttributes.add(new StringAttributeValue(new JavaSymbolName("targetNamespace"), targetNamespace));
wsClientAttributes.add(new EnumAttributeValue(new JavaSymbolName("binding"), new EnumDetails(RooJavaType.ROO_ENUM_SOAP_BINDING_TYPE, new JavaSymbolName(bindingType.name()))));
return new AnnotationMetadataBuilder(RooJavaType.ROO_WS_CLIENT, wsClientAttributes);
}
Aggregations