use of org.mule.runtime.module.extension.api.loader.java.type.Type in project mule by mulesoft.
the class ConnectionProviderModelValidator method validateConfigLevelConnectionTypes.
private void validateConfigLevelConnectionTypes(Multimap<ConfigurationModel, ConnectionProviderModel> configLevelConnectionProviders, ProblemsReporter problemsReporter) {
configLevelConnectionProviders.asMap().forEach((configModel, providerModels) -> {
for (ConnectionProviderModel providerModel : providerModels) {
Type connectionType = MuleExtensionUtils.getConnectionType(providerModel);
configModel.getOperationModels().forEach(operationModel -> validateConnectionTypes(providerModel, operationModel, connectionType, problemsReporter));
}
});
}
use of org.mule.runtime.module.extension.api.loader.java.type.Type in project mule by mulesoft.
the class ConnectionProviderModelValidator method validateGlobalConnectionTypes.
private void validateGlobalConnectionTypes(ExtensionModel extensionModel, Set<ConnectionProviderModel> globalConnectionProviders, ProblemsReporter problemsReporter) {
if (globalConnectionProviders.isEmpty()) {
return;
}
for (ConnectionProviderModel connectionProviderModel : globalConnectionProviders) {
final Type connectionType = MuleExtensionUtils.getConnectionType(connectionProviderModel);
new IdempotentExtensionWalker() {
@Override
protected void onOperation(OperationModel operationModel) {
validateConnectionTypes(connectionProviderModel, operationModel, connectionType, problemsReporter);
}
@Override
protected void onSource(SourceModel sourceModel) {
validateConnectionTypes(connectionProviderModel, sourceModel, connectionType, problemsReporter);
}
}.walk(extensionModel);
}
}
use of org.mule.runtime.module.extension.api.loader.java.type.Type in project mule by mulesoft.
the class IntrospectionUtils method getReturnType.
private static MetadataType getReturnType(Type returnType) {
Type type = returnType;
if (returnType.isAssignableTo(Result.class)) {
List<TypeGeneric> generics = returnType.getGenerics();
if (generics.isEmpty()) {
return typeBuilder().anyType().build();
}
Type payloadType = generics.get(0).getConcreteType();
if (!payloadType.isAnyType()) {
type = payloadType;
} else {
type = null;
}
}
if (isPagingProvider(returnType)) {
Type itemType = getPagingProviderTypes(returnType).getSecond();
if (itemType.isSameType(Result.class)) {
return returnListOfMessagesType(returnType, itemType);
} else {
return typeBuilder().arrayType().of(itemType.asMetadataType()).with(returnType.getClassInformation()).build();
}
}
if (returnType.isAssignableTo(ParameterResolver.class) || returnType.isAssignableTo(TypedValue.class) || returnType.isAssignableTo(Literal.class)) {
type = returnType.getGenerics().get(0).getConcreteType();
}
if (isCollection(returnType) && !returnType.getGenerics().isEmpty()) {
Type itemType = returnType.getGenerics().get(0).getConcreteType();
if (itemType.isAssignableTo(Result.class)) {
return returnListOfMessagesType(returnType, itemType);
}
}
return type != null ? type.asMetadataType() : typeBuilder().anyType().build();
}
use of org.mule.runtime.module.extension.api.loader.java.type.Type in project mule by mulesoft.
the class IntrospectionUtils method toDataType.
/**
* Transforms a {@link MetadataType} and generates the correspondent {@link DataType}
*
* @param metadataType to introspect a create a {@link DataType} from it.
* @return a {@link DataType} based on the given {@link MetadataType}
*/
public static DataType toDataType(MetadataType metadataType) {
Class<?> type = getType(metadataType).orElse(null);
if (type == null) {
return DataType.fromType(Object.class);
}
Reference<DataType> dataType = new Reference<>();
metadataType.accept(new MetadataTypeVisitor() {
@Override
protected void defaultVisit(MetadataType metadataType) {
dataType.set(DataType.fromType(type));
}
@Override
public void visitArrayType(ArrayType arrayType) {
Class itemClass = getType(arrayType.getType()).get();
if (Collection.class.isAssignableFrom(type)) {
dataType.set(DataType.builder().collectionType((Class<? extends Collection>) type).itemType(itemClass).build());
} else if (Iterator.class.isAssignableFrom(type)) {
dataType.set(DataType.builder().streamType((Class<? extends Iterator>) type).itemType(itemClass).build());
} else {
defaultVisit(arrayType);
}
}
@Override
public void visitObject(ObjectType objectType) {
if (Map.class.isAssignableFrom(type)) {
dataType.set(DataType.builder().mapType((Class<? extends Map>) type).keyType(String.class).valueType(objectType.getOpenRestriction().map(restriction -> {
if (restriction.getAnnotation(TypedValueTypeAnnotation.class).isPresent()) {
return TypedValue.class;
}
return getType(restriction).get();
}).orElse(Object.class)).build());
} else {
defaultVisit(objectType);
}
}
});
return dataType.get();
}
use of org.mule.runtime.module.extension.api.loader.java.type.Type in project mule by mulesoft.
the class IntrospectionUtils method getMethodReturnAttributesType.
/**
* Returns a {@link MetadataType} representing the {@link Result#getAttributes()} that will be set after executing the given
* {@code method}.
* <p>
* If the {@code method} returns a {@link Result}, then it returns the type of the {@code Attributes} generic. In any other case
* (including raw uses of {@link Result}) it will return a {@link VoidType}
* <p>
* If the {@code method} returns a collection or a {@link PagingProvider} of {@link Result}, then this will return
* {@link VoidType} since the messages in the main output already contain an attributes for each item.
*
* @param method the {@link Method} being introspected
* @return a {@link MetadataType}
* @throws IllegalArgumentException is method is {@code null}
*/
public static MetadataType getMethodReturnAttributesType(MethodElement method) {
Type returnType = method.getReturnType();
Type attributesType = null;
if (returnType.isAssignableTo(Result.class)) {
List<TypeGeneric> generics = returnType.getGenerics();
if (generics.size() == 2) {
Type genericType = generics.get(1).getConcreteType();
if (genericType != null) {
if (genericType.isAnyType()) {
return typeBuilder().anyType().build();
} else {
attributesType = genericType;
}
} else {
return typeBuilder().anyType().build();
}
} else {
return typeBuilder().anyType().build();
}
}
if (isPagingProvider(returnType)) {
Type second = getPagingProviderTypes(returnType).getSecond();
if (second.isSameType(Result.class)) {
attributesType = null;
}
}
if (isCollection(returnType)) {
List<TypeGeneric> generics = returnType.getGenerics();
if (generics.size() > 0) {
Type genericType = generics.get(0).getConcreteType();
if (genericType.isAssignableTo(Result.class)) {
attributesType = null;
}
}
}
return attributesType != null ? attributesType.asMetadataType() : typeBuilder().voidType().build();
}
Aggregations