动机:在Cougaar中,已经提供了一些标准的AspectType和AspectValue。但在实际的应用中,可能需要定制特殊的
AspectType和AspectValue.
实现步骤:
1、在Domain类中定义特殊的AspectValue和AspectType相关的信息, 并注册AspectValue相应的Factory
Domain类要继承DomainAdapter, 核心代码如下:
public class PersistenceDomain extends DomainAdapter {
//Aspect Type Factories
/** DbChange Aspect */
Factory DbChange = new Factory() {
public int getKey() {return PersistenceDomainUtil.DBCHANGE_ASPECT;}
public String getName() {return "DBCHANGE";}
public AspectValue newAspectValue(Object o) {
return DoubleAspectValue.create(PersistenceDomainUtil.DBCHANGE_ASPECT, o);
}
};
/**
* Load the domain and custom aspect types used throughout BOL
*/
public void load() {
super.load();
loadCustomAspectTypes();
}
/**
* Load Custom AspectType Factories
*/
private void loadCustomAspectTypes() {
if (AspectType.registry.get(PersistenceDomainUtil.DBCHANGE_ASPECT) == null) {
AspectType.registry.registerFactory(DbChange);
}
}
....
}
其中PersistenceDomainUtil.DBCHANGE_ASPECT的值是:
public static final int DBCHANGE_ASPECT = AspectType.ASPECT_STRINGS.length + 2;
2、注册Domain类
在LDMDomains.ini文件中增加一项:
PersistenceDomain=com.justep.business.content.model.persistence.domain.PersistenceDomain