当前位置: 首页>>代码示例>>Java>>正文


Java SpringJavaType.getConverterType方法代码示例

本文整理汇总了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);
}
 
开发者ID:gvSIGAssociation,项目名称:gvnix1,代码行数:35,代码来源:ConversionServiceMetadata.java

示例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);
}
 
开发者ID:gvSIGAssociation,项目名称:gvnix1,代码行数:45,代码来源:ConversionServiceMetadata.java

示例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);
}
 
开发者ID:gvSIGAssociation,项目名称:gvnix1,代码行数:37,代码来源:ConversionServiceMetadata.java

示例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);
}
 
开发者ID:gvSIGAssociation,项目名称:gvnix1,代码行数:32,代码来源:ConversionServiceMetadata.java

示例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);
}
 
开发者ID:gvSIGAssociation,项目名称:gvnix1,代码行数:34,代码来源:ConversionServiceMetadata.java

示例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;
}
 
开发者ID:gvSIGAssociation,项目名称:gvnix1,代码行数:72,代码来源:ConversionServiceMetadata.java


注:本文中的org.springframework.roo.model.SpringJavaType.getConverterType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。