实现存储配置类 |
实现了扩展的json存储方式后,还需要为其实现一个配置类,用于指定json存储配置,包括磁盘存储位置等。您在iServer中使用扩展的json存储方式时,就可以通过指定这个配置类,使扩展生效。iServer提供了自定义存储扩展的配置接口 CustomSecurityInfoStorageSetting,基于该接口可实现自定义的存储配置类。
扩展形式如:
public class JsonStorageSetting extends CustomSecurityInfoStorageSetting{ ... }
该配置类想要指定扩展类型和json的存储位置,需要实现两个参数:
public JsonStorageSetting() { super(); this.type = SecurityInfoStorageType.CUSTOM; }
public JsonStorageSetting(JsonStorageSetting jsonStorageSetting) { super(jsonStorageSetting); this.outputDirectory = jsonStorageSetting.outputDirectory; } @Override public SecurityInfoStorageSetting copy() { return new JsonStorageSetting(this); }
完整扩展示例代码如下:
package com.supermap.server.config; import org.apache.commons.lang.builder.EqualsBuilder; import org.apache.commons.lang3.builder.HashCodeBuilder; public class JsonStorageSetting extends CustomSecurityInfoStorageSetting { private static final long serialVersionUID = 1L; public String outputDirectory; public JsonStorageSetting() { super(); this.type = SecurityInfoStorageType.CUSTOM; } public JsonStorageSetting(JsonStorageSetting jsonStorageSetting) { super(jsonStorageSetting); this.outputDirectory = jsonStorageSetting.outputDirectory; } @Override public boolean equals(Object objToEqual) { if (objToEqual == null) { return false; } if (!(objToEqual instanceof JsonStorageSetting)) { return false; } JsonStorageSetting obj = (JsonStorageSetting) objToEqual; EqualsBuilder builder = new EqualsBuilder(); builder.append(this.outputDirectory, obj.outputDirectory); return builder.isEquals(); } @Override public int hashCode() { HashCodeBuilder builder = new HashCodeBuilder().appendSuper(super.hashCode()).append(this.outputDirectory); return builder.toHashCode(); } @Override public SecurityInfoStorageSetting copy() { return new JsonStorageSetting(this); } }