in src/main/java/org/apache/xmlbeans/impl/xsd2inst/SampleXmlUtil.java [157:278]
private String sampleDataForSimpleType(SchemaType sType) {
if (XmlObject.type.equals(sType)) {
return "anyType";
}
if (XmlAnySimpleType.type.equals(sType)) {
return "anySimpleType";
}
if (sType.getSimpleVariety() == SchemaType.LIST) {
SchemaType itemType = sType.getListItemType();
StringBuilder sb = new StringBuilder();
int length = pickLength(sType);
if (length > 0) {
sb.append(sampleDataForSimpleType(itemType));
}
for (int i = 1; i < length; i += 1) {
sb.append(' ');
sb.append(sampleDataForSimpleType(itemType));
}
return sb.toString();
}
if (sType.getSimpleVariety() == SchemaType.UNION) {
SchemaType[] possibleTypes = sType.getUnionConstituentTypes();
if (possibleTypes.length == 0) {
return "";
}
return sampleDataForSimpleType(possibleTypes[pick(possibleTypes.length)]);
}
XmlAnySimpleType[] enumValues = sType.getEnumerationValues();
if (enumValues != null && enumValues.length > 0) {
return enumValues[pick(enumValues.length)].getStringValue();
}
switch (sType.getPrimitiveType().getBuiltinTypeCode()) {
default:
case SchemaType.BTC_NOT_BUILTIN:
return "";
case SchemaType.BTC_ANY_TYPE:
case SchemaType.BTC_ANY_SIMPLE:
return "anything";
case SchemaType.BTC_BOOLEAN:
return pick(2) == 0 ? "true" : "false";
case SchemaType.BTC_BASE_64_BINARY: {
byte[] v = formatToLength(pick(WORDS), sType).getBytes(StandardCharsets.UTF_8);
return Base64.getEncoder().encodeToString(v);
}
case SchemaType.BTC_HEX_BINARY:
return HexBin.encode(formatToLength(pick(WORDS), sType));
case SchemaType.BTC_ANY_URI:
return formatToLength("http://www." + pick(DNS1) + "." + pick(DNS2) + "/" + pick(WORDS) + "/" + pick(WORDS), sType);
case SchemaType.BTC_QNAME:
return formatToLength("qname", sType);
case SchemaType.BTC_NOTATION:
return formatToLength("notation", sType);
case SchemaType.BTC_FLOAT:
return "1.5E2";
case SchemaType.BTC_DOUBLE:
return "1.051732E7";
case SchemaType.BTC_DECIMAL:
switch (closestBuiltin(sType).getBuiltinTypeCode()) {
case SchemaType.BTC_SHORT:
return formatDecimal("1", sType);
case SchemaType.BTC_UNSIGNED_SHORT:
return formatDecimal("5", sType);
case SchemaType.BTC_BYTE:
return formatDecimal("2", sType);
case SchemaType.BTC_UNSIGNED_BYTE:
return formatDecimal("6", sType);
case SchemaType.BTC_INT:
return formatDecimal("3", sType);
case SchemaType.BTC_UNSIGNED_INT:
return formatDecimal("7", sType);
case SchemaType.BTC_LONG:
return formatDecimal("10", sType);
case SchemaType.BTC_UNSIGNED_LONG:
return formatDecimal("11", sType);
case SchemaType.BTC_INTEGER:
return formatDecimal("100", sType);
case SchemaType.BTC_NON_POSITIVE_INTEGER:
return formatDecimal("-200", sType);
case SchemaType.BTC_NEGATIVE_INTEGER:
return formatDecimal("-201", sType);
case SchemaType.BTC_NON_NEGATIVE_INTEGER:
return formatDecimal("200", sType);
case SchemaType.BTC_POSITIVE_INTEGER:
return formatDecimal("201", sType);
default:
case SchemaType.BTC_DECIMAL:
return formatDecimal("1000.00", sType);
}
case SchemaType.BTC_STRING: {
String result = closestBuiltin(sType).getBuiltinTypeCode() == SchemaType.BTC_TOKEN ? "token" : "string";
return formatToLength(result, sType);
}
case SchemaType.BTC_DURATION:
return formatDuration(sType);
case SchemaType.BTC_DATE_TIME:
case SchemaType.BTC_TIME:
case SchemaType.BTC_DATE:
case SchemaType.BTC_G_YEAR_MONTH:
case SchemaType.BTC_G_YEAR:
case SchemaType.BTC_G_MONTH_DAY:
case SchemaType.BTC_G_DAY:
case SchemaType.BTC_G_MONTH:
return formatDate(sType);
}
}