luigidemasi commented on code in PR #27079: URL: https://github.com/apache/camel/pull/27079#discussion_r4143208747
########## core/camel-core-model/src/main/java/org/apache/camel/model/SwitchDefinition.java: ########## @@ -0,0 +1,260 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.model; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Map; + +import jakarta.xml.bind.annotation.XmlAccessType; +import jakarta.xml.bind.annotation.XmlAccessorType; +import jakarta.xml.bind.annotation.XmlElement; +import jakarta.xml.bind.annotation.XmlRootElement; +import jakarta.xml.bind.annotation.XmlTransient; +import jakarta.xml.bind.annotation.XmlType; + +import org.apache.camel.Expression; +import org.apache.camel.NamedNode; +import org.apache.camel.builder.ExpressionClause; +import org.apache.camel.model.language.ExpressionDefinition; +import org.apache.camel.spi.Metadata; + +/** Routes a message to one fixed endpoint using a literal lookup table. */ +@Metadata(firstVersion = "4.23.0", label = "eip,routing", + description = "Evaluates a selector once and dispatches to a fixed endpoint by literal scalar or composite values") +@XmlRootElement(name = "switch") +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(propOrder = { "selector", "keys", "cases", "otherwise" }) +public class SwitchDefinition extends NoOutputDefinition<SwitchDefinition> { + @XmlElement(required = true) + @Metadata(required = true, + description = "Expression evaluated once per entry. Returns a scalar, or a map when keys are configured.") + private ExpressionSubElementDefinition selector; + @XmlElement(name = "keys") + @Metadata(description = "Exact map field names forming a composite key. Additional result fields are ignored.") + private List<String> keys = new ArrayList<>(); + @XmlElement(name = "case") + @Metadata(description = "Literal cases. Duplicate combinations are rejected at startup.") + private List<SwitchCaseDefinition> cases = new ArrayList<>(); + @XmlElement + @Metadata(description = "Fixed fallback URI for null or unmatched selector results. Without a fallback processing continues.") + private SwitchOtherwiseDefinition otherwise; Review Comment: Yes, let's retain the `otherwise` element. The reason is to support the same YAML `uri` plus `parameters` endpoint configuration for the fallback as for cases. XML keeps `<otherwise uri="direct:review"/>`, and Java keeps `.otherwise("direct:review")`. This only determines how the destination is declared: null or unmatched selector results still use the fallback, selector failures still follow normal Camel error handling, and a case value named `otherwise` remains an ordinary literal. _Comment written by Codex on behalf of @luigidemasi._ -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
