附录编辑:
由于没有经验丰富的 Spring Framework 开发人员的任何反馈,因此尚未接受对此的回答。
我一直在研究用于 Spring-Framework applicationContext.xml 文件的替代 DSL(其中描述了 bean 初始化和依赖关系以加载到 Spring bean 工厂中)。
我的动机是我完全不喜欢 Spring 为此目的使用 XML,也不喜欢迄今为止设计的任何替代方案。出于各种我不会深入讨论的原因,我想继续使用声明性语言,而不是像 Groovy 这样的命令式脚本语言。
所以我抓住了 ANTLR 解析器工具,并一直在设计一个新的 bean factory DSL,我称之为 SFig。这是一个有关此内容的链接:
SFig™ - Spring-Framework 的替代元数据配置语言
这是源代码存储库站点:
http://code.google.com/p/sfig/
我很想知道到目前为止我在语言语法上的表现如何。您认为 SFig 既高效又清晰易懂?(我现在特别关心多行文本字符串):
properties_include "classpath:application.properties";
org.apache.commons.dbcp.BasicDataSource dataSource {
@scope = singleton;
@destroy-method = close;
driverClassName = "${jdbc.driverClassName}";
url = "${jdbc.url}";
username = "${jdbc.username}";
password = "${jdbc.password}";
defaultAutoCommit = true;
}
org.springframework.orm.ibatis.SqlMapClientFactoryBean sqlMapClient {
@scope = singleton;
@init-method = afterPropertiesSet;
@factory-method = getObject;
configLocation = "classpath:sqlmap-config.xml";
dataSource = $dataSource;
}
/* this string will have Java unescape encoding applied */
STRING str = "\tA test\u0020string with \\ escaped character encodings\r\n";
/* this string will remain literal - with escape characters remaining in place */
STRING regexp = @"(\$\{([a-zA-Z][a-zA-Z0-9._]*)\})";
/* multi-line text block - equates to a java.lang.String instance */
TEXT my_multi_line_text = ///
Here is a line of text.
This is yet another. Here is a blank line:
Now picks up again.
///;
/* forward use of 'props' bean */
java.util.HashMap map {
this( $props );
}
/* equates to a java.util.Propertis instance */
PROPERTIES props {
"James Ward" = "Adobe Flex evangelist";
"Stu Stern" = "Gorilla Logic - Flex Monkey test automation";
Dilbert = "character in popular comic strip of same title";
"App Title Display" = "Application: ${app.name}";
"${app.desc}" = "JFig processes text-format Java configuration data";
}
/* equates to a java.util.ArrayList instance */
LIST list {
this( ["dusty", "moldy", "${app.version}", $str] );
[234, 9798.76, -98, .05, "numbers", $props, ["red", "green", "blue"]];
}