Search in sources :

Example 1 with ReflectionCache

use of org.mule.runtime.module.extension.internal.util.ReflectionCache in project mule by mulesoft.

the class DefaultExtensionBuildingDefinitionProvider method registerExtensionParsers.

private void registerExtensionParsers(ExtensionModel extensionModel) {
    XmlDslModel xmlDslModel = extensionModel.getXmlDslModel();
    final ExtensionParsingContext parsingContext = createParsingContext(extensionModel);
    final Builder definitionBuilder = new Builder().withNamespace(xmlDslModel.getPrefix());
    final DslSyntaxResolver dslSyntaxResolver = DslSyntaxResolver.getDefault(extensionModel, DslResolvingContext.getDefault(extensions));
    if (extensionModel.getModelProperty(CustomBuildingDefinitionProviderModelProperty.class).isPresent()) {
        return;
    }
    if (extensionModel.getModelProperty(XmlExtensionModelProperty.class).isPresent()) {
        registerXmlExtensionParsers(definitionBuilder, extensionModel, dslSyntaxResolver);
    } else {
        final ClassLoader extensionClassLoader = getClassLoader(extensionModel);
        withContextClassLoader(extensionClassLoader, () -> {
            ReflectionCache reflectionCache = new ReflectionCache();
            new IdempotentExtensionWalker() {

                @Override
                public void onConfiguration(ConfigurationModel model) {
                    parseWith(new ConfigurationDefinitionParser(definitionBuilder, extensionModel, model, dslSyntaxResolver, parsingContext));
                }

                @Override
                protected void onConstruct(ConstructModel model) {
                    parseWith(new ConstructDefinitionParser(definitionBuilder, extensionModel, model, dslSyntaxResolver, parsingContext));
                }

                @Override
                public void onOperation(OperationModel model) {
                    parseWith(new OperationDefinitionParser(definitionBuilder, extensionModel, model, dslSyntaxResolver, parsingContext));
                }

                @Override
                public void onConnectionProvider(ConnectionProviderModel model) {
                    parseWith(new ConnectionProviderDefinitionParser(definitionBuilder, model, extensionModel, dslSyntaxResolver, parsingContext));
                }

                @Override
                public void onSource(SourceModel model) {
                    parseWith(new SourceDefinitionParser(definitionBuilder, extensionModel, model, dslSyntaxResolver, parsingContext));
                }

                @Override
                protected void onParameter(ParameterGroupModel groupModel, ParameterModel model) {
                    registerTopLevelParameter(model.getType(), definitionBuilder, extensionClassLoader, dslSyntaxResolver, parsingContext, reflectionCache);
                }
            }.walk(extensionModel);
            registerExportedTypesTopLevelParsers(extensionModel, definitionBuilder, extensionClassLoader, dslSyntaxResolver, parsingContext, reflectionCache);
            registerSubTypes(definitionBuilder, extensionClassLoader, dslSyntaxResolver, parsingContext, reflectionCache);
        });
    }
}
Also used : ConfigurationModel(org.mule.runtime.api.meta.model.config.ConfigurationModel) ReflectionCache(org.mule.runtime.module.extension.internal.util.ReflectionCache) Builder(org.mule.runtime.dsl.api.component.ComponentBuildingDefinition.Builder) ModuleOperationMessageProcessorChainBuilder(org.mule.runtime.core.internal.processor.chain.ModuleOperationMessageProcessorChainBuilder) DslSyntaxResolver(org.mule.runtime.extension.api.dsl.syntax.resolver.DslSyntaxResolver) CustomBuildingDefinitionProviderModelProperty(org.mule.runtime.core.internal.extension.CustomBuildingDefinitionProviderModelProperty) ConnectionProviderDefinitionParser(org.mule.runtime.module.extension.internal.config.dsl.connection.ConnectionProviderDefinitionParser) SourceModel(org.mule.runtime.api.meta.model.source.SourceModel) ConstructModel(org.mule.runtime.api.meta.model.construct.ConstructModel) XmlExtensionModelProperty(org.mule.runtime.extension.api.property.XmlExtensionModelProperty) ConstructDefinitionParser(org.mule.runtime.module.extension.internal.config.dsl.construct.ConstructDefinitionParser) ParameterModel(org.mule.runtime.api.meta.model.parameter.ParameterModel) SourceDefinitionParser(org.mule.runtime.module.extension.internal.config.dsl.source.SourceDefinitionParser) ParameterGroupModel(org.mule.runtime.api.meta.model.parameter.ParameterGroupModel) XmlDslModel(org.mule.runtime.api.meta.model.XmlDslModel) MuleExtensionUtils.getClassLoader(org.mule.runtime.module.extension.internal.util.MuleExtensionUtils.getClassLoader) ClassUtils.withContextClassLoader(org.mule.runtime.core.api.util.ClassUtils.withContextClassLoader) ConfigurationDefinitionParser(org.mule.runtime.module.extension.internal.config.dsl.config.ConfigurationDefinitionParser) IdempotentExtensionWalker(org.mule.runtime.api.meta.model.util.IdempotentExtensionWalker) ConnectionProviderModel(org.mule.runtime.api.meta.model.connection.ConnectionProviderModel) OperationModel(org.mule.runtime.api.meta.model.operation.OperationModel) OperationDefinitionParser(org.mule.runtime.module.extension.internal.config.dsl.operation.OperationDefinitionParser)

