private void extractParameter(ParameterizedDeclarer parameterizedDeclarer, ComponentModel param, ParameterRole role) { Map<String, String> parameters = param.getParameters(); String receivedInputType = parameters.get(TYPE_ATTRIBUTE); final LayoutModel.LayoutModelBuilder layoutModelBuilder = builder(); if (parseBoolean(parameters.get(PASSWORD))) { layoutModelBuilder.asPassword(); } layoutModelBuilder.order(getOrder(parameters.get(ORDER_ATTRIBUTE))); layoutModelBuilder.tabName(getTab(parameters.get(TAB_ATTRIBUTE))); final DisplayModel displayModel = getDisplayModel(param); MetadataType parameterType = extractType(receivedInputType); ParameterDeclarer parameterDeclarer = getParameterDeclarer(parameterizedDeclarer, parameters); parameterDeclarer.describedAs(getDescription(param)) .withLayout(layoutModelBuilder.build()) .withDisplayModel(displayModel) .withRole(role) .ofType(parameterType); }
/** * Declares a new connection provider for a configuration given a {@link SoapServiceProviderWrapper} declaration. * * @param configDeclarer the configuration declarer that will own the provider * @param provider a {@link SoapServiceProviderWrapper} that describes the {@link SoapServiceProvider} Type. * @param hasCustomTransports if declares custom transport or not. */ public void declare(ConfigurationDeclarer configDeclarer, SoapServiceProviderWrapper provider, boolean hasCustomTransports) { String description = provider.getDescription(); // Declares the Service Provider as a Connection Provider. ConnectionProviderDeclarer providerDeclarer = configDeclarer.withConnectionProvider(provider.getAlias()) .describedAs(description) .withModelProperty(new ConnectionTypeModelProperty(ForwardingSoapClient.class)) //TODO - MULE-14311 - Make loader work in compile time .withModelProperty(new ImplementingTypeModelProperty(provider.getDeclaringClass().get())) .withConnectionManagementType(POOLING) .supportsConnectivityTesting(provider.supportsConnectivityTesting()); ParameterDeclarationContext context = new ParameterDeclarationContext("Service Provider", providerDeclarer.getDeclaration()); parametersLoader.declare(providerDeclarer, provider.getParameters(), context); if (hasCustomTransports) { providerDeclarer.onParameterGroup(TRANSPORT_GROUP) .withRequiredParameter(TRANSPORT_PARAM) .withDisplayModel(DisplayModel.builder().displayName(TRANSPORT_GROUP).build()) .ofType(typeLoader.load(MessageDispatcherProvider.class)) .withLayout(LayoutModel.builder().order(1).tabName(TRANSPORT).build()) .withExpressionSupport(NOT_SUPPORTED); } }
/** * Given the Invoke Operation Declarer declares all the parameters that the operation has. * * @param operation the invoke operation declarer. */ private void declareMetadataKeyParameters(OperationDeclarer operation, ClassTypeLoader loader, ReflectionCache reflectionCache) { TypeWrapper keyType = new TypeWrapper(WebServiceTypeKey.class, loader); ParameterGroupDeclarer group = operation .onParameterGroup(KEYS_GROUP) .withModelProperty( new ParameterGroupModelProperty(new ParameterGroupDescriptor(KEYS_GROUP, keyType))); StringType stringType = TYPE_BUILDER.stringType().build(); group.withRequiredParameter(SERVICE_PARAM) .withModelProperty(new DeclaringMemberModelProperty(getField(WebServiceTypeKey.class, SERVICE_PARAM, reflectionCache) .get())) .ofType(stringType) .withModelProperty(new MetadataKeyPartModelProperty(1)) .withLayout(getLayout(1)); group.withRequiredParameter(OPERATION_PARAM) .ofType(stringType) .withModelProperty(new DeclaringMemberModelProperty(getField(WebServiceTypeKey.class, OPERATION_PARAM, reflectionCache) .get())) .withModelProperty(new MetadataKeyPartModelProperty(2)) .withLayout(getLayout(2)); }
void declareParameters(ComponentDeclarer component, List<ExtensionParameter> methodParameters, List<ExtensionParameter> fieldParameters, ParameterDeclarationContext declarationContext) { loader.getMethodParametersLoader().declare(component, methodParameters, declarationContext); loader.getFieldParametersLoader().declare(component, fieldParameters, declarationContext).forEach(p -> { p.withExpressionSupport(NOT_SUPPORTED); p.withModelProperty(new FieldOperationParameterModelProperty()); }); }
private void declareFlowRef(ExtensionDeclarer extensionDeclarer, ClassTypeLoader typeLoader) { OperationDeclarer flowRef = extensionDeclarer.withOperation("flowRef") .describedAs("Allows a \u0027flow\u0027 to be referenced such that the message processing will continue in the referenced flow " + "before returning. Message processing in the referenced \u0027flow\u0027 will occur within the context of the " + "referenced flow and will therefore use its exception strategy etc.") .withErrorModel(routingError); flowRef.withOutput().ofType(BaseTypeBuilder.create(JAVA).anyType().build()); flowRef.withOutputAttributes().ofType(BaseTypeBuilder.create(JAVA).anyType().build()); flowRef.onDefaultParameterGroup() .withRequiredParameter("name") .ofType(typeLoader.load(String.class)) .withExpressionSupport(NOT_SUPPORTED) .describedAs("The name of the flow to call"); }
private void declareConfigurationProperties(ExtensionDeclarer extensionDeclarer, ClassTypeLoader typeLoader) { ConstructDeclarer configuration = extensionDeclarer.withConstruct("configurationProperties") .allowingTopLevelDefinition() .withStereotype(APP_CONFIG) .describedAs("References a file with configuration properties. Each property has a key and a value. \n" + "The key can be referenced from the mule configuration files using the following semantics: \n" + "${key_name}. This allows to externalize configuration and change it based\n" + "on the environment the application is being deployed to."); configuration.onDefaultParameterGroup() .withRequiredParameter("file") .ofType(typeLoader.load(String.class)) .withExpressionSupport(NOT_SUPPORTED) .withDisplayModel(DisplayModel.builder().path(new PathModel(FILE, false, EMBEDDED, new String[] {"properties"})).build()) .describedAs(" The location of the file with the configuration properties to use. " + "It may be a location in the classpath or an absolute location. The file location\n" + " value may also contains references to properties that will only be resolved based on " + "system properties or properties set at deployment time."); }
parameter.ofType(extensionParameter.getType().asMetadataType()).describedAs(extensionParameter.getDescription()); parseParameterRole(extensionParameter, parameter); parseExpressionSupport(extensionParameter, parameter); parseLayout(extensionParameter, parameter); parseExclusiveOptional(extensionParameter, groupDeclarer, parameter); parameter.withModelProperty(new ExtensionParameterDescriptorModelProperty(extensionParameter)); extensionParameter.getDeclaringElement().ifPresent(element -> addImplementingTypeModelProperty(element, parameter)); parseParameterDsl(extensionParameter, parameter);
.describedAs("Spring configuration that allows to define a set of spring XML files and create an application context with objects to be used in the mule artifact."); ParameterGroupDeclarer parameterGroupDeclarer = springConfig.onDefaultParameterGroup(); parameterGroupDeclarer.withRequiredParameter("files").withExpressionSupport(NOT_SUPPORTED) .withRole(BEHAVIOUR).ofType(typeLoader.load(String.class)); securityManager.onDefaultParameterGroup().withRequiredParameter("providers").withExpressionSupport(NOT_SUPPORTED) .withRole(BEHAVIOUR).ofType(typeBuilder.arrayType().of(typeLoader.load(SecurityProvider.class)).build()); authorizationFilter.withOutputAttributes().ofType(typeBuilder.voidType().build()); authorizationFilter.onDefaultParameterGroup().withRequiredParameter("requiredAuthorities") .withExpressionSupport(NOT_SUPPORTED) .withRole(BEHAVIOUR).ofType(typeLoader.load(String.class));
/** * Contributes to a {@link ParameterDeclarer} if the type of the given parameter is one of the registered * as {@link StackableType wrapper types} * * @param parameter {@link ExtensionParameter} with introspected information of the Java parameter * @param declarer declarer to be enriched * @param declarationContext context of the parameter to be declared */ @Override public void contribute(ExtensionParameter parameter, ParameterDeclarer declarer, ParameterDeclarationContext declarationContext) { LazyValue<StackedTypesModelProperty.Builder> stackedTypesModelPropertyBuilder = new LazyValue<>(StackedTypesModelProperty::builder); doContribute(parameter, declarationContext, parameter.getType(), stackedTypesModelPropertyBuilder); declarer.ofType(parameter.getType().asMetadataType()); stackedTypesModelPropertyBuilder.ifComputed(builder -> declarer.withModelProperty(builder.build())); }
private void declareScheduler(ExtensionDeclarer extensionDeclarer, ClassTypeLoader typeLoader) { SourceDeclarer scheduler = extensionDeclarer.withMessageSource("scheduler") .hasResponse(false) .describedAs("Source that schedules periodic execution of a flow."); scheduler.withOutput().ofType(typeLoader.load(Object.class)); scheduler.withOutputAttributes().ofType(typeLoader.load(Object.class)); MetadataType baseSchedulingStrategy = typeLoader.load(Scheduler.class); scheduler.onDefaultParameterGroup() .withRequiredParameter("schedulingStrategy") .ofType(baseSchedulingStrategy) .withExpressionSupport(NOT_SUPPORTED); MetadataType fixedFrequencyScheduler = typeLoader.load(FixedFrequencyScheduler.class); MetadataType cronScheduler = typeLoader.load(CronScheduler.class); extensionDeclarer.withSubType(baseSchedulingStrategy, fixedFrequencyScheduler); extensionDeclarer.withSubType(baseSchedulingStrategy, cronScheduler); // workaround for an "org.mule.runtime" package and still export the type in the extension model extensionDeclarer.getDeclaration().addType((ObjectType) baseSchedulingStrategy); extensionDeclarer.getDeclaration().addType((ObjectType) fixedFrequencyScheduler); extensionDeclarer.getDeclaration().addType((ObjectType) cronScheduler); }
private void declareChoice(ExtensionDeclarer extensionDeclarer, ClassTypeLoader typeLoader) { ConstructDeclarer choice = extensionDeclarer.withConstruct("choice") .describedAs("Sends the message to the first message processor whose condition has been satisfied. " + "If no conditions were satisfied, sends to the configured default message processor if configured, " + "or throws an exception if not configured.") .withErrorModel(routingError); NestedRouteDeclarer when = choice.withRoute("when").withMinOccurs(1); when.withChain(); when.onDefaultParameterGroup() .withRequiredParameter("expression") .ofType(typeLoader.load(boolean.class)) .describedAs("The expression to evaluate."); choice.withRoute("otherwise").withMaxOccurs(1).withChain(); }
@Override public void accept(ExtensionDeclarer extensionDeclarer, ExtensionLoadingContext context) { ConfigurationDeclarer configurationDeclarer = extensionDeclarer.named(EXTENSION_NAME) .describedAs("Crafted Config Properties Extension") .onVersion("1.0.0") .withCategory(COMMUNITY) .fromVendor("Mulesoft") .withConfig("secure-configuration-properties"); ParameterGroupDeclarer defaultParameterGroup = configurationDeclarer.onDefaultParameterGroup(); defaultParameterGroup .withRequiredParameter("file").ofType(BaseTypeBuilder.create(JAVA).stringType().build()); ParameterGroupDeclarer parameterGroupDeclarer = configurationDeclarer.onParameterGroup("encrypt").withDslInlineRepresentation(true); parameterGroupDeclarer.withRequiredParameter("algorithm").ofType(BaseTypeBuilder.create(JAVA).stringType().build()); parameterGroupDeclarer.withRequiredParameter("mode").ofType(BaseTypeBuilder.create(JAVA).stringType().build()); } }
private void parseExpressionSupport(ExtensionParameter extensionParameter, ParameterDeclarer parameter) { extensionParameter.getAnnotation(Expression.class) .ifPresent(expression -> parameter.withExpressionSupport(getExpressionSupport(expression))); }
private void parseParameterRole(ExtensionParameter extensionParameter, ParameterDeclarer parameter) { parameter.withRole(roleOf(extensionParameter.getAnnotation(Content.class))); }
hasDefaultOverride ? nullSafeAnnotationType.asMetadataType() : parameter.getDeclaration().getType(); parameter.getDeclaration().getType().accept(new BasicTypeMetadataVisitor() { parameter.withModelProperty(new NullSafeModelProperty(nullSafeType)); if (hasDefaultOverride) { parameter.withModelProperty(new DefaultImplementingTypeModelProperty(nullSafeType));
private void addImplementingTypeModelProperty(AnnotatedElement element, ParameterDeclarer parameter) { parameter.withModelProperty(element instanceof Field ? new DeclaringMemberModelProperty(((Field) element)) : new ImplementingParameterModelProperty((java.lang.reflect.Parameter) element)); }
private void declareRaiseError(ExtensionDeclarer extensionDeclarer, ClassTypeLoader typeLoader) { OperationDeclarer raiseError = extensionDeclarer.withOperation("raiseError") .describedAs("Throws an error with the specified type and description."); raiseError.withOutput().ofType(typeLoader.load(void.class)); raiseError.withOutputAttributes().ofType(typeLoader.load(void.class)); raiseError.onDefaultParameterGroup() .withRequiredParameter("type") .ofType(typeLoader.load(String.class)) .withExpressionSupport(NOT_SUPPORTED) .describedAs("The error type to raise."); raiseError.onDefaultParameterGroup() .withOptionalParameter("description") .ofType(typeLoader.load(String.class)) .describedAs("The description of this error."); }
parameter.ofType(extensionParameter.getType().asMetadataType()).describedAs(extensionParameter.getDescription()); parseParameterRole(extensionParameter, parameter); parseExpressionSupport(extensionParameter, parameter); parseLayout(extensionParameter, parameter); parseExclusiveOptional(extensionParameter, groupDeclarer, parameter); parameter.withModelProperty(new ExtensionParameterDescriptorModelProperty(extensionParameter)); extensionParameter.getDeclaringElement().ifPresent(element -> addImplementingTypeModelProperty(element, parameter)); parseParameterDsl(extensionParameter, parameter);
/** * {@inheritDoc} */ @Override public void contribute(ExtensionParameter parameter, ParameterDeclarer declarer, ParameterDeclarationContext declarationContext) { getInfrastructureType(parameter.getType()).ifPresent(infrastructureType -> { if (!isBlank(infrastructureType.getName())) { declarer.withModelProperty(new InfrastructureParameterModelProperty(infrastructureType.getSequence())); declarer.withExpressionSupport(NOT_SUPPORTED); getQName(infrastructureType.getName()).ifPresent(declarer::withModelProperty); getDslConfiguration(infrastructureType.getName()).ifPresent(declarer::withDsl); } }); } }
/** * Contributes to a {@link ParameterDeclarer} if the type of the given parameter is one of the registered * as {@link StackableType wrapper types} * * @param parameter {@link ExtensionParameter} with introspected information of the Java parameter * @param declarer declarer to be enriched * @param declarationContext context of the parameter to be declared */ @Override public void contribute(ExtensionParameter parameter, ParameterDeclarer declarer, ParameterDeclarationContext declarationContext) { LazyValue<StackedTypesModelProperty.Builder> stackedTypesModelPropertyBuilder = new LazyValue<>(StackedTypesModelProperty::builder); doContribute(parameter, declarationContext, parameter.getType(), stackedTypesModelPropertyBuilder); declarer.ofType(parameter.getType().asMetadataType()); stackedTypesModelPropertyBuilder.ifComputed(builder -> declarer.withModelProperty(builder.build())); }