use of org.mule.runtime.config.internal.dsl.model.config.RuntimeConfigurationException in project mule by mulesoft.
the class ObjectBeanDefinitionCreator method handleRequest.
@Override
boolean handleRequest(CreateBeanDefinitionRequest createBeanDefinitionRequest) {
SpringComponentModel componentModel = createBeanDefinitionRequest.getComponentModel();
if (!componentModel.getIdentifier().equals(buildFromStringRepresentation("mule:object"))) {
return false;
}
String refParameterValue = componentModel.getParameters().get(REF_PARAMETER);
String classParameterValue = componentModel.getParameters().get(CLASS_PARAMETER);
if (refParameterValue != null && classParameterValue != null) {
throw new RuntimeConfigurationException(createStaticMessage(format("Object cannot contain both '%s' and '%s' parameters. Offending resource is '%s'", REF_PARAMETER, CLASS_PARAMETER, componentModel.getComponentLocation())));
}
if (refParameterValue == null && classParameterValue == null) {
throw new RuntimeConfigurationException(createStaticMessage(format("Object must contain '%s' or '%s' parameter. Offending resource is '%s'", REF_PARAMETER, CLASS_PARAMETER, componentModel.getComponentLocation())));
}
if (refParameterValue != null) {
componentModel.setBeanReference(new RuntimeBeanReference(refParameterValue));
}
if (classParameterValue != null) {
BeanDefinitionBuilder beanDefinitionBuilder;
final Class<?> classParameter;
try {
classParameter = ClassUtils.getClass(classParameterValue);
} catch (ClassNotFoundException e) {
throw new RuntimeConfigurationException(createStaticMessage(format("Could not resolve class '%s' for component '%s'", classParameterValue, componentModel.getComponentLocation())));
}
beanDefinitionBuilder = rootBeanDefinition(addAnnotationsToClass(classParameter));
processMuleProperties(componentModel, beanDefinitionBuilder, null);
componentModel.setBeanDefinition(beanDefinitionBuilder.getBeanDefinition());
}
return true;
}
use of org.mule.runtime.config.internal.dsl.model.config.RuntimeConfigurationException in project mule by mulesoft.
the class ApplicationModel method resolveComponentTypes.
/**
* Resolves the types of each component model when possible.
*/
public void resolveComponentTypes() {
// TODO MULE-13894 enable this once changes are completed and no componentBuildingDefinition is needed
// checkState(componentBuildingDefinitionRegistry.isPresent(),
// "ApplicationModel was created without a " + ComponentBuildingDefinitionProvider.class.getName());
componentBuildingDefinitionRegistry.ifPresent(buildingDefinitionRegistry -> {
executeOnEveryComponentTree(componentModel -> {
Optional<ComponentBuildingDefinition<?>> buildingDefinition = buildingDefinitionRegistry.getBuildingDefinition(componentModel.getIdentifier());
buildingDefinition.map(definition -> {
ObjectTypeVisitor typeDefinitionVisitor = new ObjectTypeVisitor(componentModel);
definition.getTypeDefinition().visit(typeDefinitionVisitor);
componentModel.setType(typeDefinitionVisitor.getType());
return definition;
}).orElseGet(() -> {
String classParameter = componentModel.getParameters().get(CLASS_ATTRIBUTE);
if (classParameter != null) {
try {
componentModel.setType(ClassUtils.getClass(classParameter));
} catch (ClassNotFoundException e) {
throw new RuntimeConfigurationException(I18nMessageFactory.createStaticMessage(String.format("Could not resolve class '%s' for component '%s'", classParameter, componentModel.getComponentLocation())));
}
}
return null;
});
});
});
}
use of org.mule.runtime.config.internal.dsl.model.config.RuntimeConfigurationException in project mule by mulesoft.
the class MuleArtifactContext method recursivelyResolveConfigFiles.
private List<ConfigFile> recursivelyResolveConfigFiles(List<Pair<String, InputStream>> configFilesToResolve, List<ConfigFile> alreadyResolvedConfigFiles) {
DefaultConfigurationPropertiesResolver propertyResolver = new DefaultConfigurationPropertiesResolver(empty(), new EnvironmentPropertiesConfigurationProvider());
ImmutableList.Builder<ConfigFile> resolvedConfigFilesBuilder = ImmutableList.<ConfigFile>builder().addAll(alreadyResolvedConfigFiles);
configFilesToResolve.stream().filter(fileNameInputStreamPair -> !alreadyResolvedConfigFiles.stream().anyMatch(configFile -> configFile.getFilename().equals(fileNameInputStreamPair.getFirst()))).forEach(fileNameInputStreamPair -> {
Document document = xmlConfigurationDocumentLoader.loadDocument(muleContext.getExtensionManager() == null ? emptySet() : muleContext.getExtensionManager().getExtensions(), fileNameInputStreamPair.getFirst(), fileNameInputStreamPair.getSecond());
ConfigLine mainConfigLine = xmlApplicationParser.parse(document.getDocumentElement()).get();
ConfigFile configFile = new ConfigFile(fileNameInputStreamPair.getFirst(), asList(mainConfigLine));
resolvedConfigFilesBuilder.add(configFile);
try {
fileNameInputStreamPair.getSecond().close();
} catch (IOException e) {
throw new MuleRuntimeException(e);
}
});
ImmutableSet.Builder<String> importedFiles = ImmutableSet.builder();
for (ConfigFile configFile : resolvedConfigFilesBuilder.build()) {
List<ConfigLine> rootConfigLines = configFile.getConfigLines();
ConfigLine muleRootElementConfigLine = rootConfigLines.get(0);
importedFiles.addAll(muleRootElementConfigLine.getChildren().stream().filter(configLine -> configLine.getNamespace().equals(CORE_PREFIX) && configLine.getIdentifier().equals(IMPORT_ELEMENT)).map(configLine -> {
SimpleConfigAttribute fileConfigAttribute = configLine.getConfigAttributes().get("file");
if (fileConfigAttribute == null) {
throw new RuntimeConfigurationException(createStaticMessage(format("<import> does not have a file attribute defined. At file '%s', at line %s", configFile.getFilename(), configLine.getLineNumber())));
}
return fileConfigAttribute.getValue();
}).map(value -> (String) propertyResolver.resolveValue(value)).filter(fileName -> !alreadyResolvedConfigFiles.stream().anyMatch(solvedConfigFile -> solvedConfigFile.getFilename().equals(fileName))).collect(toList()));
}
Set<String> importedConfigurationFiles = importedFiles.build();
if (importedConfigurationFiles.isEmpty()) {
return resolvedConfigFilesBuilder.build();
}
List<Pair<String, InputStream>> newConfigFilesToResolved = importedConfigurationFiles.stream().map(importedFileName -> {
InputStream resourceAsStream = muleContext.getExecutionClassLoader().getResourceAsStream(importedFileName);
if (resourceAsStream == null) {
throw new RuntimeConfigurationException(createStaticMessage(format("Could not find imported resource '%s'", importedFileName)));
}
return (Pair<String, InputStream>) new Pair(importedFileName, resourceAsStream);
}).collect(toList());
return recursivelyResolveConfigFiles(newConfigFilesToResolved, resolvedConfigFilesBuilder.build());
}
Aggregations