HDFS文件系统浏览器的配置设置分为两部分,一个是配置的基础类,涉及到对象的持久化写入,该部分定义相关的接口和抽象类的实现;另一部分是具体的对象持久化配置,包括HDFS连接配置持久化和整个系统的通用配置(国际化多语言的支持和文件树展现方式)持久化。本节讲解配置的基础类。 配置的基础类,定义在core 包中。整个的类的关系图如下:
定义持久化配置接口PersistentConfiguration 该接口定义读取和写入持久化配置方法:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 public interface PersistentConfiguration { void readConfiguration (Element paramElement) ; void writeConfiguration (Element paramElement) ; }
定义Boolean、Enum、Int、String类型的对象持久化 这些对象,继承了抽象类Setting,并且实现了PersistentConfiguration接口。抽象类Setting,代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 public abstract class Setting <T , E > { private T value; private String name; protected Setting (String configName, T value) { this .name = configName; this .value = value; } public String getName () { return this .name; } public T value () { return this .value; } public boolean setValue (T value) { boolean response = !CommonUtil.safeEqual(this .value, value); this .value = value; return response; } public T getValue () { return this .value; } public String toString () { return "[" + getClass().getSimpleName() + "] " + this .name + " = " + this .value; } public abstract boolean to (E paramE) throws ConfigurationException ; public abstract void from (E paramE) ; }
定义抽象配置类Configuration 抽象类Configuration是一个抽象的泛型类,创建和读取配置的主窗体UI对象:ConfigurationEditorForm,同时也继承了ConfigurationUtil类。 ConfigurationEditorForm类是配置的UI对象的抽象类,所有配置的UI对象都需要实现该类。该类继承了通用窗体类FileSystemBaseFormImpl。
ProjectConfiguration 为工程配置抽象类,继承了配置Configuration,泛型类,定义了获取当前的工程Project。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 public abstract class ProjectConfiguration <T extends ConfigurationEditorForm > extends Configuration <T > implements ProjectSupplier { private Project project; public ProjectConfiguration (Project project) { this .project = project; } public Project getProject () { return this .project; } }
CompositeConfigurationEditorForm 类为配置集合类,插件的配置分为多个项,因此需要将多个配置组合到一起。代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 public abstract class CompositeConfiguration <T extends CompositeConfigurationEditorForm > extends Configuration <T > { private Configuration[] configurations; public final Configuration[] getConfigurations() { if (this .configurations == null ) { this .configurations = createConfigurations(); } return this .configurations; } protected abstract Configuration[] createConfigurations(); public final boolean isModified () { for (Configuration configuration : getConfigurations()) { if (configuration.isModified()) { return true ; } } return super .isModified(); } public void apply () throws ConfigurationException { T settingsEditor = (T) getSettingsEditor(); if (((this instanceof TopLevelConfig)) && (settingsEditor != null )) { GUIUtil.stopTableCellEditing(settingsEditor.getComponent()); } for (Configuration configuration : getConfigurations()) { configuration.apply(); } super .apply(); onApply(); } public final void reset () { for (Configuration configuration : getConfigurations()) { configuration.reset(); } super .reset(); } public void disposeUIResources () { for (Configuration configuration : getConfigurations()) { configuration.disposeUIResources(); } super .disposeUIResources(); } public void readConfiguration (Element element) { Configuration[] configurations = getConfigurations(); for (Configuration configuration : configurations) { readConfiguration(element,configuration); } } public void writeConfiguration (Element element) { Configuration[] configurations = getConfigurations(); for (Configuration configuration : configurations) { writeConfiguration(element,configuration); } } }
基础配置部分大致就这么多了,下一节,具体分析一下各个配置项。