Good idea, failed product-PropertySet
PropertySet is indeed a good thing. As for how good it is, I will not say it. Let's see it on your own.
However, PropertySet does make me very angry. I did not succeed in the experiment for one night, but the problem lies in its source code! Let me talk about it slowly.
How simple is the simplest example? Look at the configuration file and you will know:
<Propertysets>
<Propertyset name = "myBean" class = "testLab. MyBean">
<Arg name = "myInt" value = "57"/>
<Arg name = "myString" value = "na57"/>
</Propertyset>
</Propertysets>
This example is just to read the values I need from the configuration file. My test code is as follows:
PropertySet ps = PropertySetManager. getInstance ("myBean", null );
System. out. print (ps. getString ("myString "));
Assert. assertEquals ("na57", ps. getString ("myString "));
The result failed. Where is the failure? I checked the PropertySet Code while keeping my code safe. The implementation of the PropertySet interface is the MemoryPropertySet class, so I first found the code for reading data in this class:
Public String getString (String key ){
Try {
Return (String) get (STRING, key );
} Catch (NullPointerException e ){
Return null;
}
}
The following is the get method:
Protected synchronized Object get (int type, String key) throws InvalidPropertyTypeException {
If (exists (key )){
ValueEntry v = (ValueEntry) getMap (). get (key );
If (v. type! = Type ){
Throw new InvalidPropertyTypeException ();
}
Return v. value;
} Else {
Return null;
}
}
Then the getMap () method is used:
Protected HashMap getMap (){
Return map;
}
There is no problem here. Next we need to see where map is assigned. map is a private field of the MemoryPropertySet class. Naturally, it will not be assigned a value in the base class of MemoryPropertySet. However, in the MemoryPropertySet class, the map assignment operation has only one place:
Public void init (Map config, Map args ){
Map = new HashMap ();
}
I will not talk about it any more. There is nothing in map at all, and I am dizzy ~~~