use of org.mule.metadata.api.model.ObjectType in project mule by mulesoft.
the class ExtensionDefinitionParser method parseObjectParameter.
/**
* Registers a definition for a {@link ParameterModel} which represents an {@link ObjectType}
*
* @param key the key that the parsed value should have on the parsed parameter's map
* @param name the parameter's name
* @param type an {@link ObjectType}
* @param defaultValue the parameter's default value
* @param expressionSupport the parameter's {@link ExpressionSupport}
* @param required whether the parameter is required or not
* @param modelProperties parameter's {@link ModelProperty}s
*/
protected void parseObjectParameter(String key, String name, ObjectType type, Object defaultValue, ExpressionSupport expressionSupport, boolean required, boolean acceptsReferences, DslElementSyntax elementDsl, Set<ModelProperty> modelProperties) {
parseObject(key, name, type, defaultValue, expressionSupport, required, acceptsReferences, elementDsl, modelProperties);
final String elementNamespace = elementDsl.getPrefix();
final String elementName = elementDsl.getElementName();
if (elementDsl.supportsChildDeclaration() && !elementDsl.isWrapped() && modelProperties.stream().noneMatch(m -> m.getName().equals(InfrastructureParameterModelProperty.NAME))) {
try {
new ObjectTypeParameterParser(baseDefinitionBuilder, elementName, elementNamespace, type, getContextClassLoader(), dslResolver, parsingContext).parse().forEach(this::addDefinition);
} catch (Exception e) {
throw new MuleRuntimeException(new ConfigurationException(e));
}
}
}
use of org.mule.metadata.api.model.ObjectType in project mule by mulesoft.
the class SoapInvokeOperationDeclarer method declareRequestParameters.
/**
* Given the Invoke Operation Declarer declares the parameters for the soap request.
*
* @param operation the invoke operation declarer.
* @param loader a {@link ClassTypeLoader} to load some parameters types.
*/
private void declareRequestParameters(OperationDeclarer operation, ClassTypeLoader loader) {
ParameterGroupDeclarer message = operation.onParameterGroup(MESSAGE_GROUP).withDslInlineRepresentation(true).withLayout(getLayout(1));
MetadataType binaryType = loader.load(InputStream.class);
ObjectType attachments = TYPE_BUILDER.objectType().openWith(TYPE_BUILDER.binaryType().id(InputStream.class.getName()).with(new TypedValueTypeAnnotation())).with(new TypeIdAnnotation(Map.class.getName())).build();
message.withOptionalParameter(BODY_PARAM).ofDynamicType(binaryType).withRole(PRIMARY_CONTENT).defaultingTo(PAYLOAD).withLayout(getLayout(3)).withDisplayModel(DisplayModel.builder().summary("The XML body to include in the SOAP message, with all the required parameters.").build());
message.withOptionalParameter(HEADERS_PARAM).ofDynamicType(binaryType).withRole(CONTENT).withLayout(getLayout(4)).withDisplayModel(DisplayModel.builder().displayName(HEADERS_DISPLAY_NAME).summary("The XML headers to include in the SOAP message.").build());
message.withOptionalParameter(ATTACHMENTS_PARAM).ofDynamicType(attachments).withRole(CONTENT).withLayout(getLayout(5)).withDisplayModel(DisplayModel.builder().summary("The attachments to include in the SOAP request.").build());
operation.onParameterGroup(TRANSPORT_GROUP).withLayout(getLayout(2)).withOptionalParameter(TRANSPORT_HEADERS_PARAM).ofType(TYPE_BUILDER.objectType().openWith(loader.load(String.class)).with(new TypeIdAnnotation(Map.class.getName())).build()).withDsl(ParameterDslConfiguration.getDefaultInstance()).withLayout(LayoutModel.builder().order(2).tabName(TRANSPORT).build()).withDisplayModel(DisplayModel.builder().displayName(HEADERS_DISPLAY_NAME).summary("The headers to set in the transport configuration.").build());
}
use of org.mule.metadata.api.model.ObjectType in project mule by mulesoft.
the class ParameterModelsLoaderDelegate method parseNullSafe.
private void parseNullSafe(ExtensionParameter extensionParameter, ParameterDeclarer parameter) {
if (extensionParameter.isAnnotatedWith(NullSafe.class)) {
if (extensionParameter.isAnnotatedWith(ConfigOverride.class)) {
throw new IllegalParameterModelDefinitionException(format("Parameter '%s' is annotated with '@%s' and also marked as a config override, which is redundant. " + "The default value for this parameter will come from the configuration parameter", extensionParameter.getName(), NullSafe.class.getSimpleName()));
}
if (extensionParameter.isRequired() && !extensionParameter.isAnnotatedWith(ParameterGroup.class)) {
throw new IllegalParameterModelDefinitionException(format("Parameter '%s' is required but annotated with '@%s', which is redundant", extensionParameter.getName(), NullSafe.class.getSimpleName()));
}
Type nullSafeAnnotationType = extensionParameter.getValueFromAnnotation(NullSafe.class).get().getClassValue(NullSafe::defaultImplementingType);
final boolean hasDefaultOverride = !nullSafeAnnotationType.isSameType(Object.class);
MetadataType nullSafeType = hasDefaultOverride ? nullSafeAnnotationType.asMetadataType() : parameter.getDeclaration().getType();
boolean isInstantiable = hasDefaultOverride ? nullSafeAnnotationType.isInstantiable() : extensionParameter.getType().isInstantiable();
parameter.getDeclaration().getType().accept(new BasicTypeMetadataVisitor() {
@Override
protected void visitBasicType(MetadataType metadataType) {
throw new IllegalParameterModelDefinitionException(format("Parameter '%s' is annotated with '@%s' but is of type '%s'. That annotation can only be " + "used with complex types (Pojos, Lists, Maps)", extensionParameter.getName(), NullSafe.class.getSimpleName(), extensionParameter.getType().getName()));
}
@Override
public void visitArrayType(ArrayType arrayType) {
if (hasDefaultOverride) {
throw new IllegalParameterModelDefinitionException(format("Parameter '%s' is annotated with '@%s' is of type '%s'" + " but a 'defaultImplementingType' was provided." + " Type override is not allowed for Collections", extensionParameter.getName(), NullSafe.class.getSimpleName(), extensionParameter.getType().getName()));
}
}
@Override
public void visitObject(ObjectType objectType) {
if (hasDefaultOverride && isMap(objectType)) {
throw new IllegalParameterModelDefinitionException(format("Parameter '%s' is annotated with '@%s' is of type '%s'" + " but a 'defaultImplementingType' was provided." + " Type override is not allowed for Maps", extensionParameter.getName(), NullSafe.class.getSimpleName(), extensionParameter.getType().getName()));
}
if (hasDefaultOverride && extensionParameter.getType().isInstantiable()) {
throw new IllegalParameterModelDefinitionException(format("Parameter '%s' is annotated with '@%s' is of concrete type '%s'," + " but a 'defaultImplementingType' was provided." + " Type override is not allowed for concrete types", extensionParameter.getName(), NullSafe.class.getSimpleName(), extensionParameter.getType().getName()));
}
if (!isInstantiable && !isMap(nullSafeType)) {
throw new IllegalParameterModelDefinitionException(format("Parameter '%s' is annotated with '@%s' but is of type '%s'. That annotation can only be " + "used with complex instantiable types (Pojos, Lists, Maps)", extensionParameter.getName(), NullSafe.class.getSimpleName(), extensionParameter.getType().getName()));
}
if (hasDefaultOverride && !extensionParameter.getType().isAssignableFrom(nullSafeAnnotationType)) {
throw new IllegalParameterModelDefinitionException(format("Parameter '%s' is annotated with '@%s' of type '%s', but provided type '%s" + " is not a subtype of the parameter's type", extensionParameter.getName(), NullSafe.class.getSimpleName(), extensionParameter.getType().getName(), getType(nullSafeType).getName()));
}
}
});
parameter.withModelProperty(new NullSafeModelProperty(nullSafeType));
if (hasDefaultOverride) {
parameter.withModelProperty(new DefaultImplementingTypeModelProperty(nullSafeType));
}
}
}
use of org.mule.metadata.api.model.ObjectType in project mule by mulesoft.
the class PollingSourceDeclarationEnricher method enrich.
@Override
public void enrich(ExtensionLoadingContext extensionLoadingContext) {
ClassTypeLoader loader = ExtensionsTypeLoaderFactory.getDefault().createTypeLoader();
ExtensionDeclarer extensionDeclarer = extensionLoadingContext.getExtensionDeclarer();
Reference<Boolean> thereArePollingSources = new Reference<>(false);
new IdempotentDeclarationWalker() {
@Override
protected void onSource(SourceDeclaration source) {
extractType(source).ifPresent(type -> {
if (type.isAssignableTo(PollingSource.class)) {
source.setRunsOnPrimaryNodeOnly(true);
ParameterDeclaration parameter = new ParameterDeclaration(SCHEDULING_STRATEGY_PARAMETER_NAME);
parameter.setDescription(SCHEDULING_STRATEGY_PARAMETER_DESCRIPTION);
parameter.setRequired(true);
parameter.setType(loader.load(Scheduler.class), false);
parameter.setExpressionSupport(NOT_SUPPORTED);
parameter.addModelProperty(new InfrastructureParameterModelProperty(10));
parameter.addModelProperty(new QNameModelProperty(new QName(CORE_NAMESPACE, SCHEDULING_STRATEGY_ELEMENT_IDENTIFIER, CORE_PREFIX)));
parameter.setDslConfiguration(ParameterDslConfiguration.builder().allowsInlineDefinition(true).allowsReferences(false).allowTopLevelDefinition(false).build());
thereArePollingSources.set(true);
source.getParameterGroup(DEFAULT_GROUP_NAME).addParameter(parameter);
}
});
}
}.walk(extensionDeclarer.getDeclaration());
if (thereArePollingSources.get() && !isSchedulerAlreadyImported(extensionDeclarer.getDeclaration())) {
ClassTypeLoader typeLoader = ExtensionsTypeLoaderFactory.getDefault().createTypeLoader();
extensionDeclarer.withImportedType(new ImportedTypeModel((ObjectType) typeLoader.load(Scheduler.class)));
}
}
use of org.mule.metadata.api.model.ObjectType in project mule by mulesoft.
the class RedeliveryPolicyDeclarationEnricher method enrich.
@Override
public void enrich(ExtensionLoadingContext extensionLoadingContext) {
final Reference<Boolean> hasObjectStoreParams = new Reference<>(false);
ExtensionDeclaration extension = extensionLoadingContext.getExtensionDeclarer().getDeclaration();
new IdempotentDeclarationWalker() {
@Override
protected void onSource(SourceDeclaration declaration) {
addRedeliveryPolicy(declaration);
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)));
}
}
Aggregations