Class AiComponentLoaderSupport

java.lang.Object
io.jmix.aichat.xml.layout.loader.AiComponentLoaderSupport
All Implemented Interfaces:
org.springframework.beans.factory.Aware, org.springframework.context.ApplicationContextAware

@Component("aichat_AiComponentLoaderSupport") @Scope("prototype") public class AiComponentLoaderSupport extends Object implements org.springframework.context.ApplicationContextAware
Support for this add-on's component loaders: the single-component slots and the structured children shared by aiMessageList and aiChat.
  • Field Details

  • Constructor Details

    • AiComponentLoaderSupport

      public AiComponentLoaderSupport(ComponentLoader.Context context)
      Parameters:
      context - the loader context this support object reads from
  • Method Details

    • setApplicationContext

      public void setApplicationContext(org.springframework.context.ApplicationContext applicationContext)
      Specified by:
      setApplicationContext in interface org.springframework.context.ApplicationContextAware
    • createSlot

      public void createSlot(org.dom4j.Element parentElement, String elementName, Consumer<@Nullable com.vaadin.flow.component.Component> setter)
      Creates the component declared in a single-component slot element and hands it to the setter, deferring the child's own loading to loadSlots(). Exactly one child component is required, matching the framework's prefix/suffix loading; an absent element leaves whatever the component already had.
      Parameters:
      parentElement - the component's element
      elementName - the slot element name
      setter - the setter to feed the loaded component to
    • createClearableSlot

      public void createClearableSlot(org.dom4j.Element parentElement, String elementName, Consumer<@Nullable com.vaadin.flow.component.Component> setter)
      A createSlot(org.dom4j.Element, java.lang.String, java.util.function.Consumer<com.vaadin.flow.component.Component>) variant for slots with a built-in default: an empty element is not an error but the declarative spelling of "nothing in this slot" — the only way to clear such a default (the message list's thinking indicator). Slots without a default must use createSlot(org.dom4j.Element, java.lang.String, java.util.function.Consumer<com.vaadin.flow.component.Component>), where an empty element fails instead of silently loading nothing.
      Parameters:
      parentElement - the component's element
      elementName - the slot element name
      setter - the setter to feed the loaded component to
    • createSlotComponent

      protected void createSlotComponent(org.dom4j.Element slotElement, String elementName, Consumer<@Nullable com.vaadin.flow.component.Component> setter)
    • loadSlots

      public void loadSlots()
    • getI18nElement

      public @Nullable org.dom4j.Element getI18nElement(org.dom4j.Element parentElement)
      Returns the nested i18n element, or null when the component declares none.

      Every caller then edits the localization the component already carries instead of building a fresh bean: the setI18n setters replace the whole object, so a bean built from the element alone would null out every label the element does not declare, reverting those to the client's hardcoded English rather than keeping the messages.properties value.

      Parameters:
      parentElement - the component's element
      Returns:
      the i18n element, or null
    • loadLabel

      public void loadLabel(org.dom4j.Element i18nElement, String attributeName, Consumer<String> setter)
      Reads one label attribute of an i18n element, resolving a msg:// key against the descriptor's message group. An absent attribute leaves the setter untouched.
      Parameters:
      i18nElement - the i18n element (or a nested one, such as codeBlock)
      attributeName - the attribute name
      setter - the setter to feed the resolved label to
    • loadCodeBlockLabels

      public void loadCodeBlockLabels(org.dom4j.Element element, AiCodeBlockI18n i18n)
      Applies the code block's labels declared on the given element. One method per *I18n bean, mirroring its fields, so the element and the bean stay in step — and, because the beans nest, so does every host that reuses this one.
      Parameters:
      element - the element carrying the labels
      i18n - the bean to apply them to
    • loadMessageInputLabels

      public void loadMessageInputLabels(org.dom4j.Element element, AiMessageInputI18n i18n)
      Applies the message input's labels declared on the given element.
      Parameters:
      element - the element carrying the labels
      i18n - the bean to apply them to
    • loadMessageListLabels

      public void loadMessageListLabels(org.dom4j.Element element, AiMessageListI18n i18n)
      Applies the message list's labels declared on the given element, and those of its nested codeBlock element.
      Parameters:
      element - the element carrying the labels
      i18n - the bean to apply them to
    • loadChatLabels

      public void loadChatLabels(org.dom4j.Element element, AiChatI18n i18n)
      Applies the chat's own announcements declared on the given element, and the labels of its nested messageInput and messageList elements — the localization of the two components the chat composes, which its bean holds as their own beans rather than restating.
      Parameters:
      element - the element carrying the labels
      i18n - the bean to apply them to
    • loadNested

      protected <T> void loadNested(org.dom4j.Element parentElement, String elementName, Supplier<@Nullable T> getter, Supplier<T> factory, Consumer<T> setter, BiConsumer<org.dom4j.Element,T> labelLoader)
      Applies a nested localization element to the host bean's corresponding nested bean. An absent element leaves that bean alone; an absent bean — a host built by hand rather than resolved from the bundle — is allocated first, so the element is never dropped.
      Type Parameters:
      T - the nested bean type
      Parameters:
      parentElement - the host's localization element
      elementName - the nested element name
      getter - the host's current nested bean
      factory - creates the nested bean when the host carries none
      setter - attaches a freshly created nested bean to the host
      labelLoader - applies the element's labels to the nested bean
    • loadThinkingStages

      public void loadThinkingStages(org.dom4j.Element parentElement, Consumer<List<ThinkingStage>> setter)
      Loads the escalating thinking stages. An absent thinkingStages element keeps the component's localized defaults; a present one replaces them wholesale, so an empty element means "no escalating labels".
      Parameters:
      parentElement - the component's element
      setter - the setter to feed the loaded stages to
    • loadMessageActions

      public void loadMessageActions(org.dom4j.Element parentElement, String elementName, Consumer<List<AiMessageAction<?>>> setter)
      Loads the actions of one message role. An absent container keeps the component's own actions; a present one replaces them, so an empty element means "no actions".

      An action with a type is created through the Actions registry and must be an AiMessageAction; one without a type becomes a bare AiMessageAction that does nothing until a controller subscribes to it. Ids must be unique within the container.

      Parameters:
      parentElement - the component's element
      elementName - the container element name
      setter - the setter to feed the loaded actions to
    • loadMessageAction

      protected AiMessageAction<?> loadMessageAction(org.dom4j.Element actionElement, String containerName)
    • createMessageAction

      protected AiMessageAction<?> createMessageAction(String typeId, String id, String containerName)
    • loadActionProperties

      protected void loadActionProperties(org.dom4j.Element actionElement, AiMessageAction<?> action)
    • checkUniqueMessageActionIds

      public void checkUniqueMessageActionIds(List<AiMessageAction<?>> userActions, List<AiMessageAction<?>> assistantActions, Collection<Action> componentActions)
      Verifies that every declared message action id is unique within its host. A duplicate is a load error rather than a caveat: a controller resolves an action by id through getSubPart, which can return only one instance, so a shared id would silently bind a subscription to one of two actions.
      Parameters:
      userActions - the loaded user-message actions
      assistantActions - the loaded assistant-message actions
      componentActions - the host's component-level actions, or an empty collection
    • getLayoutLoader

      protected LayoutLoader getLayoutLoader()
    • getIconLoaderSupport

      protected IconLoaderSupport getIconLoaderSupport()