use of org.mule.runtime.api.util.Reference in project mule by mulesoft.
the class ValueProvidersParameterDeclarationEnricher method enrichParameter.
/**
* Enriches a parameter that has an associated {@link ValueProvider}
*
* @param resolverClass the class of the {@link ValueProvider}
* @param paramDeclaration {@link ParameterDeclaration} or {@link ParameterGroupDeclaration} paramDeclaration
* @param containerParameterNames parameters container's names
*/
private void enrichParameter(OfValues resolverClass, BaseDeclaration paramDeclaration, Consumer<ValueProviderModel> valueProviderModelConsumer, Integer partOrder, Map<String, String> containerParameterNames, String name) {
ValueProviderFactoryModelPropertyBuilder propertyBuilder = ValueProviderFactoryModelProperty.builder(resolverClass.value());
ParameterizableTypeWrapper resolverClassWrapper = new ParameterizableTypeWrapper(resolverClass.value(), new DefaultExtensionsTypeLoaderFactory().createTypeLoader());
List<ExtensionParameter> resolverParameters = resolverClassWrapper.getParametersAnnotatedWith(Parameter.class);
resolverParameters.forEach(param -> propertyBuilder.withInjectableParameter(param.getName(), param.getType().asMetadataType(), param.isRequired()));
Reference<Boolean> requiresConfiguration = new Reference<>(false);
Reference<Boolean> requiresConnection = new Reference<>(false);
enrichWithConnection(propertyBuilder, resolverClassWrapper).ifPresent(field -> requiresConnection.set(true));
enrichWithConfiguration(propertyBuilder, resolverClassWrapper).ifPresent(field -> requiresConfiguration.set(true));
paramDeclaration.addModelProperty(propertyBuilder.build());
valueProviderModelConsumer.accept(new ValueProviderModel(getRequiredParametersAliases(resolverParameters, containerParameterNames), requiresConfiguration.get(), requiresConnection.get(), resolverClass.open(), partOrder, name));
}
use of org.mule.runtime.api.util.Reference in project mule by mulesoft.
the class ObjectStoreParameterDeclarationEnricher method enrich.
@Override
public void enrich(ExtensionLoadingContext extensionLoadingContext) {
final ExtensionDeclaration extension = extensionLoadingContext.getExtensionDeclarer().getDeclaration();
final Reference<Boolean> hasObjectStoreParams = new Reference<>(false);
new IdempotentDeclarationWalker() {
@Override
protected void onParameter(ParameterGroupDeclaration parameterGroup, ParameterDeclaration parameter) {
if (isObjectStore(parameter.getType())) {
List<StereotypeModel> stereotypes = parameter.getAllowedStereotypeModels();
if (!stereotypes.contains(OBJECT_STORE)) {
stereotypes.add(OBJECT_STORE);
}
hasObjectStoreParams.set(true);
}
}
}.walk(extension);
if (hasObjectStoreParams.get() && !isObjectStoreAlreadyImported(extension)) {
ClassTypeLoader typeLoader = ExtensionsTypeLoaderFactory.getDefault().createTypeLoader();
extension.getImportedTypes().add(new ImportedTypeModel((ObjectType) typeLoader.load(ObjectStore.class)));
}
}
use of org.mule.runtime.api.util.Reference in project mule by mulesoft.
the class DefaultExtensionsClient method findOperation.
private OperationModel findOperation(ExtensionModel extensionModel, String operationName) {
Reference<OperationModel> operation = new Reference<>();
ExtensionWalker walker = new IdempotentExtensionWalker() {
@Override
protected void onOperation(OperationModel operationModel) {
if (operationName.equals(operationModel.getName())) {
operation.set(operationModel);
stop();
}
}
};
walker.walk(extensionModel);
if (operation.get() == null) {
throw new MuleRuntimeException(createStaticMessage("No Operation [" + operationName + "] Found"));
}
return operation.get();
}
use of org.mule.runtime.api.util.Reference 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.api.util.Reference in project mule by mulesoft.
the class MuleExtensionUtils method supportsOAuth.
/**
* Whether at least one {@link ConnectionProviderModel} in the given {@cod extensionModel} supports OAuth authentication
*
* @param extensionModel a {@link ExtensionModel}
* @return {@code true} if a {@link ConnectionProviderModel} exist which is OAuth enabled
*/
public static boolean supportsOAuth(ExtensionModel extensionModel) {
Reference<ConnectionProviderModel> connectionProvider = new Reference<>();
new IdempotentExtensionWalker() {
@Override
protected void onConnectionProvider(ConnectionProviderModel model) {
if (model.getModelProperty(OAuthModelProperty.class).isPresent()) {
connectionProvider.set(model);
stop();
}
}
}.walk(extensionModel);
return connectionProvider.get() != null;
}
Aggregations