2
I’m making a system where I read Java objects of different types of XML files. So I don’t have a single object type and consequently I don’t know its attributes or methods. I would like to perform a search, in which I entered a string indicating attribute and value, and this search returned to me all objects that had this attribute and that was equal to the value in a ArrayList
.
Example:
I have some XML files, of the types Produto
, Pessoa
and Carro
, are already read and instantiated. I want to look for objects that have the following feature ano: 1996
, the classes Produto
and Carro
has the attribute ano
, however Pessoa
he doesn’t have it. It would traverse the objects, where it would be analyzed if the value is equal and would take the necessary steps, if the attribute did not exist it would return null
or a Exception
to be treated.
Someone has an idea of how I can do this recovery, the biggest problem is who can be objects of different types, is that a non-relational bank job, if it were relational would be very easy, with defined types.
I’d like something that as a .getAtributte (String nomeAtributo, Object o)
, where the former is an attribute name and the latter the object analyzed.
Good idea, I’ll try :) !
– leandroungari
Your answer together with this solved my problems: http://stackoverflow.com/questions/2989560/how-to-get-the-fields-in-an-object-via-reflection
– leandroungari