G
Guest
Gast
Die API einer Anwendung stellt mir folgende Methode zur Verfügung:
Die zu setzenden Properties können verschiedene Datentypen sein. Wenn das zu setzenden Propertie z.B vom Typ boolean ist, so bekomme ich mit dem Code unten eine IllegalArgumentException. Leider kann ich zur Laufzeit nicht herausfinden vom welchem Datentyp das zu setzenden Attribut ist. Kann ich nicht alle Arten von Datentypen in ein Objekt der Klasse Object kapseln, so das die Lösung dann allgemeingültig ist (egal welcher Datentyp gerade vorliegt)?
public java.lang.Object setPropValue(java.lang.String propName, java.lang.Object value)
Sets the property value for the specified property name to the specified value. The specified value is automatically unwrapped to match a primitive type. The previous value returned is wrapped in an object if it has a primitive type.
If the value of the property to be set is invalid, then an IllegalArgumentException is thrown. For String properties, this would happen if a property value is required but the string is empty or null, or if the length exceeds the length of the description for the property. For Boolean properties, the value is invalid if the type of the parameter 'value' is not Boolean, Date properties are illegal if they are outside the range 1753 January 01 AD 00:00:00 GMT and 3000 January 02 AD 00:00:00 GMT. Float and Integer properties are illegal if the 'value' parameter is not a Number object or if the property description has a minimum and maximum value and the value provided is not within that range. Menu properties are illegal if the parameter 'value' is not a String or String array and the value or values provided are not existing choices from the property description for this property.
Die zu setzenden Properties können verschiedene Datentypen sein. Wenn das zu setzenden Propertie z.B vom Typ boolean ist, so bekomme ich mit dem Code unten eine IllegalArgumentException. Leider kann ich zur Laufzeit nicht herausfinden vom welchem Datentyp das zu setzenden Attribut ist. Kann ich nicht alle Arten von Datentypen in ein Objekt der Klasse Object kapseln, so das die Lösung dann allgemeingültig ist (egal welcher Datentyp gerade vorliegt)?
Code:
String attributName = aktuellesDatenTag.getAttributeValue("Name");
String attributWert = aktuellesDatenTag.getText();
objektPrototype.setPropValue(attributName, attributWert);