We help IT Professionals succeed at work.
Get Started

Display contents of hetrogeneous objects in HashMap or DistributedMap.

SHKR
SHKR asked
on
520 Views
Last Modified: 2012-05-05
I am trying to write a small util to display the contents of the objects in the HashMap/ DistributedMap. Please guide or provide some sample code to achieve this.

HashMap will have differnet types of objects and  writing if then else instanceof operator  code  block will be  cumbersome and need to make changes to the code for each class type added , I am looking to make this dynamic by configuring the class type and methodName and variable Names in XML files. I will add detail of the any  new classes in the XML file.
public  String displayObjectData(Object obj){
 	StringBuffer outPutJsp = new StringBuffer() ;
	String className = obj.getClass().getName();
	ClassType classType = null ;
	if(classMap.containsKey(className)){
		classType = (ClassType)classMap.get(className);
		outPutJsp.append("<table> <th> <td>cachInstanceName : ["+this.cachInstanceName +"]</td>" +
				 "<td>Object classType["+ className +"]"+
				 ",Object value["+ obj.toString() +"]</td>");
		/// this point we need create reference based on the class type and then cast and display the contents by calling the methods listed in classMap.
			
			///stuck here.
			
			return outPutJsp.toString();
		}

Open in new window

Comment
Watch Question
Java Developer
CERTIFIED EXPERT
Top Expert 2010
Commented:
This problem has been solved!
Unlock 2 Answers and 11 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE