抽象类Advertisemnt中有一个抽象方法
/** * Returns an ID which identifies this { @code Advertisement} as uniquely as * possible. This ID is typically used as the primary key for indexing of * the Advertisement within databases. * <p/> * Each advertisement sub-class must choose an appropriate implementation * which returns canonical and relatively unique ID values for it's * instances. Since this ID is commonly used for indexing, the IDs returned * must be as unique as possible to avoid collisions. The value for the ID * returned can either be: * <p/> * <ul> * <li>An ID which is already part of the advertisement definition * and is relatively unique between advertisements instances. For * example, the Peer Advertisement returns the Peer ID.</li> * * <li>A static CodatID which is generated via some canonical process * which will produce the same value each time and different values for * different advertisements of the same type.</li> * * <li>ID.nullID for advertisement types which are not readily indexed. * </li> * </ul> * <p/> * For Advertisement types which normally return non-ID.nullID values * no ID should be returned when asked to generate an ID while the * Advertisement is an inconsistent state (example: uninitialized index * fields). Instead { @link java.lang.IllegalStateException} should be * thrown. * * @return An ID that relatively uniquely identifies this advertisement * or { @code ID.nullID} if this advertisement is of a type that is not * normally indexed. */ public abstract ID getID();英语不好,对上面的注释不是很理解:对于不需要索引的通告类型,可以将ID设置为ID.nullID,不知道是不是这个意思!
对索引的理解是凡是由getIndexFields返回的字段都是需要索引的
/** * Returns the element names on which this advertisement should be indexed. * * @return The element names on which this advertisement should be indexed. */ public abstract String[] getIndexFields();总结起来就是说,只要你的ID字段名不需要索引(没有通过getIndexFields返回,当然此时也不能通过ID来发现通告了),就可以设置为ID.nullID。
另外注意,自定义通告必须使用以下方法进行注册才能使用:
/** * Register an instantiator for and advertisement type to allow instances * of that type to be created. * * @param rootType the identifying value for this advertisement instance * type. * @param instantiator the instantiator to use in constructing objects * of this rootType. * @return boolean true if the rootType type is registered. If there is * already a constructor for this type then false will be returned. */ public static boolean registerAdvertisementInstance(String rootType, Instantiator instantiator) { boolean result = factory.registerAssoc(rootType, instantiator); return result; }
转载于:https://www.cnblogs.com/cuizhf/archive/2011/09/10/2173010.html