Example 2 with ReflectionCache

use of org.mule.runtime.module.extension.internal.util.ReflectionCache in project mule by mulesoft.

the class DefaultExtensionBuildingDefinitionProvider method registerTopLevelParameter.

private void registerTopLevelParameter(final MetadataType parameterType, Builder definitionBuilder, ClassLoader extensionClassLoader, DslSyntaxResolver dslSyntaxResolver, ExtensionParsingContext parsingContext, ReflectionCache reflectionCache) {
    Optional<DslElementSyntax> dslElement = dslSyntaxResolver.resolve(parameterType);
    if (!dslElement.isPresent() || parsingContext.isRegistered(dslElement.get().getElementName(), dslElement.get().getPrefix()) || !IntrospectionUtils.isInstantiable(parameterType, reflectionCache)) {
        return;
    }
    parameterType.accept(new MetadataTypeVisitor() {

        @Override
        public void visitObject(ObjectType objectType) {
            DslElementSyntax pojoDsl = dslElement.get();
            if (pojoDsl.supportsTopLevelDeclaration() || (pojoDsl.supportsChildDeclaration() && pojoDsl.isWrapped()) || getSubstitutionGroup(objectType).isPresent() || parsingContext.getAllSubTypes().contains(objectType)) {
                parseWith(new ObjectTypeParameterParser(definitionBuilder, objectType, extensionClassLoader, dslSyntaxResolver, parsingContext));
            }
            registerSubTypes(objectType, definitionBuilder, extensionClassLoader, dslSyntaxResolver, parsingContext, reflectionCache);
        }

        @Override
        public void visitArrayType(ArrayType arrayType) {
            registerTopLevelParameter(arrayType.getType(), definitionBuilder, extensionClassLoader, dslSyntaxResolver, parsingContext, reflectionCache);
        }

        @Override
        public void visitUnion(UnionType unionType) {
            unionType.getTypes().forEach(type -> type.accept(this));
        }
    });
}
Also used : ArrayType(org.mule.metadata.api.model.ArrayType) OperationModel(org.mule.runtime.api.meta.model.operation.OperationModel) ComponentBuildingDefinitionProvider(org.mule.runtime.dsl.api.component.ComponentBuildingDefinitionProvider) IntrospectionUtils(org.mule.runtime.module.extension.internal.util.IntrospectionUtils) SourceModel(org.mule.runtime.api.meta.model.source.SourceModel) ArrayType(org.mule.metadata.api.model.ArrayType) DslResolvingContext(org.mule.runtime.api.dsl.DslResolvingContext) UnionType(org.mule.metadata.api.model.UnionType) ParameterGroupModel(org.mule.runtime.api.meta.model.parameter.ParameterGroupModel) Preconditions.checkState(org.mule.runtime.api.util.Preconditions.checkState) ConstructModel(org.mule.runtime.api.meta.model.construct.ConstructModel) IdempotentExtensionWalker(org.mule.runtime.api.meta.model.util.IdempotentExtensionWalker) OperationDefinitionParser(org.mule.runtime.module.extension.internal.config.dsl.operation.OperationDefinitionParser) ObjectType(org.mule.metadata.api.model.ObjectType) ConstructDefinitionParser(org.mule.runtime.module.extension.internal.config.dsl.construct.ConstructDefinitionParser) ConfigurationDefinitionParser(org.mule.runtime.module.extension.internal.config.dsl.config.ConfigurationDefinitionParser) Set(java.util.Set) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) ReflectionCache(org.mule.runtime.module.extension.internal.util.ReflectionCache) MetadataTypeVisitor(org.mule.metadata.api.visitor.MetadataTypeVisitor) ExtensionMetadataTypeUtils.getSubstitutionGroup(org.mule.runtime.extension.api.util.ExtensionMetadataTypeUtils.getSubstitutionGroup) ComponentBuildingDefinition(org.mule.runtime.dsl.api.component.ComponentBuildingDefinition) List(java.util.List) Stream(java.util.stream.Stream) DslElementSyntax(org.mule.runtime.extension.api.dsl.syntax.DslElementSyntax) SourceDefinitionParser(org.mule.runtime.module.extension.internal.config.dsl.source.SourceDefinitionParser) XmlDslModel(org.mule.runtime.api.meta.model.XmlDslModel) MetadataType(org.mule.metadata.api.model.MetadataType) DslSyntaxResolver(org.mule.runtime.extension.api.dsl.syntax.resolver.DslSyntaxResolver) Optional(java.util.Optional) Builder(org.mule.runtime.dsl.api.component.ComponentBuildingDefinition.Builder) ConnectionProviderDefinitionParser(org.mule.runtime.module.extension.internal.config.dsl.connection.ConnectionProviderDefinitionParser) ParameterModel(org.mule.runtime.api.meta.model.parameter.ParameterModel) ConnectionProviderModel(org.mule.runtime.api.meta.model.connection.ConnectionProviderModel) MuleExtensionUtils.getClassLoader(org.mule.runtime.module.extension.internal.util.MuleExtensionUtils.getClassLoader) ComponentLocationVisitor(org.mule.runtime.config.internal.dsl.model.ComponentLocationVisitor) ObjectTypeParameterParser(org.mule.runtime.module.extension.internal.config.dsl.parameter.ObjectTypeParameterParser) CustomBuildingDefinitionProviderModelProperty(org.mule.runtime.core.internal.extension.CustomBuildingDefinitionProviderModelProperty) ImmutableList(com.google.common.collect.ImmutableList) ExtensionBuildingDefinitionProvider(org.mule.runtime.module.extension.internal.config.ExtensionBuildingDefinitionProvider) ClassUtils.withContextClassLoader(org.mule.runtime.core.api.util.ClassUtils.withContextClassLoader) LinkedList(java.util.LinkedList) ModuleOperationMessageProcessorChainBuilder(org.mule.runtime.core.internal.processor.chain.ModuleOperationMessageProcessorChainBuilder) TypeDefinition.fromType(org.mule.runtime.dsl.api.component.TypeDefinition.fromType) ConfigurationException(org.mule.runtime.core.api.config.ConfigurationException) XmlExtensionModelProperty(org.mule.runtime.extension.api.property.XmlExtensionModelProperty) ConfigurationModel(org.mule.runtime.api.meta.model.config.ConfigurationModel) ExtensionModel(org.mule.runtime.api.meta.model.ExtensionModel) ExtensionManager(org.mule.runtime.core.api.extension.ExtensionManager) ComponentModel(org.mule.runtime.config.internal.model.ComponentModel) ObjectType(org.mule.metadata.api.model.ObjectType) ObjectTypeParameterParser(org.mule.runtime.module.extension.internal.config.dsl.parameter.ObjectTypeParameterParser) UnionType(org.mule.metadata.api.model.UnionType) DslElementSyntax(org.mule.runtime.extension.api.dsl.syntax.DslElementSyntax) MetadataTypeVisitor(org.mule.metadata.api.visitor.MetadataTypeVisitor)

