ConfigurationManager API

来源:互联网 发布:java开发必备技能 编辑:程序博客网 时间:2024/06/11 05:55
<span style="font-size:24px;">class ConfigurationManager implements Cloneable本类的作用:是管理一系列的configurable,包括configurable的属性参数,configurable之间的关系。Configurable可以通过xml文件或编码确定。本类的属性:1,Map<String, PropertySheet> symbolTable:存储了所有的propertysheet,即转变为configurable所需的信息。可以说是configurable表,存储了所有的configurable。2,Map<String, RawPropertyData> rawPropertyMap:存储了所有的rawproperty,即原始的component信息。3,Map<String, String> globalProperties:存储了xml中的globalProperties信息。4,URL configURL  :配置文件存储路径5,showCreations  :是否显示创建信息。6,List<ConfigurationChangeListener> changeListeners:configurable配置(属性)改变的监听器。本类的构造方法:本类的构造方法完成后,只是初始化了(对其属性赋值)configURL,globalProperties,rawPropertyMap,showCreations属性。symbolTable没有进行初始化(没有赋值)。设置了系统配置logger。有一个空的构造方法,将什么也不进行初始化,用于动态的创建configurable。本类一般方法:。1,PropertySheet getPropertySheet(String instanceName):作用是通过component的name获得propertysheet,本方法查看symbolTable是否存在与instancename相对应得propertysheet,有则返回此propertysheet,没有就通过rawpropertyMap获得propertysheet,然后把instancename和propertysheet存入symbolTable中,并返回propertysheet。2,Collection<String> getInstanceNames(Class<? extends Configurable> type):通过symbolTable根据configurable的Class对象名获得实例名(为component中的name值)集合。返回的为symbolTable中所有的component的name值集合。3,Set<String> getComponentNames():获得所有的component的name的集合。4,Configurable lookup(String instanceName):通过instancename,通过getPropertySheet方法获得ps,通过ps获得其owner即configurable。5,<C extends Configurable> C lookup(Class<C> confClass):本法通过getPropertySheet来获得propertysheet列表,获得此列表中的第一个propertysheet,并转换为输入的类型进行输出。6,List<PropertySheet> getPropSheets(Class<? extends Configurable> confClass):本方法获得symbolTable中的所有propertysheet,并放入列表中输出。7,addConfigurable (Class<? extends Configurable> confClass, String name, Map<String, Object> props):添加一个component的信息入symbolTable,rawPropertyMap,并添加监听器为此加入configurable。如果要添加的原本在symbolTable中存在则会发生异常。8,addConfigurable(Configurable configurable, String name):与7一样只是输入参数不同。9,renameConfigurable(String oldName, String newName):改变的是symbolTable,rawPropertyMap中的configurable的对应的名字,其监听改变成对新名字的监听。10,removeConfigurable(String name):symbolTable,rawPropertyMap移除与name相对应的configurable(component)信息,并移除相应的监听器。addSubConfiguration(ConfigurationManager subCM, boolean doOverrideComponents):本方法输入的ConfigurationManager(必须是non-instantiated)中的中的symbolTable,rawPropertyMap,globalProperties中的内容放入本ConfigurationManager的相应属性中。11,Map<String, String> getGlobalProperties():获得CM中的globalProperties的所有内容。即获得CM的globalProperties。12,String getGlobalProperty(String propertyName):根据propertyName,获得某一确定的GlobalProperty。Configurable属性。13,String getGloPropReference(String propertyName):返回的为globalProperties.get(propertyName),即与getGlobalProperty一样。14,URL getConfigURL():若通过xml配置的,返回其URL路径,动态配置返回为null。15,setGlobalProperty(String propertyName, String value):若输入value为null,则移除此GlobalProperty,否则就设置把相应的propertyName的value设置成此值。并且对使用了此GlobalProperty的所有propertysheet和configurable进行更新。16,String getStrippedComponentName(String propertyName):返回的是globalProperty的value值,作用是某些component中使用了globalProperty的值是以${}形式,本方法是用globalProperty的value来代替${}形式。17,addConfigurationChangeListener(ConfigurationChangeListener l):为CM添加监听器。18,removeConfigurationChangeListener(ConfigurationChangeListener l):移除监听器。19,void fireConfChanged(String configurableName, String propertyName):{        assert getComponentNames().contains(configurableName);        for (ConfigurationChangeListener changeListener : changeListeners)            changeListener.configurationChanged(configurableName, propertyName, this);    }20,void fireRenamedConfigurable(String oldName, String newName) {        assert getComponentNames().contains(newName);        for (ConfigurationChangeListener changeListener : changeListeners) {            changeListener.componentRenamed(this, getPropertySheet(newName), oldName);        }    }21,ConfigurationManager clone():把本CM的changeListeners,symbolTable,globalProperties,rawPropertyMap都放入进新的CM中。22,static <C extends Configurable> C getInstance(Class<C> targetClass):本方法得到一个targetClass的Class对象的类或接口。23,static <C extends Configurable> C getInstance(Class<C> targetClass, Map<String, Object> props):与22一样。24,static <C extends Configurable> C getInstance(Class<C> targetClass, Map<String, Object> props, String compName):与22一样。25,static PropertySheet getPropSheetInstanceFromClass(Class<? extends Configurable> targetClass, Map<String, Object> defaultProps, String componentName, ConfigurationManager cm):本方法返回new PropertySheet(targetClass, componentName, cm, rpd)。即根据Class对象,component名字,CM,得到一个,defaultprops都放入了rpd中。26,Logger getRootLogger():通得根logger。</span>

0 0