NoConfigRefFoundException(ExtensionModel extension, ComponentModel component) { super(format("No config-ref was specified for component '%s' of extension '%s'. Please specify which to use", component.getName(), extension.getName())); } }
@Override protected void defaultVisit(MetadataType metadataType) { exceptionValueHolder.set(buildException(format("'%s' type is invalid for MetadataKeyId parameters, " + "use String type instead. Affecting component: '%s'", metadataKeyType.getSimpleName(), component.getName()))); }
private Object getShowInDslParameterValue(String parameterName, String showInDslGroupName) { Object group = executionContext.getParameter(showInDslGroupName); try { return getFieldValue(group, parameterName, reflectionCache); } catch (IllegalAccessException | NoSuchFieldException e) { throw new IllegalStateException( format("An error occurred trying to obtain the field '%s' from the group '%s' of the Operation '%s'", parameterName, showInDslGroupName, operationModel.getName())); } } }
private MetadataKeyIdModelProperty findMetadataKeyIdModelProperty(ComponentModel component) throws MetadataResolvingException { return component.getModelProperty(MetadataKeyIdModelProperty.class) .orElseThrow(() -> buildException(format("Component '%s' doesn't have a MetadataKeyId " + "parameter associated", component.getName()))); }
private void validateParameterFieldsHaveGetters(ComponentModel model, MetadataType parameterMetadataType, ProblemsReporter problems, Set<Class<?>> validatedTypes) { validateType(format("%s '%s' has an argument", getComponentModelTypeName(model), model.getName()), model, parameterMetadataType, problems, validatedTypes); }
private void reportNoMatchingParameterForOverride(String ownerName, ComponentModel model, List<String> parameters, ProblemsReporter reporter) { reporter.addError(new Problem(model, format( "%s '%s' declares parameters %s as '%s' but associated Configuration '%s' does not declare parameters of the same name or alias.", capitalize(getComponentModelTypeName(model)), model.getName(), parameters, ConfigOverride.class.getSimpleName(), ownerName))); }
private void reportNoConfigurationForOverride(ComponentModel model, ProblemsReporter reporter) { reporter.addError(new Problem(model, format( "%s '%s' declares parameters as '%s' but is not associated to a Configuration.", capitalize(getComponentModelTypeName(model)), model.getName(), ConfigOverride.class.getSimpleName()))); }
public void visitObject(ObjectType objectType) { List<ParameterModel> parts = model.getAllParameterModels().stream() .filter(p -> p.getModelProperty(MetadataKeyPartModelProperty.class).isPresent()).collect(toList()); List<ParameterModel> defaultParts = parts.stream().filter(p -> p.getDefaultValue() != null).collect(toList()); if (!defaultParts.isEmpty() && defaultParts.size() != parts.size()) { String typeName = ExtensionMetadataTypeUtils.getId(objectType).orElse("Anonymous type"); problemsReporter .addError(new Problem(model, format("%s '%s' uses the multilevel key of type '%s', which defines '%s' MetadataKeyPart with default values, but the type contains '%s' " + "MetadataKeyParts. All the annotated MetadataKeyParts should have a default value if at least one part " + "has a default value. Either add the missing defaults or remove all of them.", modelTypeName, model.getName(), typeName, defaultParts.size(), parts.size()))); } } });
private OperationTransactionalAction getTransactionalAction() { try { Optional<ParameterModel> transactionalParameter = getTransactionalActionParameter(); if (transactionalParameter.isPresent()) { return getParameter(transactionalParameter.get().getName()); } else { throw new NoSuchElementException(); } } catch (NoSuchElementException e) { throw new IllegalArgumentException( format("Operation '%s' from extension '%s' is transactional but no transactional action defined", componentModel.getName(), extensionModel.getName())); } }
private void validateCategoryNames(ComponentModel componentModel, ProblemsReporter problemsReporter, List<NamedTypeResolver> resolvers) { resolvers.stream().filter(r -> StringUtils.isBlank(r.getCategoryName())) .findFirst().ifPresent(r -> problemsReporter.addError(new Problem(componentModel, format(EMPTY_RESOLVER_NAME, capitalize(getComponentModelTypeName(componentModel)), componentModel.getName(), r.getClass().getSimpleName(), "category")))); Set<String> names = resolvers.stream() .filter(r -> !isNullResolver(r)) .map(NamedTypeResolver::getCategoryName) .collect(toSet()); if (names.size() > 1) { problemsReporter.addError(new Problem(componentModel, format("%s '%s' specifies metadata resolvers that doesn't belong to the same category. The following categories were the ones found '%s'", capitalize(getComponentModelTypeName(componentModel)), componentModel.getName(), join(names, ",")))); } }
private Object instantiateFromFieldValue(Class<?> metadataKeyType, Map<Field, String> fieldValueMap) throws MetadataResolvingException { try { DefaultObjectBuilder objectBuilder = new DefaultObjectBuilder<>(metadataKeyType, reflectionCache); fieldValueMap.forEach((f, v) -> objectBuilder.addPropertyResolver(f, new StaticValueResolver<>(v))); return objectBuilder.build(null); } catch (Exception e) { throw buildException(format("MetadataKey object of type '%s' from the component '%s' could not be instantiated", metadataKeyType.getSimpleName(), component.getName()), e); } }
private Optional<ComponentElementDeclarer> declareComponentModel(String namespace, String identifier, Map<String, SimpleConfigAttribute> configAttributes, List<ConfigLine> children, ComponentModel model, Function<String, ComponentElementDeclarer> declarerBuilder) { final DslElementSyntax elementDsl = resolvers.get(getNamespace(namespace)).resolve(model); if (elementDsl.getElementName().equals(identifier)) { ComponentElementDeclarer declarer = declarerBuilder.apply(model.getName()); if (configAttributes.get(CONFIG_ATTRIBUTE_NAME) != null) { declarer.withConfig(configAttributes.get(CONFIG_ATTRIBUTE_NAME).getValue()); } declareParameterizedComponent(model, elementDsl, declarer, configAttributes, children); declareComposableModel(model, elementDsl, children, declarer); return Optional.of(declarer); } return Optional.empty(); }
public void registerOperation(ComponentModel componentModel, DslElementSyntax dslSyntax, boolean hasImplicitConfig) { String typeName = capitalize(componentModel.getName()) + TYPE_SUFFIX; registerProcessorElement(componentModel, typeName, dslSyntax); ExtensionType extensionType = registerOperationType(typeName, componentModel, dslSyntax, hasImplicitConfig); registerNestedComponents(extensionType, componentModel.getNestedComponents()); }
private <T> ConnectionHandler<T> getTransactionlessConnectionHandler(ExecutionContext executionContext) throws ConnectionException { final Optional<ConfigurationInstance> configuration = executionContext.getConfiguration(); Optional<ConnectionProvider> connectionProvider = configuration.flatMap(ConfigurationInstance::getConnectionProvider); if (!connectionProvider.isPresent()) { String configRef = configuration .map(config -> format("with config '%s' which is not associated to a connection provider", config.getName())) .orElse("without a config"); throw new IllegalStateException(format("%s '%s' of extension '%s' requires a connection but was executed %s", getComponentModelTypeName(executionContext.getComponentModel()), executionContext.getComponentModel().getName(), executionContext.getExtensionModel().getName(), configRef)); } return connectionManager.getConnection(configuration.get().getValue()); } }
public <T extends TransactionalConnection> Optional<ConnectionHandler<T>> bindToTransaction(TransactionConfig transactionConfig, ConfigurationInstance configurationInstance, ConnectionHandler connectionHandler) throws ConnectionException, TransactionException { if (!transactionConfig.isTransacted()) { return empty(); } Transaction tx = transactionConfig.getFactory().beginTransaction(muleContext); tx.setTimeout(transactionConfig.getTimeout()); ConfigurationInstance configuration = ofNullable(configurationInstance) .orElseThrow(() -> new IllegalStateException(format( "Source '%s' of extension '%s' cannot participate in a transaction because it doesn't have a config", componentModel.getName(), extensionModel.getName()))); final ExtensionTransactionKey txKey = new ExtensionTransactionKey(configuration); return Optional.of(transactionBindingDelegate.getBoundResource(transactionConfig, txKey, () -> connectionHandler)); } }
protected boolean isTargetPresent() { if (isBlank(target)) { return false; } if (muleContext.getExpressionManager().isExpression(target)) { throw new IllegalOperationException(format(INVALID_TARGET_MESSAGE, getLocation().getRootContainerName(), componentModel.getName(), "an expression", TARGET_PARAMETER_NAME)); } else if (!muleContext.getExpressionManager().isExpression(targetValue)) { throw new IllegalOperationException(format(INVALID_TARGET_MESSAGE, getLocation().getRootContainerName(), componentModel.getName(), "something that is not an expression", TARGET_VALUE_PARAMETER_NAME)); } return true; }
private void validateConnectionTypes(ConnectionProviderModel providerModel, ComponentModel componentModel, Type providerConnectionType, ProblemsReporter problemsReporter) { getConnectionType(componentModel).ifPresent(connectionType -> { if (!connectionType.isAssignableFrom(providerConnectionType)) { problemsReporter .addError(new Problem(providerModel, format("Component '%s' requires a connection of type '%s'. However, it also defines connection provider " + "'%s' which yields connections of incompatible type '%s'", componentModel.getName(), connectionType.getName(), providerModel.getName(), providerConnectionType.getName()))); } }); } }
private void validateConfigurationProviderIsNotExpression() throws InitialisationException { if (isConfigurationSpecified() && expressionParser.isContainsTemplate(configurationProvider.get().getName())) { throw new InitialisationException( createStaticMessage( format("Root component '%s' defines component '%s' which specifies the expression '%s' as a config-ref. " + "Expressions are not allowed as config references", getLocation().getRootContainerName(), hyphenize(componentModel.getName()), configurationProvider)), this); } }
private Throwable handleTypedException(final Throwable exception, ErrorTypeDefinition errorDefinition) { ErrorType errorType = typeRepository.lookupErrorType(builder() .namespace(extensionNamespace) .name(errorDefinition.getType()) .build()) .orElseThrow(() -> new MuleRuntimeException(createStaticMessage("The component '%s' from the connector '%s' attempted to throw '%s', but it was not registered " + "in the Error Repository", componentModel.getName(), extensionModel.getName(), extensionNamespace + ":" + errorDefinition), getExceptionCause(exception))); if (!isAllowedError(errorType)) { throw new MuleRuntimeException(createStaticMessage("The component '%s' from the connector '%s' attempted to throw '%s', but" + " only %s errors are allowed.", componentModel.getName(), extensionModel.getName(), extensionNamespace + ":" + errorDefinition, allowedErrorTypes), exception.getCause()); } return new TypedException(getExceptionCause(exception), errorType); }
@Before public void setUp() { mockMetadataKeyModelProp(continentParam, 1); mockMetadataKeyModelProp(countryParam, 2); mockMetadataKeyModelProp(cityParam, 3); ReflectionCache reflectionCache = new ReflectionCache(); mockDeclaringMemberModelProp(continentParam, CONTINENT, reflectionCache); mockDeclaringMemberModelProp(countryParam, COUNTRY, reflectionCache); mockDeclaringMemberModelProp(cityParam, CITY, reflectionCache); mockQueryModelProp(continentParam); mockQueryModelProp(countryParam); mockQueryModelProp(cityParam); when(componentModel.getName()).thenReturn(OPERATION_NAME); }