Example 3 with ReflectionCache

use of org.mule.runtime.module.extension.internal.util.ReflectionCache in project mule by mulesoft.

the class SoapInvokeOperationDeclarer method declare.

/**
 * Declares the invoke operation.
 *
 * @param configDeclarer the soap config declarer
 * @param loader         a {@link ClassTypeLoader} to load some parameters types.
 * @param soapErrors     the {@link ErrorModel}s that this operation can throw.
 */
void declare(ConfigurationDeclarer configDeclarer, ClassTypeLoader loader, Set<ErrorModel> soapErrors) {
    ReflectionCache reflectionCache = new ReflectionCache();
    OperationDeclarer operation = configDeclarer.withOperation(OPERATION_NAME).describedAs(OPERATION_DESCRIPTION).requiresConnection(true).blocking(true).withModelProperty(new ComponentExecutorModelProperty(new SoapOperationExecutorFactory())).withModelProperty(new ConnectivityModelProperty(ForwardingSoapClient.class));
    soapErrors.forEach(operation::withErrorModel);
    declareMetadata(operation, loader);
    declareOutput(operation, loader);
    declareMetadataKeyParameters(operation, loader, reflectionCache);
    declareRequestParameters(operation, loader);
}
Also used : ConnectivityModelProperty(org.mule.runtime.module.extension.internal.loader.java.property.ConnectivityModelProperty) ForwardingSoapClient(org.mule.runtime.module.extension.soap.internal.runtime.connection.ForwardingSoapClient) ReflectionCache(org.mule.runtime.module.extension.internal.util.ReflectionCache) OperationDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.OperationDeclarer) SoapOperationExecutorFactory(org.mule.runtime.module.extension.soap.internal.runtime.operation.SoapOperationExecutorFactory) ComponentExecutorModelProperty(org.mule.runtime.module.extension.api.loader.java.property.ComponentExecutorModelProperty)

