use of org.mule.runtime.api.meta.model.declaration.fluent.ExtensionDeclaration in project mule by mulesoft.
the class JavaDeclarationDelegateTestCase method categoryDefaultValueIsDescribedCorrectly.
@Test
public void categoryDefaultValueIsDescribedCorrectly() {
setLoader(loaderFor(PetStoreConnector.class));
ExtensionDeclarer declarer = declareExtension();
final ExtensionDeclaration declaration = declarer.getDeclaration();
assertThat(declaration.getCategory(), is(COMMUNITY));
}
use of org.mule.runtime.api.meta.model.declaration.fluent.ExtensionDeclaration in project mule by mulesoft.
the class ErrorsDeclarationEnricher method collectErrorOperations.
private List<Pair<ComponentDeclaration, MethodElement>> collectErrorOperations(ExtensionDeclaration declaration) {
List<Pair<ComponentDeclaration, MethodElement>> operations = new LinkedList<>();
new IdempotentDeclarationWalker() {
@Override
public void onOperation(WithOperationsDeclaration owner, OperationDeclaration declaration) {
addComponent(declaration);
}
@Override
protected void onConstruct(ConstructDeclaration declaration) {
addComponent(declaration);
}
private void addComponent(ComponentDeclaration<?> declaration) {
declaration.getModelProperty(ExtensionOperationDescriptorModelProperty.class).ifPresent(implementingMethodModelProperty -> operations.add(new Pair<>(declaration, implementingMethodModelProperty.getOperationMethod())));
}
}.walk(declaration);
return operations;
}
use of org.mule.runtime.api.meta.model.declaration.fluent.ExtensionDeclaration in project mule by mulesoft.
the class ErrorsDeclarationEnricher method enrich.
@Override
public void enrich(ExtensionLoadingContext extensionLoadingContext) {
ExtensionDeclaration declaration = extensionLoadingContext.getExtensionDeclarer().getDeclaration();
String extensionNamespace = getExtensionsNamespace(declaration);
Optional<ExtensionTypeDescriptorModelProperty> implementingType = declaration.getModelProperty(ExtensionTypeDescriptorModelProperty.class);
ErrorsModelFactory errorModelDescriber = new ErrorsModelFactory(extensionNamespace);
errorModelDescriber.getErrorModels().forEach(declaration::addErrorModel);
if (implementingType.isPresent() && implementingType.get().getType().getDeclaringClass().isPresent()) {
Type extensionElement = implementingType.get().getType();
Optional<ErrorTypes> errorAnnotation = extensionElement.getAnnotation(ErrorTypes.class);
List<Pair<ComponentDeclaration, MethodElement>> errorOperations = collectErrorOperations(declaration);
if (errorAnnotation.isPresent()) {
ErrorTypeDefinition<?>[] errorTypes = (ErrorTypeDefinition<?>[]) errorAnnotation.get().value().getEnumConstants();
if (errorTypes.length > 0) {
ErrorsModelFactory operationErrorModelDescriber = new ErrorsModelFactory(errorTypes, extensionNamespace);
operationErrorModelDescriber.getErrorModels().forEach(declaration::addErrorModel);
errorOperations.stream().forEach(pair -> registerOperationErrorTypes(pair.getSecond(), pair.getFirst(), operationErrorModelDescriber, errorTypes, extensionElement));
} else {
handleNoErrorTypes(extensionElement, errorOperations);
}
} else {
handleNoErrorTypes(extensionElement, errorOperations);
}
}
}
use of org.mule.runtime.api.meta.model.declaration.fluent.ExtensionDeclaration in project mule by mulesoft.
the class ExtensionDescriptionsEnricher method document.
/**
* Fills all the descriptions in the provided {@link ExtensionDeclaration} based on the
* <strong>extensions-descriptions.xml</strong> file.
*
* @param declaration the declaration to describe.
* @param documentation the extension documentation with its corresponding description.
*/
private void document(ExtensionDeclaration declaration, XmlExtensionDocumentation documentation) {
declaration.setDescription(documentation.getExtension().getDescription());
new DeclarationWalker() {
@Override
protected void onConfiguration(ConfigurationDeclaration declaration) {
document(declaration, documentation.getConfigs());
}
@Override
protected void onOperation(WithOperationsDeclaration owner, OperationDeclaration declaration) {
document(declaration, documentation.getOperations());
}
@Override
protected void onConnectionProvider(ConnectedDeclaration owner, ConnectionProviderDeclaration declaration) {
document(declaration, documentation.getConnections());
}
@Override
protected void onSource(WithSourcesDeclaration owner, SourceDeclaration declaration) {
document(declaration, documentation.getSources());
}
private void document(ParameterizedDeclaration<?> declaration, List<XmlExtensionElementDocumentation> elements) {
elements.stream().filter(e -> e.getName().equals(declaration.getName())).findAny().ifPresent(e -> {
declaration.setDescription(e.getDescription());
declaration.getAllParameters().forEach(param -> e.getParameters().stream().filter(p -> p.getName().equals(param.getName())).findAny().ifPresent(p -> param.setDescription(p.getDescription())));
});
}
}.walk(declaration);
}
use of org.mule.runtime.api.meta.model.declaration.fluent.ExtensionDeclaration in project mule by mulesoft.
the class ImportedTypesDeclarationEnricher method enrich.
@Override
public void enrich(ExtensionLoadingContext extensionLoadingContext) {
ExtensionDeclarer descriptor = extensionLoadingContext.getExtensionDeclarer();
ExtensionDeclaration extensionDeclaration = descriptor.getDeclaration();
final Optional<ExtensionTypeDescriptorModelProperty> extensionType = extensionDeclaration.getModelProperty(ExtensionTypeDescriptorModelProperty.class);
if (!extensionType.isPresent()) {
return;
}
Type type = extensionType.get().getType();
final List<AnnotationValueFetcher<Import>> importTypes = parseRepeatableAnnotation(type, Import.class, c -> ((ImportedTypes) c).value());
if (!importTypes.isEmpty()) {
if (importTypes.stream().map(annotation -> annotation.getClassValue(Import::type)).distinct().collect(toList()).size() != importTypes.size()) {
throw new IllegalModelDefinitionException(format("There should be only one Import declaration for any given type in extension [%s]." + " Multiple imports of the same type are not allowed", extensionDeclaration.getName()));
}
importTypes.forEach(imported -> {
MetadataType importedType = imported.getClassValue(Import::type).asMetadataType();
if (!(importedType instanceof ObjectType)) {
throw new IllegalArgumentException(format("Type '%s' is not complex. Only complex types can be imported from other extensions.", type.getTypeName()));
}
extensionDeclaration.addImportedType(new ImportedTypeModel((ObjectType) importedType));
});
}
}
Aggregations