use of org.mule.metadata.api.model.MetadataType in project mule by mulesoft.
the class DeclarationBasedElementModelFactory method createList.
private void createList(ParameterListValue list, DslElementSyntax listDsl, Object model, ArrayType listType, InternalComponentConfiguration.Builder parentConfig, DslElementModel.Builder parentElement) {
final DslElementModel.Builder listElement = DslElementModel.builder().withModel(model).withDsl(listDsl);
final InternalComponentConfiguration.Builder listConfig = InternalComponentConfiguration.builder().withIdentifier(asIdentifier(listDsl));
final MetadataType itemType = listType.getType();
listDsl.getGeneric(itemType).ifPresent(itemDsl -> list.getValues().forEach(value -> createListItemConfig(itemType, value, itemDsl, listConfig, listElement)));
ComponentConfiguration result = listConfig.build();
parentConfig.withNestedComponent(result);
parentElement.containing(listElement.withConfig(result).build());
}
use of org.mule.metadata.api.model.MetadataType in project mule by mulesoft.
the class IntrospectionUtils method collectRelativeClasses.
/**
* Given a {@link MetadataType} it adds all the {@link Class} that are related from that type. This includes generics of an
* {@link ArrayType}, open restriction of an {@link ObjectType} as well as its fields.
*
* @param type {@link MetadataType} to inspect
* @param extensionClassLoader extension class loader
* @return {@link Set<Class<?>>} with the classes reachable from the {@code type}
*/
public static Set<Class<?>> collectRelativeClasses(MetadataType type, ClassLoader extensionClassLoader) {
Set<Class<?>> relativeClasses = new HashSet<>();
type.accept(new MetadataTypeVisitor() {
@Override
public void visitArrayType(ArrayType arrayType) {
arrayType.getType().accept(this);
}
@Override
public void visitObjectField(ObjectFieldType objectFieldType) {
objectFieldType.getValue().accept(this);
}
@Override
public void visitObject(ObjectType objectType) {
if (objectType.getMetadataFormat() != JAVA) {
return;
}
final Class<Object> clazz = getType(objectType).orElse(null);
if (clazz == null || relativeClasses.contains(clazz)) {
return;
}
Optional<ClassInformationAnnotation> classInformation = objectType.getAnnotation(ClassInformationAnnotation.class);
if (classInformation.isPresent()) {
classInformation.get().getGenericTypes().forEach(generic -> relativeClasses.add(loadClass(generic, extensionClassLoader)));
}
relativeClasses.add(clazz);
objectType.getFields().stream().forEach(objectFieldType -> objectFieldType.accept(this));
objectType.getOpenRestriction().ifPresent(t -> t.accept(this));
}
@Override
public void visitString(StringType stringType) {
if (stringType.getMetadataFormat() == JAVA && isEnum(stringType)) {
getType(stringType).ifPresent(relativeClasses::add);
}
}
});
return relativeClasses;
}
use of org.mule.metadata.api.model.MetadataType in project mule by mulesoft.
the class IntrospectionUtils method getGenerics.
public static List<MetadataType> getGenerics(java.lang.reflect.Type type, ClassTypeLoader typeLoader) {
if (type instanceof ParameterizedType) {
ParameterizedType parameterizedType = (ParameterizedType) type;
java.lang.reflect.Type[] generics = parameterizedType.getActualTypeArguments();
return Stream.of(generics).map(typeLoader::load).collect(toList());
}
return new LinkedList<>();
}
use of org.mule.metadata.api.model.MetadataType in project mule by mulesoft.
the class DsqlQueryMetadataResolverTestCase method getFullOutputMetadata.
@Test
public void getFullOutputMetadata() throws MetadataResolvingException, ConnectionException {
DsqlQuery dsqlQuery = dsqlParser.parse("dsql:SELECT * FROM Circle WHERE (diameter < 18)");
MetadataType outputMetadata = getQueryMetadataResolver().getOutputType(context, dsqlQuery);
ObjectType type = getAndAssertTypeOf(outputMetadata);
assertThat(type.getFields(), hasSize(3));
type.getFields().forEach(f -> {
String name = f.getKey().getName().getLocalPart();
assertThat(name, isIn(asList("color", "id", "diameter")));
});
}
use of org.mule.metadata.api.model.MetadataType in project mule by mulesoft.
the class CustomStaticTypeDeclarationEnricher method declareCustomType.
private <T extends BaseDeclaration & TypedDeclaration> void declareCustomType(T declaration, MetadataType target) {
MetadataType type = declaration.getType();
Class<?> clazz = getType(type).orElseThrow(() -> new IllegalStateException("Could not find class in type [" + type + "]"));
Set<TypeAnnotation> a = new HashSet<>(asList(new ClassInformationAnnotation(clazz), new CustomDefinedStaticTypeAnnotation()));
declaration.setType(enricher.enrich(target, a), false);
}
Aggregations