Example 4 with ReflectionCache

use of org.mule.runtime.module.extension.internal.util.ReflectionCache in project mule by mulesoft.

the class CraftedExtensionModelLoader method declareExtension.

@Override
protected void declareExtension(ExtensionLoadingContext context) {
    Class<?> delegateType = getDelegateType(context, context.getExtensionClassLoader());
    if (!ExtensionLoadingDelegate.class.isAssignableFrom(delegateType)) {
        throw new IllegalArgumentException(format("Property '%s' was expected to point to an implementation of the '%s', but '%s' was found instead", TYPE_PROPERTY_NAME, ExtensionLoadingDelegate.class.getName(), delegateType.getClass().getName()));
    }
    if (!isInstantiable(delegateType, new ReflectionCache())) {
        throw new IllegalArgumentException(format("Type '%s' is not instantiable. A concrete class with a public default constructor was expected", delegateType.getName()));
    }
    ExtensionLoadingDelegate delegate;
    try {
        delegate = (ExtensionLoadingDelegate) ClassUtils.instantiateClass(delegateType);
    } catch (Throwable e) {
        throw new MuleRuntimeException(createStaticMessage(format("Could not instantiate type '%s'", delegateType.getName())), e);
    }
    delegate.accept(context.getExtensionDeclarer(), context);
}
Also used : ReflectionCache(org.mule.runtime.module.extension.internal.util.ReflectionCache) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) ExtensionLoadingDelegate(org.mule.runtime.extension.api.loader.ExtensionLoadingDelegate)

Example 5 with ReflectionCache

use of org.mule.runtime.module.extension.internal.util.ReflectionCache in project mule by mulesoft.

the class JavaSubtypesModelValidator method validate.

@Override
public void validate(ExtensionModel model, ProblemsReporter problemsReporter) {
    final Map<ObjectType, Set<ObjectType>> typesMapping = toSubTypesMap(model.getSubTypes());
    validateNonAbstractSubtypes(model, typesMapping, problemsReporter, new ReflectionCache());
}
Also used : ObjectType(org.mule.metadata.api.model.ObjectType) Set(java.util.Set) ReflectionCache(org.mule.runtime.module.extension.internal.util.ReflectionCache)

Aggregations

ReflectionCache (org.mule.runtime.module.extension.internal.util.ReflectionCache)13 String.format (java.lang.String.format)5 MetadataType (org.mule.metadata.api.model.MetadataType)5 ObjectType (org.mule.metadata.api.model.ObjectType)5 Optional (java.util.Optional)4 ArrayType (org.mule.metadata.api.model.ArrayType)4 MetadataTypeVisitor (org.mule.metadata.api.visitor.MetadataTypeVisitor)4 OperationModel (org.mule.runtime.api.meta.model.operation.OperationModel)4 ParameterGroupModel (org.mule.runtime.api.meta.model.parameter.ParameterGroupModel)4 ParameterModel (org.mule.runtime.api.meta.model.parameter.ParameterModel)4 SourceModel (org.mule.runtime.api.meta.model.source.SourceModel)4 IdempotentExtensionWalker (org.mule.runtime.api.meta.model.util.IdempotentExtensionWalker)4 Set (java.util.Set)3 Collectors.joining (java.util.stream.Collectors.joining)3 StringUtils.isBlank (org.apache.commons.lang3.StringUtils.isBlank)3 Before (org.junit.Before)3 ExtensionModel (org.mule.runtime.api.meta.model.ExtensionModel)3 ExtensionModelValidator (org.mule.runtime.extension.api.loader.ExtensionModelValidator)3 Problem (org.mule.runtime.extension.api.loader.Problem)3 ProblemsReporter (org.mule.runtime.extension.api.loader.ProblemsReporter)3