XWorker
LOGO
LOGO
XWorker与动态模型
基于认知的抽象编程框架
动态模型简介
T
事物(Thing)
模型是结构化的数据(如XML/JSON),表示系统中的各种实体。通过树形结构组织属性、行为和子节点。
A
动作(Action)
任何模型都可转化为可执行函数。通过递归解释最终调用底层语言(如Java)执行,实现模型的行为逻辑。
C
认知驱动
从认知角度出发:事物可先于类存在,通过面向对象方法动态认知和使用系统实体,实现灵活的系统建模。
动态模型抽象层
应用层
用户业务逻辑实现
(Person/SayHello等)
(Person/SayHello等)
↓
动态模型层
模型(Thing) ↔ 动作(Action)
转换与执行
转换与执行
↓
编程语言层
底层执行引擎
(Java/Groovy等)
(Java/Groovy等)
↑ 模型解释
↓ 动作执行
动态模型基本概念
T
模型(Thing)
结构化的树形数据(XML/JSON),表示系统中的各种实体
<Person name="zhangsan" age="40">
<Child name="xiaoming"/>
</Person>
A
动作(Action)
任何模型都可转化为可执行函数
<GroovyAction
name="helloWorld"
code="println "hello world""/>
C
动作上下文(ActionContext)
存储变量和维护执行状态的上下文环境
// 变量存取示例
actionContext.put("user", zhangsan)
actionContext.get("user").helloWorld()
W
世界(World)
模型的容器,通过路径获取模型
// 获取模型示例
Person zhangsan = world.getThing(
"xworker.doc.examples.Person"
)
面向对象:模型即对象
Person对象模型
<Person name="zhangsan" age="40">
<actions>
<GroovyAction name="helloWorld"
code="println "e;hello world"e;"/>
</actions>
</Person>
对象结构解析
Person 对象
P
属性 (Properties)
-
name"zhangsan"
-
age40
B
行为 (Behaviors)
helloWorld()
println "hello world"
模型 = 结构化数据 = 对象
面向对象:类型与继承
Person实例(对象)
<Person name="Zhangsan"
descriptors="xworker.doc.dyanmicmodel.examples.Person"
age="40" sex="0">
<Child name="Xiaoming" age="10" sex="0"/>
<Child name="Lili" age="5" sex="1"/>
</Person>
继承
↑ 继承 ↓
Person描述者(类)
<thing name="Person" descriptors="xworker.lang.MetaDescriptor3">
<actions>
<GroovyAction name="sayHello"
code="println self.name + " say hello world";"/>
</actions>
<attribute name="name"/>
<attribute name="age"/>
<attribute name="sex" inputtype="select">
<value name="男" value="0"/>
<value name="女" value="1"/>
</attribute>
<thing name="Child"
extends="xworker.doc.dyanmicmodel.examples.Person">
⚠️
</thing>
</thing>
⚠️
菱形继承问题解决方案
顺序原则
按定义顺序查找继承关系
单次使用原则
每个模型在继承链中只使用一次
模型解释与执行
模型执行流程
1
模型(Thing)
结构化数据表示对象或行为
↓
2
行为查找
查找模型对应的run方法
↓
3
动作转换
将模型转化为可执行动作
↓
4
执行终止
⏹️
JavaAction直接执行
递归到元语言(Java)层执行
X-Meta引擎架构
应用层
用户定义的模型(Things)
↓
动态模型层
• 模型解释引擎
• 动作转换器
• 动作上下文管理
↓
执行层
• JavaAction执行器
• Groovy等脚本引擎
• 原生Java代码执行
实现与应用
1
数字化编程
- 基础模型封装 - Java类库包装为可执行模型
- GroovyAction→JavaAction执行链 - 脚本到原生代码的无缝转换
- 动态更新 - 模型修改后实时生效
2
高层模型
- 模型组合 - 已有模型构建新模型
- 模型编辑器配置抽象 - 简化复杂编辑器创建
- 渐进抽象 - 高层次模型实现丰富功能
3
AI集成
- 元模型扩展 - 新增ai_needGenerate等属性
- AI作为第二语言 - 动态模型与AI自然交互
- 即时生成 - ai_generate()动态创建内容
XWorker技术栈
G
Groovy
W
Web
S
SWT
J
JavaFX
A
AI
N
Netty
J
Jetty
F
FFmpeg
元模型
XML结构自解释过程
Person模型
<Person name="Zhangsan">
<Child name="Xiaoming"/>
</Person>
<Child name="Xiaoming"/>
</Person>
↓
结构定义模型
<thing name="Person">
<attribute name="name"/>
<thing name="Child">
<attribute name="name"/>
</thing>
</thing>
<attribute name="name"/>
<thing name="Child">
<attribute name="name"/>
</thing>
</thing>
↓
元模型(Thing)
<thing name="thing">
<attribute name="name"/>
<thing name="attribute">...</thing>
<thing name="thing" extends="_root"/>
</thing>
<attribute name="name"/>
<thing name="attribute">...</thing>
<thing name="thing" extends="_root"/>
</thing>
"无名天地之始" → 元模型
"道生一" → thing自指
最终元模型XML
<?xml version='1.0' encoding='utf-8'?>
<thing name="thing" descriptors="xworker.lang.MetaDescriptor3">
<attribute name="name"/>
<attribute name="extends"/>
<thing name="attribute">
<attribute name="name"/>
</thing>
<thing name="thing" extends="_root"/>
<!-- 元模型扩展的AI属性 -->
<attribute name="ai_needGenerate">
<annotation>设置需要AI生成</annotation>
</attribute>
<attribute name="ai_promptContainsVars">
<annotation>是否包含变量描述</annotation>
</attribute>
<attribute name="ai_promptSystem">
<annotation>AI角色设定提示词</annotation>
</attribute>
<attribute name="ai_promptRequirement">
<annotation>用户需求描述</annotation>
</attribute>
<attribute name="ai_getPromptFormat">
<annotation>AI输出格式要求</annotation>
</attribute>
<!-- 元模型扩展的AI方法 -->
<actions>
<JavaAction name="ai_isNeedGenerate">
<annotation>检查是否需要AI生成</annotation>
</JavaAction>
<JavaAction name="ai_generate">
<annotation>执行AI生成过程</annotation>
</JavaAction>
<JavaAction name="ai_onResult">
<annotation>处理AI生成结果</annotation>
</JavaAction>
<JavaAction name="ai_execute">
<annotation>执行AI生成后的操作</annotation>
</JavaAction>
<JavaAction name="ai_getChatService">
<annotation>获取聊天服务实例</annotation>
</JavaAction>
<JavaAction name="ai_getPromptSystem">
<annotation>获取系统提示词</annotation>
</JavaAction>
<JavaAction name="ai_getPromptFormat">
<annotation>获取输出格式要求</annotation>
</JavaAction>
<JavaAction name="ai_getPromptRequirement">
<annotation>获取用户需求</annotation>
</JavaAction>
<JavaAction name="ai_getContent">
<annotation>获取待编辑内容</annotation>
</JavaAction>
<JavaAction name="ai_getPrompt">
<annotation>生成完整AI提示词</annotation>
</JavaAction>
</actions>
</thing>
XWorker简介
在动态模型生态中的位置
应用层
终端/模型编辑器/AI集成应用
↓
引擎层
X-Meta动态模型引擎
↓
编程语言层
Java实现基础功能
技术封装能力
G
Groovy
W
Web
S
SWT
J
JavaFX
A
AI
N
Netty
运行时动态编程
模型修改后实时生效,无需重启系统
AI集成
元模型新增属性与方法
属性 (5个)
属性名 | 功能说明 |
---|---|
ai_needGenerate | 设置需要AI生成内容 |
ai_promptContainsVars | 提示词是否包含上下文变量 |
ai_promptSystem | AI角色设定提示词 |
ai_promptRequirement | 用户需求描述 |
ai_getPromptFormat | AI输出格式要求 |
方法 (7个)
方法名 | 功能说明 |
---|---|
ai_isNeedGenerate() | 检查是否需要AI生成 |
ai_generate() | 执行AI生成过程 |
ai_onResult() | 处理AI生成结果 |
ai_execute() | 执行AI生成后操作 |
ai_getChatService() | 获取聊天服务实例 |
ai_getContent() | 获取待编辑内容 |
ai_getPrompt() | 生成完整AI提示词 |
AI工作流程
1
需求输入
用户通过ai_promptRequirement定义需求
↓
2
提示词生成
ai_getPrompt()生成完整提示词
↓
3
AI执行
ai_generate()调用AI服务
↓
4
结果回调
ai_onResult()处理返回内容
AI即编程