@Override public MetadataType getOutputType(MetadataContext context, Object key) { return BaseTypeBuilder.create(JAVA).stringType().build(); }
private void addBackPressureParameter(ExtensionDeclaration extensionDeclaration, SourceDeclaration sourceDeclaration, BackPressureStrategyModelProperty property) { ParameterDeclaration parameter = new ParameterDeclaration(BACK_PRESSURE_STRATEGY_PARAMETER_NAME); parameter.setDescription(BACK_PRESSURE_STRATEGY_PARAMETER_DESCRIPTION); parameter.setRequired(false); parameter.setDefaultValue(property.getDefaultMode()); parameter.setExpressionSupport(NOT_SUPPORTED); parameter.setLayoutModel(LayoutModel.builder().tabName(ADVANCED_TAB).build()); MetadataType type = BaseTypeBuilder.create(JAVA).stringType() .id(format("%s-%s-backPressureStrategy", extensionDeclaration.getName(), sourceDeclaration.getName())) .with(new EnumAnnotation<>(property.getSupportedModes().stream().map(BackPressureMode::name).toArray(String[]::new))) .build(); parameter.setType(type, false); sourceDeclaration.getParameterGroup(DEFAULT_GROUP_NAME).addParameter(parameter); }
private void declareTry(ExtensionDeclarer extensionDeclarer, ClassTypeLoader typeLoader) { ConstructDeclarer tryScope = extensionDeclarer.withConstruct("try") .describedAs("Processes the nested list of message processors, " + "within a transaction and with it's own error handler if required."); tryScope.onDefaultParameterGroup() .withOptionalParameter("transactionalAction") .ofType(BaseTypeBuilder.create(JAVA).stringType() .enumOf("INDIFFERENT", "ALWAYS_BEGIN", "BEGIN_OR_JOIN").build()) .defaultingTo("INDIFFERENT") .withExpressionSupport(NOT_SUPPORTED) .withLayout(LayoutModel.builder().tabName("Transactions").build()) .describedAs("The action to take regarding transactions. By default nothing will be done."); tryScope.onDefaultParameterGroup() .withOptionalParameter("transactionType") .ofType(BaseTypeBuilder.create(JAVA).stringType().enumOf("LOCAL", "XA").build()) .defaultingTo("LOCAL") .withExpressionSupport(NOT_SUPPORTED) .describedAs("Transaction type supported. Availability will depend on the runtime version, " + "though LOCAL is always available."); tryScope.withChain(); tryScope.withOptionalComponent("errorHandler") .withAllowedStereotypes(ERROR_HANDLER); }
public StringTypeBuilder boundary(Number minLength, Number maxLength) { return with(new LengthAnnotation(minLength, maxLength)); }
@Override public TypeBuilder<?> handleClass(Class<?> clazz, List<Type> genericTypes, TypeHandlerManager typeHandlerManager, ParsingContext context, BaseTypeBuilder<?> typeBuilder) { final StringTypeBuilder<?> enumType = typeBuilder.stringType(); enumType.id(clazz.getCanonicalName()); final Object[] enumConstants = clazz.getEnumConstants(); final String[] enumOf = new String[enumConstants.length]; for (int i = 0; i < enumConstants.length; i++) { final Object enumConstant = enumConstants[i]; enumOf[i] = String.valueOf(enumConstant); } enumType.enumOf(enumOf); return enumType; } }
@Override public TypeBuilder<?> handleClass(Class<?> clazz, List<Type> genericTypes, TypeHandlerManager typeHandlerManager, ParsingContext context, BaseTypeBuilder<?> typeBuilder) { final StringTypeBuilder<?> stringType = typeBuilder.stringType(); if (clazz.getCanonicalName() != null) { stringType.id(clazz.getCanonicalName()); } return stringType; } }
@Override public TypeBuilder<?> handle(Schema schema, BaseTypeBuilder root, HandlerManager handlerManager, ParsingContext parsingContext) { final EnumSchema enumSchema = (EnumSchema) schema; final StringTypeBuilder enumMetadataBuilder = root.stringType(); final Set<Object> possibleValues = enumSchema.getPossibleValues(); final String[] stringValues = possibleValues.stream().map((v) -> String.valueOf(v)).toArray(String[]::new); enumMetadataBuilder.enumOf(stringValues); return enumMetadataBuilder; } }
private void declareFlow(ExtensionDeclarer extensionDeclarer, ClassTypeLoader typeLoader) { ConstructDeclarer flow = extensionDeclarer.withConstruct(FLOW_ELEMENT_IDENTIFIER) .allowingTopLevelDefinition() .withStereotype(FLOW); flow.onDefaultParameterGroup().withOptionalParameter("initialState").defaultingTo("started") .ofType(BaseTypeBuilder.create(JAVA).stringType().enumOf("started", "stopped").build()); flow.onDefaultParameterGroup().withOptionalParameter("maxConcurrency") .ofType(typeLoader.load(Integer.class)); flow.withComponent("source") .withAllowedStereotypes(MuleStereotypes.SOURCE); flow.withChain().setRequired(true); flow.withComponent("errorHandler") .withAllowedStereotypes(ERROR_HANDLER); }
public StringTypeBuilder length(Integer length) { return with(new LengthAnnotation(length, length)); } }
@Override public TypeBuilder<?> handleClass(Class<?> clazz, List<Type> genericTypes, TypeHandlerManager typeHandlerManager, ParsingContext context, BaseTypeBuilder typeBuilder) { final StringTypeBuilder enumType = typeBuilder.stringType(); enumType.id(clazz.getCanonicalName()); final Object[] enumConstants = clazz.getEnumConstants(); final String[] enumOf = new String[enumConstants.length]; for (int i = 0; i < enumConstants.length; i++) { final Enum enumConstant = (Enum) enumConstants[i]; enumOf[i] = enumConstant.name(); } enumType.enumOf(enumOf); return enumType; } }
@Override public MetadataType getInputMetadata(MetadataContext context, Object key) { if (key instanceof NullMetadataKey) { return BaseTypeBuilder.create(JAVA).voidType().build(); } return BaseTypeBuilder.create(JAVA).stringType().build(); }
private void declareLogger(ExtensionDeclarer extensionDeclarer, ClassTypeLoader typeLoader) { OperationDeclarer logger = extensionDeclarer.withOperation("logger") .describedAs("Performs logging using an expression that determines what should be logged. By default the current messages is logged " + "using the DEBUG level to the \u0027org.mule.runtime.core.api.processor.LoggerMessageProcessor\u0027 category but " + "the level and category can both be configured to suit your needs. message is specified then the current message is used."); logger.withOutput().ofType(typeLoader.load(void.class)); logger.withOutputAttributes().ofType(typeLoader.load(void.class)); logger.onDefaultParameterGroup() .withOptionalParameter("message") .ofType(typeLoader.load(String.class)) .describedAs("Message that will be logged. Embedded expressions can be used to extract value from the current message. " + "If no message is specified then the current message is used."); logger.onDefaultParameterGroup() .withOptionalParameter("level") .defaultingTo("DEBUG") .ofType(BaseTypeBuilder.create(JAVA).stringType() .enumOf("ERROR", "WARN", "INFO", "DEBUG", "TRACE").build()) .withExpressionSupport(NOT_SUPPORTED) .describedAs("The logging level to be used. Default is DEBUG."); logger.onDefaultParameterGroup() .withOptionalParameter("category") .ofType(typeLoader.load(String.class)) .withExpressionSupport(NOT_SUPPORTED) .describedAs("The log category to be used"); }
public StringTypeBuilder id(String typeIdentifier) { return with(new TypeIdAnnotation(typeIdentifier)); }
@Override public void visitString(StringType stringType) { if (property == null || stringType.getAnnotation(EnumAnnotation.class).isPresent()) { return; } if (!property.isStrict()) { declareOutputMimeTypeParameter(declaration.getParameterGroup(DEFAULT_GROUP_NAME)); } replaceOutputType(declaration, property, format -> { StringTypeBuilder stringTypeBuilder = BaseTypeBuilder.create(format).stringType(); enrichWithAnnotations(stringTypeBuilder, declaration.getOutput().getType().getAnnotations()); return stringTypeBuilder.build(); }); }
private void addBackPressureParameter(ExtensionDeclaration extensionDeclaration, SourceDeclaration sourceDeclaration, BackPressureStrategyModelProperty property) { ParameterDeclaration parameter = new ParameterDeclaration(BACK_PRESSURE_STRATEGY_PARAMETER_NAME); parameter.setDescription(BACK_PRESSURE_STRATEGY_PARAMETER_DESCRIPTION); parameter.setRequired(false); parameter.setDefaultValue(property.getDefaultMode()); parameter.setExpressionSupport(NOT_SUPPORTED); parameter.setLayoutModel(LayoutModel.builder().tabName(ADVANCED_TAB).build()); MetadataType type = BaseTypeBuilder.create(JAVA).stringType() .id(format("%s-%s-backPressureStrategy", extensionDeclaration.getName(), sourceDeclaration.getName())) .with(new EnumAnnotation<>(property.getSupportedModes().stream().map(BackPressureMode::name).toArray(String[]::new))) .build(); parameter.setType(type, false); sourceDeclaration.getParameterGroup(DEFAULT_GROUP_NAME).addParameter(parameter); }
private void declareOnErrorRoute(ClassTypeLoader typeLoader, NestedRouteDeclarer onError) { onError.withChain(); onError.onDefaultParameterGroup() .withOptionalParameter("when") .ofType(typeLoader.load(String.class)) .describedAs("The expression that will be evaluated to determine if this exception strategy should be executed. " + "This should always be a boolean expression."); onError.onDefaultParameterGroup() .withOptionalParameter("type") .ofType(BaseTypeBuilder.create(JAVA).stringType() .enumOf("ANY", "REDELIVERY_EXHAUSTED", "TRANSFORMATION", "EXPRESSION", "SECURITY", "CLIENT_SECURITY", "SERVER_SECURITY", "ROUTING", "CONNECTIVITY", "RETRY_EXHAUSTED", "TIMEOUT") .build()) .withExpressionSupport(NOT_SUPPORTED) .describedAs("The full name of the error type to match against or a comma separated list of full names, " + "to match against any of them."); onError.onDefaultParameterGroup() .withOptionalParameter("logException") .ofType(typeLoader.load(boolean.class)) .defaultingTo(true) .describedAs("Determines whether the handled exception will be logged to its standard logger in the ERROR " + "level before being handled. Default is true."); onError.onDefaultParameterGroup() .withOptionalParameter("enableNotifications") .ofType(typeLoader.load(boolean.class)) .defaultingTo(true) .withExpressionSupport(NOT_SUPPORTED) .describedAs("Determines whether ExceptionNotifications will be fired from this strategy when an exception occurs." + " Default is true."); }
public StringTypeBuilder pattern(String pattern) { return with(new RegexPatternAnnotation(pattern)); }
@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()); } }