Package io.jmix.aichat.xml.layout.loader
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 Summary
FieldsModifier and TypeFieldDescriptionprotected static final Stringprotected Actionsprotected org.springframework.context.ApplicationContextprotected static final Stringprotected static final Stringprotected ComponentLoader.Contextprotected static final Stringprotected static final Stringprotected static final Stringprotected @Nullable IconLoaderSupportprotected static final Stringprotected @Nullable LayoutLoaderprotected LoaderSupportprotected static final Stringprotected static final Stringprotected static final Stringprotected Collection<ComponentLoader<?>> protected static final Stringprotected static final Stringprotected ActionCustomPropertyLoaderprotected static final Stringprotected static final Stringprotected static final Stringprotected static final Stringprotected static final String -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidcheckUniqueMessageActionIds(List<AiMessageAction<?>> userActions, List<AiMessageAction<?>> assistantActions, Collection<Action> componentActions) Verifies that every declared message action id is unique within its host.voidcreateClearableSlot(org.dom4j.Element parentElement, String elementName, Consumer<@Nullable com.vaadin.flow.component.Component> setter) AcreateSlot(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).protected AiMessageAction<?> createMessageAction(String typeId, String id, String containerName) voidcreateSlot(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 toloadSlots().protected voidcreateSlotComponent(org.dom4j.Element slotElement, String elementName, Consumer<@Nullable com.vaadin.flow.component.Component> setter) @Nullable org.dom4j.ElementgetI18nElement(org.dom4j.Element parentElement) Returns the nestedi18nelement, ornullwhen the component declares none.protected IconLoaderSupportprotected LayoutLoaderprotected voidloadActionProperties(org.dom4j.Element actionElement, AiMessageAction<?> action) voidloadChatLabels(org.dom4j.Element element, AiChatI18n i18n) Applies the chat's own announcements declared on the given element, and the labels of its nestedmessageInputandmessageListelements — the localization of the two components the chat composes, which its bean holds as their own beans rather than restating.voidloadCodeBlockLabels(org.dom4j.Element element, AiCodeBlockI18n i18n) Applies the code block's labels declared on the given element.voidReads one label attribute of ani18nelement, resolving amsg://key against the descriptor's message group.protected AiMessageAction<?> loadMessageAction(org.dom4j.Element actionElement, String containerName) voidloadMessageActions(org.dom4j.Element parentElement, String elementName, Consumer<List<AiMessageAction<?>>> setter) Loads the actions of one message role.voidloadMessageInputLabels(org.dom4j.Element element, AiMessageInputI18n i18n) Applies the message input's labels declared on the given element.voidloadMessageListLabels(org.dom4j.Element element, AiMessageListI18n i18n) Applies the message list's labels declared on the given element, and those of its nestedcodeBlockelement.protected <T> voidloadNested(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.voidLoads the components created bycreateSlot(org.dom4j.Element, java.lang.String, java.util.function.Consumer<com.vaadin.flow.component.Component>)— the second phase.voidloadThinkingStages(org.dom4j.Element parentElement, Consumer<List<ThinkingStage>> setter) Loads the escalating thinking stages.voidsetApplicationContext(org.springframework.context.ApplicationContext applicationContext)
-
Field Details
-
I18N_ELEMENT_NAME
- See Also:
-
CODE_BLOCK_ELEMENT_NAME
- See Also:
-
MESSAGE_INPUT_ELEMENT_NAME
- See Also:
-
MESSAGE_LIST_ELEMENT_NAME
- See Also:
-
THINKING_STAGES_ELEMENT_NAME
- See Also:
-
THINKING_STAGE_ELEMENT_NAME
- See Also:
-
ACTION_ELEMENT_NAME
- See Also:
-
PROPERTIES_ELEMENT_NAME
- See Also:
-
PROPERTY_ELEMENT_NAME
- See Also:
-
DELAY_MILLIS_ATTRIBUTE_NAME
- See Also:
-
TEXT_ATTRIBUTE_NAME
- See Also:
-
ID_ATTRIBUTE_NAME
- See Also:
-
TYPE_ATTRIBUTE_NAME
- See Also:
-
DESCRIPTION_ATTRIBUTE_NAME
- See Also:
-
CLASS_NAMES_ATTRIBUTE_NAME
- See Also:
-
NAME_ATTRIBUTE_NAME
- See Also:
-
VALUE_ATTRIBUTE_NAME
- See Also:
-
context
-
pendingLoadComponents
-
applicationContext
protected org.springframework.context.ApplicationContext applicationContext -
loaderSupport
-
actions
-
propertyLoader
-
layoutLoader
-
iconLoaderSupport
-
-
Constructor Details
-
AiComponentLoaderSupport
- Parameters:
context- the loader context this support object reads from
-
-
Method Details
-
setApplicationContext
public void setApplicationContext(org.springframework.context.ApplicationContext applicationContext) - Specified by:
setApplicationContextin interfaceorg.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 toloadSlots(). 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 elementelementName- the slot element namesetter- 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) AcreateSlot(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 usecreateSlot(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 elementelementName- the slot element namesetter- the setter to feed the loaded component to
-
createSlotComponent
-
loadSlots
public void loadSlots()Loads the components created bycreateSlot(org.dom4j.Element, java.lang.String, java.util.function.Consumer<com.vaadin.flow.component.Component>)— the second phase. -
getI18nElement
public @Nullable org.dom4j.Element getI18nElement(org.dom4j.Element parentElement) Returns the nestedi18nelement, ornullwhen the component declares none.Every caller then edits the localization the component already carries instead of building a fresh bean: the
setI18nsetters 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 themessages.propertiesvalue.- Parameters:
parentElement- the component's element- Returns:
- the
i18nelement, ornull
-
loadLabel
Reads one label attribute of ani18nelement, resolving amsg://key against the descriptor's message group. An absent attribute leaves the setter untouched.- Parameters:
i18nElement- thei18nelement (or a nested one, such ascodeBlock)attributeName- the attribute namesetter- the setter to feed the resolved label to
-
loadCodeBlockLabels
Applies the code block's labels declared on the given element. One method per*I18nbean, 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 labelsi18n- the bean to apply them to
-
loadMessageInputLabels
Applies the message input's labels declared on the given element.- Parameters:
element- the element carrying the labelsi18n- the bean to apply them to
-
loadMessageListLabels
Applies the message list's labels declared on the given element, and those of its nestedcodeBlockelement.- Parameters:
element- the element carrying the labelsi18n- the bean to apply them to
-
loadChatLabels
Applies the chat's own announcements declared on the given element, and the labels of its nestedmessageInputandmessageListelements — 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 labelsi18n- 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 elementelementName- the nested element namegetter- the host's current nested beanfactory- creates the nested bean when the host carries nonesetter- attaches a freshly created nested bean to the hostlabelLoader- 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 absentthinkingStageselement 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 elementsetter- 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
actionwith atypeis created through theActionsregistry and must be anAiMessageAction; one without a type becomes a bareAiMessageActionthat does nothing until a controller subscribes to it. Ids must be unique within the container.- Parameters:
parentElement- the component's elementelementName- the container element namesetter- the setter to feed the loaded actions to
-
loadMessageAction
protected AiMessageAction<?> loadMessageAction(org.dom4j.Element actionElement, String containerName) -
createMessageAction
-
loadActionProperties
-
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 throughgetSubPart, 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 actionsassistantActions- the loaded assistant-message actionscomponentActions- the host's component-level actions, or an empty collection
-
getLayoutLoader
-
getIconLoaderSupport
-