Path: redb-route/redb.Route.Xml/CoreElements/CoreContributions.Specs.cs
Snapshot: redb-route, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages.
License: Apache-2.0. Repository: https://github.com/redbase-app/redb-route
Page: https://redbase.app/src/dev-2026-12-06/redb-route/redb.Route.Xml/CoreElements/CoreContributions.Specs.cs
----
using redb.Route.Xslt;
namespace redb.Route.Xml.CoreElements;
internal static partial class CoreContributions
{
// ── The public shapes of the core elements ──────────────────────────────
// One table, three consumers: parser hints, the XSD generator, the catalog. A test pins
// every registered core contribution to an entry here, so the shapes cannot drift from the
// parse code silently.
private static AttributeSpec S(string name, bool required = false) => new(name, AttributeType.String, required);
private static AttributeSpec E(string name, bool required = false) => new(name, AttributeType.Expression, required);
/// An expression read as a condition — a predicate, not a value.
private static AttributeSpec C(string name, bool required = false)
=> new(name, AttributeType.Expression, required) { Condition = true };
private static AttributeSpec U(string name, bool required = false) => new(name, AttributeType.Uri, required);
private static AttributeSpec R(string name, bool required = false) => new(name, AttributeType.Reference, required);
/// A CLR type as the markup names it: Full.Name, Assembly.
private static string Named() => $"{typeof(TType).FullName}, {typeof(TType).Assembly.GetName().Name}";
private static AttributeSpec T(string name, bool required = false) => new(name, AttributeType.TypeName, required);
private static AttributeSpec TL(string name, bool required = false) => new(name, AttributeType.TypeNameList, required);
private static AttributeSpec B(string name) => new(name, AttributeType.Bool);
private static AttributeSpec I(string name, bool required = false) => new(name, AttributeType.Int, required);
private static AttributeSpec L(string name) => new(name, AttributeType.Long);
private static AttributeSpec F(string name) => new(name, AttributeType.Double);
private static AttributeSpec D(string name, bool required = false) => new(name, AttributeType.Duration, required);
private static AttributeSpec En(string name, IReadOnlyList values, bool required = false)
=> new(name, AttributeType.Enum, required, values);
private static readonly string[] LogLevels =
["Trace", "Debug", "Information", "Warning", "Error", "Critical"];
private static readonly string[] TransactionPolicies =
["default", "requiresNew", "suppress", "mandatory"];
private static readonly string[] LoadBalanceStrategies =
["roundRobin", "random", "failover", "sticky", "weighted"];
private static ElementSpec AddressLeaf(string name, params AttributeSpec[] extra)
=> new(name, XmlElementKind.Step, [U("uri"), .. extra], [], TakesEndpoint: true);
private static readonly ElementSpec WhenCondition =
ElementSpec.Child("when", allowsSteps: false, C("expr", required: true));
/// The spec for a core element name; opaque for a name the table misses (test-guarded).
internal static ElementSpec SpecFor(string name, XmlElementKind kind)
=> Specs.TryGetValue(name, out var spec)
? spec
: new ElementSpec(name, kind, [], [], AllowsSteps: kind is XmlElementKind.Scope);
internal static readonly IReadOnlyDictionary Specs =
new Dictionary(StringComparer.Ordinal)
{
// ── leaves ──────────────────────────────────────────────────────
["to"] = AddressLeaf("to"),
// The step form of . ref= or beanType=, method=, and any further
// attribute is a bean: option (a bean property), as on the structured child.
["bean"] = ElementSpec.Leaf("bean", R("ref"), T("beanType"), S("method")) with { OpenAttributes = true },
["toD"] = AddressLeaf("toD"),
["wireTap"] = AddressLeaf("wireTap", S("executorService")),
["enrich"] = AddressLeaf("enrich", S("strategy")),
["pollEnrich"] = AddressLeaf("pollEnrich", S("strategy"), D("timeout")),
["setHeader"] = ElementSpec.Leaf("setHeader", S("name", required: true), S("value"), E("expr")),
["setProperty"] = ElementSpec.Leaf("setProperty", S("name", required: true), S("value"), E("expr")),
["setBody"] = ElementSpec.Leaf("setBody", S("value"), E("expr")),
["transform"] = ElementSpec.Leaf("transform", E("expr", required: true)),
["removeHeader"] = ElementSpec.Leaf("removeHeader", S("name", required: true)),
["removeProperty"] = ElementSpec.Leaf("removeProperty", S("name", required: true)),
["removeBody"] = ElementSpec.Leaf("removeBody"),
["addAttachment"] = ElementSpec.Leaf("addAttachment",
S("name"), E("expr"), B("fromBody"), S("file"), E("fileExpr"), S("fileName"), E("fileNameExpr"), S("contentType")),
["removeAttachment"] = ElementSpec.Leaf("removeAttachment", S("name", required: true)),
["removeAttachments"] = ElementSpec.Leaf("removeAttachments"),
["removeHeaders"] = ElementSpec.Leaf("removeHeaders", S("pattern", required: true), S("except")),
["removeProperties"] = ElementSpec.Leaf("removeProperties", S("pattern", required: true), S("except")),
["setHeaders"] = new("setHeaders", XmlElementKind.Step, [],
[ElementSpec.Child("header", false, S("name", required: true), S("value"), E("expr"))]),
["setProperties"] = new("setProperties", XmlElementKind.Step, [],
[ElementSpec.Child("property", false, S("name", required: true), S("value"), E("expr"))]),
["log"] = new("log", XmlElementKind.Step,
[En("level", LogLevels), B("showRouteId")],
[
new ElementSpec("message", XmlElementKind.ConfigChild, [], [], AllowsTextContent: true),
ElementSpec.Child("header", false, S("name", required: true)),
ElementSpec.Child("property", false, S("name", required: true)),
],
AllowsTextContent: true),
["delay"] = ElementSpec.Leaf("delay", D("duration"), E("expr")),
["stop"] = ElementSpec.Leaf("stop") with { Terminal = true },
["throwException"] = ElementSpec.Leaf("throwException", T("type", required: true), S("message")) with { Terminal = true },
["convertBody"] = ElementSpec.Leaf("convertBody", T("type", required: true)),
["validate"] = ElementSpec.Leaf("validate", C("expr", required: true), S("message"), B("throwOnFailure")),
["sort"] = ElementSpec.Leaf("sort", E("expr", required: true), E("by"), B("descending")),
["sample"] = ElementSpec.Leaf("sample", L("messageFrequency"), D("period")),
["streamCaching"] = ElementSpec.Leaf("streamCaching", L("spoolThreshold")),
["messageHistory"] = ElementSpec.Leaf("messageHistory", B("value")),
["validateJsonSchema"] = new("validateJsonSchema", XmlElementKind.Step,
[S("file"), B("throwOnFailure")], [], AllowsTextContent: true),
["validateXsd"] = new("validateXsd", XmlElementKind.Step,
[S("file"), S("targetNamespace"), S("schemaRoot"), B("throwOnFailure")], [], AllowsTextContent: true),
["xslt"] = new("xslt", XmlElementKind.Step,
[S("file"), En("output", Enum.GetNames()), B("failOnNullBody"), B("allowTemplateFromHeader")],
[], AllowsTextContent: true),
["marshal"] = ElementSpec.Leaf("marshal", S("format"), T("type")) with { OpenAttributes = true },
["unmarshal"] = ElementSpec.Leaf("unmarshal", S("format"), T("type"), T("target", required: true)) with { OpenAttributes = true },
["controlBus"] = ElementSpec.Leaf("controlBus",
En("action", Enum.GetNames(), required: true),
S("routeId", required: true), B("async")),
["recipientList"] = ElementSpec.Leaf("recipientList",
E("expr", required: true), S("delimiter"), B("parallel"), B("stopOnException"), S("strategy")),
["dynamicRouter"] = ElementSpec.Leaf("dynamicRouter", E("expr", required: true)),
["routingSlip"] = ElementSpec.Leaf("routingSlip",
E("expr", required: true), S("delimiter"), B("ignoreInvalidEndpoints")),
["claimCheck"] = ElementSpec.Leaf("claimCheck",
En("operation", Enum.GetNames(), required: true),
E("key"), D("ttl"), R("repository") with { References = Named() }),
["beginTransaction"] = ElementSpec.Leaf("beginTransaction", En("policy", TransactionPolicies)),
["commitTransaction"] = ElementSpec.Leaf("commitTransaction"),
["rollbackTransaction"] = ElementSpec.Leaf("rollbackTransaction"),
// Camel markRollbackOnly(): marks the exchange and stops the route (119e76d7).
["rollbackAll"] = ElementSpec.Leaf("rollbackAll") with { Terminal = true },
["exceptionHandled"] = ElementSpec.Leaf("exceptionHandled"),
["routePolicy"] = ElementSpec.Leaf("routePolicy", R("ref", required: true)),
// ── scopes ──────────────────────────────────────────────────────
["filter"] = ElementSpec.Scope("filter", C("expr"), R("predicate")),
["split"] = new("split", XmlElementKind.Scope,
[E("expr"), B("parallel"), I("maxParallelism"), B("stopOnException")],
[
ElementSpec.Child("tokenizeLines", false, S("separator"), B("skipEmpty")),
ElementSpec.Child("tokenizeXml", false, S("element", required: true), S("inheritNamespaceFrom")),
ElementSpec.Child("tokenizeJsonArray", false),
],
AllowsSteps: true),
["multicast"] = ElementSpec.Scope("multicast", B("parallel"), I("maxParallelism"), B("stopOnException")),
["aggregate"] = ElementSpec.Scope("aggregate",
E("correlation", required: true), S("strategy", required: true),
E("completion"), I("completionSize"), D("completionTimeout"), B("forceCompletionOnStop")),
["loop"] = ElementSpec.Scope("loop", I("count"), E("expr"), C("while"), B("copy"), B("shareScope")),
["throttle"] = ElementSpec.Scope("throttle",
E("maxPerPeriod", required: true), D("period"), E("key"), B("rejectOnOverflow")),
["debounce"] = ElementSpec.Scope("debounce", E("key", required: true), D("quietPeriod", required: true)),
["idempotentConsumer"] = ElementSpec.Scope("idempotentConsumer",
E("key", required: true), R("repository", required: true) with { References = Named() }, B("skipDuplicate")),
["resequence"] = ElementSpec.Scope("resequence", E("key", required: true), I("batchSize"), D("timeout")),
["transaction"] = ElementSpec.Scope("transaction", En("policy", TransactionPolicies),
U("deadLetterChannel"), I("retryAttempts"), D("retryDelay")),
["traced"] = ElementSpec.Scope("traced", S("name", required: true)),
// context.xml only: the context's dead letter channel (DeadLetterChannelContextContribution).
["dataFormat"] = new("dataFormat", XmlElementKind.ContextLevel, [T("type", required: true), S("name")], [],
AllowsSteps: false) { OpenAttributes = true },
["deadLetterChannel"] = new("deadLetterChannel", XmlElementKind.ContextLevel, [U("uri", required: true)], [],
AllowsSteps: false),
// context.xml only: a C# route builder of the context (RouteBuilderContextContribution).
["routeBuilder"] = new("routeBuilder", XmlElementKind.ContextLevel, [T("type", required: true)], [],
AllowsSteps: false),
["spanTag"] = ElementSpec.Leaf("spanTag", S("key", required: true), S("value"), E("expr"),
En("target", Enum.GetNames())),
["metered"] = new("metered", XmlElementKind.Scope, [S("name", required: true)],
[ElementSpec.Child("tag", allowsSteps: false,
S("name", required: true), S("fromHeader"), E("expr"))],
AllowsSteps: true),
["replayable"] = ElementSpec.Scope("replayable", S("name", required: true), B("exposed")),
["threads"] = ElementSpec.Scope("threads", I("poolSize", required: true),
I("maxQueueSize"), D("enqueueTimeout")),
["ofType"] = ElementSpec.Scope("ofType", T("type", required: true)),
["circuitBreaker"] = new("circuitBreaker", XmlElementKind.Scope,
[I("failureThreshold"), D("resetTimeout"), I("halfOpenMaxCalls")],
[ElementSpec.Child("fallback", allowsSteps: true)],
AllowsSteps: true),
["tryCatch"] = new("tryCatch", XmlElementKind.Scope, [],
[
ElementSpec.Child("try", allowsSteps: true),
ElementSpec.Child("catch", allowsSteps: true, TL("exceptions", required: true)),
ElementSpec.Child("finally", allowsSteps: true),
]),
["onException"] = new("onException", XmlElementKind.Scope,
[
TL("exceptions", required: true), B("handled"), B("continued"),
I("maximumRedeliveries"), D("redeliveryDelay"), B("exponentialBackOff"),
F("backOffMultiplier"), B("useOriginalBody"), B("logStackTrace"),
B("logExhausted"), B("logHandled"), B("logContinued"),
En("retryAttemptedLogLevel", LogLevels),
En("retriesExhaustedLogLevel", LogLevels),
R("onExceptionOccurred"), R("onRedelivery"), R("onPrepareFailure"),
],
[WhenCondition, ElementSpec.Child("retryWhile", allowsSteps: false, C("expr", required: true))],
AllowsSteps: true),
["intercept"] = new("intercept", XmlElementKind.Scope, [], [WhenCondition], AllowsSteps: true),
["interceptFrom"] = new("interceptFrom", XmlElementKind.Scope, [U("uri")], [WhenCondition], AllowsSteps: true),
["interceptSendToEndpoint"] = new("interceptSendToEndpoint", XmlElementKind.Scope,
[U("uri", required: true), B("skipSendToOriginalEndpoint")], [WhenCondition], AllowsSteps: true),
["onCompletion"] = new("onCompletion", XmlElementKind.Scope,
[B("onCompleteOnly"), B("onFailureOnly"), B("modeBeforeConsumer"), B("parallelProcessing"), S("executorService")],
[WhenCondition], AllowsSteps: true),
["scatterGather"] = new("scatterGather", XmlElementKind.Step,
[D("timeout"), B("parallel"), I("maxDop"), B("stopOnException"), S("strategy")],
[ElementSpec.Child("recipient", false, U("uri", required: true))]),
["loadBalance"] = new("loadBalance", XmlElementKind.Step,
[En("strategy", LoadBalanceStrategies, required: true), E("key")],
[ElementSpec.Child("endpoint", false, U("uri", required: true), I("weight"))]),
["normalize"] = new("normalize", XmlElementKind.Step, [],
[
ElementSpec.Child("when", false, C("expr", required: true), E("transform", required: true)),
ElementSpec.Child("whenContentType", false, S("type", required: true), E("transform", required: true)),
ElementSpec.Child("otherwise", false, E("transform", required: true)),
]),
["saga"] = new("saga", XmlElementKind.Step, [],
[ElementSpec.Child("step", false,
R("processor", required: true), R("compensate"))]),
// ── branching ───────────────────────────────────────────────────
["choice"] = new("choice", XmlElementKind.Branching, [],
[
ElementSpec.Child("when", allowsSteps: true, C("expr"), R("predicate")),
ElementSpec.Child("otherwise", allowsSteps: true),
]),
};
}