在这里,使用抽象的 BaseTrackingObject 类来定义通用的跟踪数据,如修改用户、修
改日期、修改原因等。其中定义了设置和取得 objectId 抽象方法,把它用作主键来访问领域
对象;定义了一个命名为 getXmlRepresentation 的工具方法,用于把对象转换成 XML 格
式,进而用于在 Subversion 中存储和检索数据。
SVNManager 类是通向 Subversion 的路由,用于在不使用工作拷贝的情况下,通过
底层 JavaSVN 接口直接访问 Subversion 仓库,通过初始化 JavaSVN 类库来可以使用
HTTP(S)或 SVN(S)与 Subversion 仓库进行交互。在这里,我们选择使用 HTTP (WebDAV),
因为可以减少在处理防火墙方面的工作。
库的初始化工作要首先调用的是方法 DAVRepositoryFactory.setup()。SVNRepository
类包含了所有直接访问 Subversion 仓库的方法,将 Subversion 仓库树状结构的根路径提供
给 SVNRepositoryFactory 类后,就完成了这个类的初始化,而 ISVNAuthenticationManager
类的作用是向 SVNRepository 提供访问 Subversion 仓库的授权信息。
public void initRepository() {
//initialize the system to work over http
DAVRepositoryFactory.setup();
............
//point to the root folder of repository
SVNURL svnUrl = SVNURL.parseURIEncoded
("http://localhost/repos/");
//initialize the SVNRepository
theRepository = SVNRepositoryFactory.
create(svnUrl);
//Creates the Auth manager with our user
//and password credentials
ISVNAuthenticationManager authManager =
new BasicAuthenticationManager
(name, password);
//provides the credentials to the
//SVNRepository
theManager.setAuthenticationManager
(authManager);