本文整理汇总了Java中org.springframework.roo.model.SpringJavaType.getConverterType方法的典型用法代码示例。如果您正苦于以下问题:Java SpringJavaType.getConverterType方法的具体用法?Java SpringJavaType.getConverterType怎么用?Java SpringJavaType.getConverterType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.roo.model.SpringJavaType
的用法示例。
在下文中一共展示了SpringJavaType.getConverterType方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getJsonToConverterMethod
import org.springframework.roo.model.SpringJavaType; //导入方法依赖的package包/类
private MethodMetadataBuilder getJsonToConverterMethod(
final JavaType targetType, final JavaSymbolName jsonMethodName) {
final JavaSymbolName methodName = new JavaSymbolName("getJsonTo"
+ targetType.getSimpleTypeName() + CONVERTER);
if (governorHasMethod(methodName)) {
return null;
}
final JavaType converterJavaType = SpringJavaType.getConverterType(
JavaType.STRING, targetType);
final String base64Name = BASE_64.getNameIncludingTypeParameters(false,
builder.getImportRegistrationResolver());
final String typeName = targetType.getNameIncludingTypeParameters(
false, builder.getImportRegistrationResolver());
final InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder();
bodyBuilder.appendFormalLine("return new "
+ converterJavaType.getNameIncludingTypeParameters() + "() {");
bodyBuilder.indent();
bodyBuilder.appendFormalLine("public " + targetType.getSimpleTypeName()
+ " convert(String encodedJson) {");
bodyBuilder.indent();
bodyBuilder.appendFormalLine("return " + typeName + "."
+ jsonMethodName.getSymbolName() + "(new String(" + base64Name
+ ".decodeBase64(encodedJson)));");
bodyBuilder.indentRemove();
bodyBuilder.appendFormalLine("}");
bodyBuilder.indentRemove();
bodyBuilder.appendFormalLine("};");
return new MethodMetadataBuilder(getId(), Modifier.PUBLIC, methodName,
converterJavaType, bodyBuilder);
}
示例2: getStringToTypeConverterMethod
import org.springframework.roo.model.SpringJavaType; //导入方法依赖的package包/类
/**
* Returns the "string to type" converter method to be generated, if any
*
* @param targetType
* the type being converted into (required)
* @param methodName
* the name of the method to generate if necessary (required)
* @param idType
* the ID type of the given target type (required)
* @return <code>null</code> if none is to be generated
*/
private MethodMetadataBuilder getStringToTypeConverterMethod(
final JavaType targetType, final JavaSymbolName methodName,
final JavaType idType) {
if (governorHasMethod(methodName)) {
return null;
}
final JavaType converterJavaType = SpringJavaType.getConverterType(
JavaType.STRING, targetType);
final String idTypeName = idType.getNameIncludingTypeParameters(false,
builder.getImportRegistrationResolver());
final InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder();
bodyBuilder.appendFormalLine("return new "
+ converterJavaType.getNameIncludingTypeParameters() + "() {");
bodyBuilder.indent();
bodyBuilder.appendFormalLine("public "
+ targetType.getFullyQualifiedTypeName()
+ " convert(String id) {");
bodyBuilder.indent();
bodyBuilder
.appendFormalLine("return getObject().convert(getObject().convert(id, "
+ idTypeName
+ ".class), "
+ targetType.getSimpleTypeName() + ".class);");
bodyBuilder.indentRemove();
bodyBuilder.appendFormalLine("}");
bodyBuilder.indentRemove();
bodyBuilder.appendFormalLine("};");
return new MethodMetadataBuilder(getId(), Modifier.PUBLIC, methodName,
converterJavaType, bodyBuilder);
}
示例3: getToJsonConverterMethod
import org.springframework.roo.model.SpringJavaType; //导入方法依赖的package包/类
private MethodMetadataBuilder getToJsonConverterMethod(
final JavaType targetType, final JavaSymbolName jsonMethodName) {
final JavaSymbolName methodName = new JavaSymbolName("get"
+ targetType.getSimpleTypeName() + "ToJsonConverter");
if (governorHasMethod(methodName)) {
return null;
}
final JavaType converterJavaType = SpringJavaType.getConverterType(
targetType, JavaType.STRING);
final String base64Name = BASE_64.getNameIncludingTypeParameters(false,
builder.getImportRegistrationResolver());
final String targetTypeName = StringUtils.uncapitalize(targetType
.getSimpleTypeName());
final InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder();
bodyBuilder.appendFormalLine("return new "
+ converterJavaType.getNameIncludingTypeParameters() + "() {");
bodyBuilder.indent();
bodyBuilder
.appendFormalLine("public String convert("
+ targetType.getSimpleTypeName() + " " + targetTypeName
+ ") {");
bodyBuilder.indent();
bodyBuilder.appendFormalLine("return " + base64Name
+ ".encodeBase64URLSafeString(" + targetTypeName + "."
+ jsonMethodName.getSymbolName() + "().getBytes());");
bodyBuilder.indentRemove();
bodyBuilder.appendFormalLine("}");
bodyBuilder.indentRemove();
bodyBuilder.appendFormalLine("};");
return new MethodMetadataBuilder(getId(), Modifier.PUBLIC, methodName,
converterJavaType, bodyBuilder);
}
示例4: getToStringConverterMethod
import org.springframework.roo.model.SpringJavaType; //导入方法依赖的package包/类
private MethodMetadataBuilder getToStringConverterMethod(
final JavaType targetType, final JavaSymbolName methodName,
final List<MethodMetadata> toStringMethods) {
if (governorHasMethod(methodName)) {
return null;
}
final JavaType converterJavaType = SpringJavaType.getConverterType(
targetType, JavaType.STRING);
final String targetTypeName = StringUtils.uncapitalize(targetType
.getSimpleTypeName());
final InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder();
bodyBuilder.appendFormalLine("return new "
+ converterJavaType.getNameIncludingTypeParameters() + "() {");
bodyBuilder.indent();
bodyBuilder
.appendFormalLine("public String convert("
+ targetType.getSimpleTypeName() + " " + targetTypeName
+ ") {");
bodyBuilder.indent();
bodyBuilder.appendFormalLine(getTypeToStringLine(targetType,
targetTypeName, toStringMethods));
bodyBuilder.indentRemove();
bodyBuilder.appendFormalLine("}");
bodyBuilder.indentRemove();
bodyBuilder.appendFormalLine("};");
return new MethodMetadataBuilder(getId(), Modifier.PUBLIC, methodName,
converterJavaType, bodyBuilder);
}
示例5: getToTypeConverterMethod
import org.springframework.roo.model.SpringJavaType; //导入方法依赖的package包/类
private MethodMetadataBuilder getToTypeConverterMethod(
final JavaType targetType, final JavaSymbolName methodName,
final MemberTypeAdditions findMethod, final JavaType idType) {
final MethodMetadata toTypeConverterMethod = getGovernorMethod(methodName);
if (findMethod == null) {
return null;
}
if (toTypeConverterMethod != null) {
return new MethodMetadataBuilder(toTypeConverterMethod);
}
findMethod.copyAdditionsTo(builder, governorTypeDetails);
final JavaType converterJavaType = SpringJavaType.getConverterType(
idType, targetType);
final InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder();
bodyBuilder.appendFormalLine("return new "
+ converterJavaType.getNameIncludingTypeParameters() + "() {");
bodyBuilder.indent();
bodyBuilder.appendFormalLine("public "
+ targetType.getFullyQualifiedTypeName() + " convert(" + idType
+ " id) {");
bodyBuilder.indent();
bodyBuilder.appendFormalLine("return " + findMethod.getMethodCall()
+ ";");
bodyBuilder.indentRemove();
bodyBuilder.appendFormalLine("}");
bodyBuilder.indentRemove();
bodyBuilder.appendFormalLine("};");
return new MethodMetadataBuilder(getId(), Modifier.PUBLIC, methodName,
converterJavaType, bodyBuilder);
}
示例6: generateEmbeddableTypeToStringMethods
import org.springframework.roo.model.SpringJavaType; //导入方法依赖的package包/类
/**
* Method to generate embeddable to string method
*
* @param embeddableTypeDetails
* @return
*/
private List<MethodMetadataBuilder> generateEmbeddableTypeToStringMethods() {
final List<MethodMetadataBuilder> embeddableToStringMethods = new ArrayList<MethodMetadataBuilder>();
for (JavaType embeddableType : this.embeddableTypes) {
ClassOrInterfaceTypeDetails embeddableTypeDetails = typeLocationService
.getTypeDetails(embeddableType);
// Generating method
final JavaSymbolName methodName = new JavaSymbolName(String.format(
"get%sToStringConverter",
embeddableType.getSimpleTypeName()));
if (governorHasMethod(methodName)) {
continue;
}
final JavaType converterJavaType = SpringJavaType.getConverterType(
embeddableType, JavaType.STRING);
final String targetTypeName = StringUtils
.uncapitalize(embeddableType.getSimpleTypeName());
final InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder();
bodyBuilder.appendFormalLine("return new "
+ converterJavaType.getNameIncludingTypeParameters()
+ "() {");
bodyBuilder.indent();
bodyBuilder.appendFormalLine("public String convert("
+ embeddableType.getSimpleTypeName() + " " + targetTypeName
+ ") {");
bodyBuilder.indent();
// Getting embedded class fields
List<? extends FieldMetadata> embeddableFields = embeddableTypeDetails
.getDeclaredFields();
if (embeddableFields.isEmpty()) {
bodyBuilder.appendFormalLine("return \"\";");
} else {
StringBuilder sb = new StringBuilder();
for (FieldMetadata field : embeddableFields) {
sb.append(String.format(
".append(%s.get%s()).append(\" \")",
targetTypeName, field.getFieldName()
.getSymbolNameCapitalisedFirstLetter()));
}
bodyBuilder.appendFormalLine(String.format(
"return new StringBuilder()%s.toString();",
sb.toString()));
}
bodyBuilder.indentRemove();
bodyBuilder.appendFormalLine("}");
bodyBuilder.indentRemove();
bodyBuilder.appendFormalLine("};");
embeddableToStringMethods
.add(new MethodMetadataBuilder(getId(), Modifier.PUBLIC,
methodName, converterJavaType, bodyBuilder));
}
return embeddableToStringMethods;
}