use of org.mule.metadata.api.model.StringType in project mule by mulesoft.
the class MimeTypeParametersDeclarationEnricherTestCase method enumTypeOperation.
@Test
public void enumTypeOperation() {
StringType type = builder.stringType().with(new EnumAnnotation<>(new String[] { "val" })).build();
mockOutput(operation, type);
enricher.enrich(extensionLoadingContext);
assertThat(getGroupParameters(operation), hasSize(0));
}
use of org.mule.metadata.api.model.StringType in project mule by mulesoft.
the class SoapInvokeOperationDeclarer method declareMetadataKeyParameters.
/**
* Given the Invoke Operation Declarer declares all the parameters that the operation has.
*
* @param operation the invoke operation declarer.
*/
private void declareMetadataKeyParameters(OperationDeclarer operation, ClassTypeLoader loader, ReflectionCache reflectionCache) {
TypeWrapper keyType = new TypeWrapper(WebServiceTypeKey.class, loader);
ParameterGroupDeclarer group = operation.onParameterGroup(KEYS_GROUP).withModelProperty(new ParameterGroupModelProperty(new ParameterGroupDescriptor(KEYS_GROUP, keyType)));
StringType stringType = TYPE_BUILDER.stringType().build();
group.withRequiredParameter(SERVICE_PARAM).withModelProperty(new DeclaringMemberModelProperty(getField(WebServiceTypeKey.class, SERVICE_PARAM, reflectionCache).get())).ofType(stringType).withModelProperty(new MetadataKeyPartModelProperty(1)).withLayout(getLayout(1));
group.withRequiredParameter(OPERATION_PARAM).ofType(stringType).withModelProperty(new DeclaringMemberModelProperty(getField(WebServiceTypeKey.class, OPERATION_PARAM, reflectionCache).get())).withModelProperty(new MetadataKeyPartModelProperty(2)).withLayout(getLayout(2));
}
use of org.mule.metadata.api.model.StringType in project mule by mulesoft.
the class SchemaTypeConversion method convertType.
public static QName convertType(final MetadataType type, ExpressionSupport expressionSupport) {
final boolean dynamic = acceptsExpressions(expressionSupport);
final Reference<QName> qName = new Reference<>(null);
type.accept(new MetadataTypeVisitor() {
@Override
public void visitBoolean(BooleanType booleanType) {
qName.set(dynamic ? EXPRESSION_BOOLEAN : SUBSTITUTABLE_BOOLEAN);
}
@Override
public void visitNumber(NumberType numberType) {
if (getId(numberType).isPresent()) {
Class<Number> type = JavaTypeUtils.getType(numberType);
if (anyOf(type, Integer.class, int.class)) {
qName.set(dynamic ? EXPRESSION_INTEGER : SUBSTITUTABLE_INT);
} else if (anyOf(type, Double.class, double.class)) {
qName.set(dynamic ? EXPRESSION_DOUBLE : SUBSTITUTABLE_DECIMAL);
} else if (anyOf(type, Long.class, long.class)) {
qName.set(dynamic ? EXPRESSION_LONG : SUBSTITUTABLE_LONG);
} else {
qName.set(dynamic ? EXPRESSION_DECIMAL : SUBSTITUTABLE_DECIMAL);
}
} else {
if (numberType.getAnnotation(IntAnnotation.class).isPresent()) {
qName.set(dynamic ? EXPRESSION_INTEGER : SUBSTITUTABLE_INT);
} else {
qName.set(dynamic ? EXPRESSION_DECIMAL : SUBSTITUTABLE_DECIMAL);
}
}
}
@Override
public void visitString(StringType stringType) {
qName.set(dynamic ? EXPRESSION_STRING : STRING);
}
@Override
public void visitDateTime(DateTimeType dateTimeType) {
onDate();
}
@Override
public void visitDate(DateType dateType) {
onDate();
}
@Override
public void visitArrayType(ArrayType arrayType) {
qName.set(dynamic ? EXPRESSION_LIST : SUBSTITUTABLE_NAME);
}
@Override
public void visitObject(ObjectType objectType) {
if (isMap(objectType)) {
qName.set(dynamic ? EXPRESSION_MAP : SUBSTITUTABLE_NAME);
} else {
defaultVisit(objectType);
}
}
@Override
protected void defaultVisit(MetadataType metadataType) {
qName.set(STRING);
}
private void onDate() {
qName.set(dynamic ? EXPRESSION_DATE_TIME : SUBSTITUTABLE_DATE_TIME);
}
private boolean anyOf(Class<Number> type, Class<?>... targets) {
for (Class<?> target : targets) {
if (type.equals(target)) {
return true;
}
}
return false;
}
});
return qName.get();
}
use of org.mule.metadata.api.model.StringType 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;
}
Aggregations