Solved

How to create a CompositeType and CompositeData for Mbean operation?

Posted on 2014-04-02
2
721 Views
Last Modified: 2014-05-06
I googled but can't find any good example for creating the CompositeData object to pass it as a parameter to the MBean operation.

Can you help?

Say, I have a Person class

Person class {String name;int age; boolean married;}

interface PersonDao {
public int addPerson(Person p);
}

PersonDaoImpl class implements PersonDao {
public int addPerson(Person p);
}


MBean
public int addPerson(Person person) {
String[] sig = { String.class.getName(),
Integer.class.getName(), Boolean.class.getName(),
};
Object[] arg = { person.getName(),new Integer(person.getAge()),
Boolean.valueOf(Person.IsMarried};

int rowNo = (int) server.invoke(name, "addPerson", arg, sig);

}

Here I cannot pass person as object.
So I have to pass it as primitive data type.


How can I create a CompositeType as Person class and CompositeData?

  private static String[] itemNames = {"name", "age", "married"};
private static String[] itemDescriptions = {"Full Name", "Age", "Married or not"};
  private static OpenType[] itemTypes = {SimpleType.STRING, SimpleType.INTEGER, SimpleType.BOOLEAN};
    private static CompositeType personType = null;

 personType = new CompositeType("person",
                                    "a Person",
                                itemNames,
                                   itemDescriptions,
                                  itemTypes);


How do I use the CompositeDat in my invoke method?

MBean
public int addPerson(Person person) {
String[] sig = { String.class.getName(),
Integer.class.getName(), Boolean.class.getName(),
};
Object[] arg = { person.getName(),new Integer(person.getAge()),
Boolean.valueOf(Person.IsMarried};

int rowNo = (int) server.invoke(name, "addPerson", arg, sig);

}
0
Comment
Question by:dkim18
2 Comments
 
LVL 9

Accepted Solution

by:
sanjooz earned 500 total points
ID: 39989614
Here is an example. Scroll down to Example 2-11

http://docs.oracle.com/cd/E19159-01/819-7758/gcitp/index.html
0
 

Author Comment

by:dkim18
ID: 39990229
Already saw that.

That doesnot show much other than invoke method returning a result set and casting using compositedata.

I am looking for an example or something explaining 1) how CustomInfo was inserted into compositetype object back in the mbean method ans 2) how to pass CustomInfo object as compositedata type to mbean method.

I looked and looked but can't find any example.

Thanks
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
The viewer will learn how to implement Singleton Design Pattern in Java.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now