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);
});
}
}
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));
}
});
}
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);
}
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);
}
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());
}
Aggregations