luigidemasi commented on code in PR #27082: URL: https://github.com/apache/camel/pull/27082#discussion_r4142122253
########## core/camel-core-model/src/main/java/org/apache/camel/model/app/SemanticDefinition.java: ########## @@ -0,0 +1,73 @@ +/* + * 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.app; + +import java.util.ArrayList; +import java.util.List; + +import jakarta.xml.bind.annotation.XmlAccessType; +import jakarta.xml.bind.annotation.XmlAccessorType; +import jakarta.xml.bind.annotation.XmlElement; +import jakarta.xml.bind.annotation.XmlType; + +import org.apache.camel.CamelContext; +import org.apache.camel.spi.Metadata; +import org.apache.camel.spi.Resource; + +/** Named, provider-independent semantic question declarations. */ +@Metadata(label = "configuration") +@XmlType(name = "semanticDefinition") +@XmlAccessorType(XmlAccessType.FIELD) +public class SemanticDefinition { + @XmlElement(name = "question") + @Metadata(description = "Named semantic questions shared by routes in this Camel context.") + private List<SemanticQuestionDefinition> questions = new ArrayList<>(); + + public List<SemanticQuestionDefinition> getQuestions() { + return questions; + } + + public void setQuestions(List<SemanticQuestionDefinition> questions) { + this.questions = questions; + } + + /** Declare a named semantic question. */ + public SemanticQuestionDefinition question(String name) { + SemanticQuestionDefinition question = new SemanticQuestionDefinition(); + question.setName(name); + questions.add(question); + return question; + } + Review Comment: The core configurer and its discovery helper have been removed in [4e03971ee3ec](https://github.com/apache/camel/commit/4e03971ee3ecbcf65621a760d660dcdc656ba5bb). Declarations now live in `camel-semantic`, using a fluent Java helper and a component XML loader. Registration and installation of the existing builder lifecycle strategy are synchronized on the context-local question registry. _Generated by Codex via /oss-address-review on behalf of [luigidemasi](https://github.com/luigidemasi)._ ########## dsl/camel-xml-io-dsl/src/main/java/org/apache/camel/dsl/xml/io/XmlRoutesBuilderLoader.java: ########## @@ -95,19 +97,50 @@ public void preParseRoute(Resource resource) throws Exception { if (preparseDone.getOrDefault(resource.getLocation(), false)) { return; } - XmlStreamInfo xmlInfo = xmlInfo(resource); - if (xmlInfo.isValid()) { - String root = xmlInfo.getRootElementName(); - if ("beans".equals(root) || "blueprint".equals(root) || "camel".equals(root)) { - new XmlModelParser(resource, xmlInfo.getRootElementNamespace()) - .parseBeansDefinition() - .ifPresent(bd -> { - registerBeans(resource, bd); - camelAppCache.put(resource.getLocation(), bd); - }); + try { + XmlStreamInfo xmlInfo = xmlInfo(resource); + if (xmlInfo.isValid()) { + String root = xmlInfo.getRootElementName(); + SemanticDefinition semantic = null; + if ("beans".equals(root) || "blueprint".equals(root) || "camel".equals(root)) { + new XmlModelParser(resource, xmlInfo.getRootElementNamespace()) + .parseBeansDefinition() + .ifPresent(bd -> { + registerBeans(resource, bd); + camelAppCache.put(resource.getLocation(), bd); + }); + BeansDefinition app = camelAppCache.get(resource.getLocation()); + if (app != null) { + semantic = app.getSemantic(); + } + } else if ("routes".equals(root) || "route".equals(root)) { + RoutesDefinition routes = new XmlModelParser(resource(resource), xmlInfo.getRootElementNamespace()) + .parseRoutesDefinition().orElse(null); + if (routes != null) { + routesCache.put(resource.getLocation(), routes); + semantic = routes.getSemantic(); + } + } + SemanticDefinition.configure(getCamelContext(), resource, resource.getLocation(), semantic); } + preparseDone.put(resource.getLocation(), true); + } catch (Exception e) { + // A failed batch also prevents builders for earlier resources from clearing their cached input. + resourceCache.clear(); + xmlInfoCache.clear(); Review Comment: This code is removed in [4e03971ee3ec](https://github.com/apache/camel/commit/4e03971ee3ecbcf65621a760d660dcdc656ba5bb): the standard XML loader is unchanged from the PR base. The component loader for `*.semantic.xml` reads fresh content without a preparse cache, so it does not need to clear other resources’ caches. _Generated by Codex via /oss-address-review on behalf of [luigidemasi](https://github.com/luigidemasi)._ ########## dsl/camel-xml-io-dsl/src/main/java/org/apache/camel/dsl/xml/io/XmlRoutesBuilderLoader.java: ########## @@ -95,19 +97,50 @@ public void preParseRoute(Resource resource) throws Exception { if (preparseDone.getOrDefault(resource.getLocation(), false)) { return; } - XmlStreamInfo xmlInfo = xmlInfo(resource); - if (xmlInfo.isValid()) { - String root = xmlInfo.getRootElementName(); - if ("beans".equals(root) || "blueprint".equals(root) || "camel".equals(root)) { - new XmlModelParser(resource, xmlInfo.getRootElementNamespace()) - .parseBeansDefinition() - .ifPresent(bd -> { - registerBeans(resource, bd); - camelAppCache.put(resource.getLocation(), bd); - }); + try { + XmlStreamInfo xmlInfo = xmlInfo(resource); + if (xmlInfo.isValid()) { + String root = xmlInfo.getRootElementName(); + SemanticDefinition semantic = null; + if ("beans".equals(root) || "blueprint".equals(root) || "camel".equals(root)) { + new XmlModelParser(resource, xmlInfo.getRootElementNamespace()) + .parseBeansDefinition() + .ifPresent(bd -> { + registerBeans(resource, bd); + camelAppCache.put(resource.getLocation(), bd); + }); Review Comment: The standard XML loader is unchanged in the final changeset after [4e03971ee3ec](https://github.com/apache/camel/commit/4e03971ee3ecbcf65621a760d660dcdc656ba5bb). Only the component loader for `*.semantic.xml` preparses declarations. It parses fresh content during loading, reusing Camel’s ordinary XML model parser for the route elements; failed-batch retry coverage checks that corrected declarations are read. _Generated by Codex via /oss-address-review on behalf of [luigidemasi](https://github.com/luigidemasi)._ ########## core/camel-core-model/src/main/java/org/apache/camel/model/app/SemanticQuestionDefinition.java: ########## @@ -0,0 +1,183 @@ +/* + * 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.app; + +import java.util.ArrayList; +import java.util.List; + +import jakarta.xml.bind.annotation.XmlAccessType; +import jakarta.xml.bind.annotation.XmlAccessorType; +import jakarta.xml.bind.annotation.XmlAttribute; +import jakarta.xml.bind.annotation.XmlElement; +import jakarta.xml.bind.annotation.XmlType; + +import org.apache.camel.model.PropertyDefinition; +import org.apache.camel.spi.Metadata; + +/** A semantic question with the same fields and policies as a YAML declaration. */ +@Metadata(label = "configuration") +@XmlType(name = "semanticQuestionDefinition", propOrder = { "instructions", "criteria", "levels" }) +@XmlAccessorType(XmlAccessType.FIELD) +public class SemanticQuestionDefinition { + @XmlAttribute(required = true) + @Metadata(required = true, description = "The context-wide question name.") + private String name; + @XmlAttribute(required = true) + @Metadata(required = true, enums = "boolean,choice,score", description = "The question type.") + private String type; + @XmlAttribute + @Metadata(description = "The Simple expression selecting the message state.") + private String state; + @XmlAttribute + @Metadata(description = "The boolean decision threshold.") + private String threshold; + @XmlAttribute + @Metadata(description = "The boolean uncertainty band.") + private String uncertainty; + @XmlAttribute + @Metadata(enums = "fail,non-match", description = "The boolean uncertainty policy.") + private String uncertaintyPolicy; + @XmlElement(required = true) + @Metadata(required = true, description = "Instructions describing the judgment to make.") + private String instructions; + @XmlElement(name = "criterion") + @Metadata(description = "Named choice criteria, or optional true/false boolean criteria.") + private List<PropertyDefinition> criteria = new ArrayList<>(); + @XmlElement(name = "level") Review Comment: The core declaration model has been removed in [4e03971ee3ec](https://github.com/apache/camel/commit/4e03971ee3ecbcf65621a760d660dcdc656ba5bb). The component fluent helper does not expose its mutable collections, and registration copies validated definitions into the existing immutable `SemanticQuestion` objects. _Generated by Codex via /oss-address-review on behalf of [luigidemasi](https://github.com/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]
