use of org.springframework.roo.classpath.details.FieldMetadata in project spring-roo by spring-projects.
the class JspViewManager method getCreateDocument.
public Document getCreateDocument() {
final DocumentBuilder builder = XmlUtils.getDocumentBuilder();
final Document document = builder.newDocument();
// Add document namespaces
final Element div = (Element) document.appendChild(new XmlElementBuilder("div", document).addAttribute("xmlns:form", "urn:jsptagdir:/WEB-INF/tags/form").addAttribute("xmlns:field", "urn:jsptagdir:/WEB-INF/tags/form/fields").addAttribute("xmlns:jsp", "http://java.sun.com/JSP/Page").addAttribute("xmlns:c", "http://java.sun.com/jsp/jstl/core").addAttribute("xmlns:spring", "http://www.springframework.org/tags").addAttribute("version", "2.0").addChild(new XmlElementBuilder("jsp:directive.page", document).addAttribute("contentType", "text/html;charset=UTF-8").build()).addChild(new XmlElementBuilder("jsp:output", document).addAttribute("omit-xml-declaration", "yes").build()).build());
// Add form create element
final Element formCreate = new XmlElementBuilder("form:create", document).addAttribute("id", XmlUtils.convertId("fc:" + formBackingType.getFullyQualifiedTypeName())).addAttribute("modelAttribute", entityName).addAttribute("path", controllerPath).addAttribute("render", "${empty dependencies}").build();
if (!controllerPath.equalsIgnoreCase(formBackingType.getSimpleTypeName())) {
formCreate.setAttribute("path", controllerPath);
}
final List<FieldMetadata> formFields = new ArrayList<FieldMetadata>();
final List<FieldMetadata> fieldCopy = new ArrayList<FieldMetadata>(fields);
// Handle Roo identifiers
if (!formBackingTypePersistenceMetadata.getRooIdentifierFields().isEmpty()) {
final String identifierFieldName = formBackingTypePersistenceMetadata.getIdentifierField().getFieldName().getSymbolName();
formCreate.setAttribute("compositePkField", identifierFieldName);
for (final FieldMetadata embeddedField : formBackingTypePersistenceMetadata.getRooIdentifierFields()) {
final FieldMetadataBuilder fieldBuilder = new FieldMetadataBuilder(embeddedField);
fieldBuilder.setFieldName(new JavaSymbolName(identifierFieldName + "." + embeddedField.getFieldName().getSymbolName()));
for (int i = 0; i < fieldCopy.size(); i++) {
// Make sure form fields are not presented twice.
if (fieldCopy.get(i).getFieldName().equals(embeddedField.getFieldName())) {
fieldCopy.remove(i);
break;
}
}
formFields.add(fieldBuilder.build());
}
}
formFields.addAll(fieldCopy);
// If identifier manually assigned, show it in creation
if (formBackingTypePersistenceMetadata.getIdentifierField().getAnnotation(JpaJavaType.GENERATED_VALUE) == null) {
formFields.add(formBackingTypePersistenceMetadata.getIdentifierField());
}
createFieldsForCreateAndUpdate(formFields, document, formCreate, true);
formCreate.setAttribute("z", XmlRoundTripUtils.calculateUniqueKeyFor(formCreate));
final Element dependency = new XmlElementBuilder("form:dependency", document).addAttribute("id", XmlUtils.convertId("d:" + formBackingType.getFullyQualifiedTypeName())).addAttribute("render", "${not empty dependencies}").addAttribute("dependencies", "${dependencies}").build();
dependency.setAttribute("z", XmlRoundTripUtils.calculateUniqueKeyFor(dependency));
div.appendChild(formCreate);
div.appendChild(dependency);
return document;
}
use of org.springframework.roo.classpath.details.FieldMetadata in project spring-roo by spring-projects.
the class JspViewManager method getShowDocument.
public Document getShowDocument() {
final DocumentBuilder builder = XmlUtils.getDocumentBuilder();
final Document document = builder.newDocument();
// Add document namespaces
final Element div = (Element) document.appendChild(new XmlElementBuilder("div", document).addAttribute("xmlns:page", "urn:jsptagdir:/WEB-INF/tags/form").addAttribute("xmlns:field", "urn:jsptagdir:/WEB-INF/tags/form/fields").addAttribute("xmlns:jsp", "http://java.sun.com/JSP/Page").addAttribute("version", "2.0").addChild(new XmlElementBuilder("jsp:directive.page", document).addAttribute("contentType", "text/html;charset=UTF-8").build()).addChild(new XmlElementBuilder("jsp:output", document).addAttribute("omit-xml-declaration", "yes").build()).build());
final Element pageShow = new XmlElementBuilder("page:show", document).addAttribute("id", XmlUtils.convertId("ps:" + formBackingType.getFullyQualifiedTypeName())).addAttribute("object", "${" + entityName.toLowerCase() + "}").addAttribute("path", controllerPath).build();
if (!webScaffoldAnnotationValues.isCreate()) {
pageShow.setAttribute("create", "false");
}
if (!webScaffoldAnnotationValues.isUpdate()) {
pageShow.setAttribute("update", "false");
}
if (!webScaffoldAnnotationValues.isDelete()) {
pageShow.setAttribute("delete", "false");
}
pageShow.setAttribute("z", XmlRoundTripUtils.calculateUniqueKeyFor(pageShow));
// Add field:display elements for each field
for (final FieldMetadata field : fields) {
// Ignoring java.util.Map field types (see ROO-194)
if (field.getFieldType().equals(new JavaType(Map.class.getName()))) {
continue;
}
final String fieldName = uncapitalize(field.getFieldName().getSymbolName());
final Element fieldDisplay = new XmlElementBuilder("field:display", document).addAttribute("id", XmlUtils.convertId("s:" + formBackingType.getFullyQualifiedTypeName() + "." + field.getFieldName().getSymbolName())).addAttribute("object", "${" + entityName.toLowerCase() + "}").addAttribute("field", fieldName).build();
if (field.getFieldType().equals(DATE)) {
if (fieldName.equals(CREATED)) {
continue;
}
fieldDisplay.setAttribute("date", "true");
fieldDisplay.setAttribute("dateTimePattern", "${" + entityName + "_" + fieldName.toLowerCase() + "_date_format}");
} else if (field.getFieldType().equals(CALENDAR)) {
fieldDisplay.setAttribute("calendar", "true");
fieldDisplay.setAttribute("dateTimePattern", "${" + entityName + "_" + fieldName.toLowerCase() + "_date_format}");
} else if (field.getFieldType().isCommonCollectionType() && field.getCustomData().get(CustomDataKeys.ONE_TO_MANY_FIELD) != null) {
continue;
}
fieldDisplay.setAttribute("z", XmlRoundTripUtils.calculateUniqueKeyFor(fieldDisplay));
pageShow.appendChild(fieldDisplay);
}
div.appendChild(pageShow);
return document;
}
use of org.springframework.roo.classpath.details.FieldMetadata in project spring-roo by spring-projects.
the class JspViewManager method getUpdateDocument.
public Document getUpdateDocument() {
final DocumentBuilder builder = XmlUtils.getDocumentBuilder();
final Document document = builder.newDocument();
// Add document namespaces
final Element div = (Element) document.appendChild(new XmlElementBuilder("div", document).addAttribute("xmlns:form", "urn:jsptagdir:/WEB-INF/tags/form").addAttribute("xmlns:field", "urn:jsptagdir:/WEB-INF/tags/form/fields").addAttribute("xmlns:jsp", "http://java.sun.com/JSP/Page").addAttribute("version", "2.0").addChild(new XmlElementBuilder("jsp:directive.page", document).addAttribute("contentType", "text/html;charset=UTF-8").build()).addChild(new XmlElementBuilder("jsp:output", document).addAttribute("omit-xml-declaration", "yes").build()).build());
// Add form update element
final Element formUpdate = new XmlElementBuilder("form:update", document).addAttribute("id", XmlUtils.convertId("fu:" + formBackingType.getFullyQualifiedTypeName())).addAttribute("modelAttribute", entityName).build();
if (!controllerPath.equalsIgnoreCase(formBackingType.getSimpleTypeName())) {
formUpdate.setAttribute("path", controllerPath);
}
if (!"id".equals(formBackingTypePersistenceMetadata.getIdentifierField().getFieldName().getSymbolName())) {
formUpdate.setAttribute("idField", formBackingTypePersistenceMetadata.getIdentifierField().getFieldName().getSymbolName());
}
final MethodMetadata versionAccessorMethod = formBackingTypePersistenceMetadata.getVersionAccessorMethod();
if (versionAccessorMethod == null) {
formUpdate.setAttribute("versionField", "none");
} else {
final String methodName = versionAccessorMethod.getMethodName().getSymbolName();
formUpdate.setAttribute("versionField", methodName.substring("get".length()));
}
// Filter out embedded ID fields as they represent the composite PK
// which is not to be updated.
final List<FieldMetadata> fieldCopy = new ArrayList<FieldMetadata>(fields);
for (final FieldMetadata embeddedField : formBackingTypePersistenceMetadata.getRooIdentifierFields()) {
for (int i = 0; i < fieldCopy.size(); i++) {
// Make sure form fields are not presented twice.
if (fieldCopy.get(i).getFieldName().equals(embeddedField.getFieldName())) {
fieldCopy.remove(i);
}
}
}
createFieldsForCreateAndUpdate(fieldCopy, document, formUpdate, false);
formUpdate.setAttribute("z", XmlRoundTripUtils.calculateUniqueKeyFor(formUpdate));
div.appendChild(formUpdate);
return document;
}
use of org.springframework.roo.classpath.details.FieldMetadata in project spring-roo by spring-projects.
the class ControllerCommands method getDetailFieldsRelatedToEntity.
/**
* Get a field list that can be selected to do a detail controller.
*
* @param entity
* Entity on which create the detail controller
* @param parentFieldName
* The parent's field name used to construct the field name
* related with the original entity
* @return the related field list
*/
private List<String> getDetailFieldsRelatedToEntity(ClassOrInterfaceTypeDetails entity, String parentFieldName) {
List<String> results = new ArrayList<String>();
MemberDetails entityDetails = getMemberDetailsScanner().getMemberDetails(entity.getType().getSimpleTypeName(), entity);
List<FieldMetadata> fields = entityDetails.getFields();
for (FieldMetadata field : fields) {
AnnotationMetadata oneToManyAnnotation = field.getAnnotation(JpaJavaType.ONE_TO_MANY);
AnnotationMetadata manyToManyAnnotation = field.getAnnotation(JpaJavaType.MANY_TO_MANY);
if ((oneToManyAnnotation != null || manyToManyAnnotation != null) && (field.getFieldType().getFullyQualifiedTypeName().equals(JavaType.LIST.getFullyQualifiedTypeName()) || field.getFieldType().getFullyQualifiedTypeName().equals(JavaType.SET.getFullyQualifiedTypeName()))) {
results.add(parentFieldName.concat(field.getFieldName().getSymbolName()));
}
}
return results;
}
use of org.springframework.roo.classpath.details.FieldMetadata in project spring-roo by spring-projects.
the class ExceptionsMetadataProviderImpl method getMetadata.
@Override
protected ItdTypeDetailsProvidingMetadataItem getMetadata(String metadataIdentificationString, JavaType aspectName, PhysicalTypeMetadata governorPhysicalTypeMetadata, String itdFilename) {
AnnotationMetadata handlersAnnotation = governorPhysicalTypeMetadata.getMemberHoldingTypeDetails().getAnnotation(ROO_EXCEPTION_HANDLERS);
// Prepare list to register @RooExceptionHandler annotations data
List<ExceptionHandlerAnnotationValues> exceptionHandlerValues = new ArrayList<ExceptionHandlerAnnotationValues>();
// Get nested annotations
AnnotationAttributeValue<Object> handlers = handlersAnnotation.getAttribute("value");
List<?> values = (List<?>) handlers.getValue();
Iterator<?> valuesIt = values.iterator();
// Iterate over nested annotations
while (valuesIt.hasNext()) {
NestedAnnotationAttributeValue handlerAnnotation = (NestedAnnotationAttributeValue) valuesIt.next();
if (handlerAnnotation.getValue() != null) {
// Get attribute values
JavaType exception = getNestedAttributeValue(handlerAnnotation, "exception");
ClassOrInterfaceTypeDetails exceptionDetails = getTypeLocationService().getTypeDetails(exception);
Validate.notNull(exception, "'exception' attribute in @RooExceptionHandler must not be null");
String errorView = getNestedAttributeValue(handlerAnnotation, "errorView");
// Register attribute values
exceptionHandlerValues.add(new ExceptionHandlerAnnotationValues(exceptionDetails, errorView));
}
}
// Check if type is a controller
AnnotationMetadata rooControllerAnnotation = governorPhysicalTypeMetadata.getMemberHoldingTypeDetails().getAnnotation(RooJavaType.ROO_CONTROLLER);
boolean isController = rooControllerAnnotation != null;
List<FieldMetadata> fieldsMetadata = getMemberDetailsScanner().getMemberDetails(this.getClass().getName(), governorPhysicalTypeMetadata.getMemberHoldingTypeDetails()).getFields();
return new ExceptionsMetadata(metadataIdentificationString, exceptionHandlerValues, aspectName, governorPhysicalTypeMetadata, fieldsMetadata, isController);
}
Aggregations