Java Reference
In-Depth Information
array for the new type. If the relation type name already exists in the relation
service, an exception will be thrown indicating what happened. In this case, the
relation type is named myRelationType .
11.3.3
Creating the role objects
Once the relation type is added to the relation service, you can successfully cre-
ate a Relation object that represents an instance of that type. In order to create a
Relation instance, you must be able to specify the roles that participate in the
relation. Using the role information as a template, let's define the roles.
Remember from the previous section that you have three roles for this exam-
ple: VoiceProcessor , FaxProcessor , and CallRouter . Just like the RelationType ,
you will need an array of Role objects in order to create the Relation instance.
You will create your role array list in the method shown in listing 11.7. This
method is also taken from the RelationMain class.
Listing 11.7
The createRoles() method from the RelationMain class
public void createRoles()
{
ArrayList voiceRoleValue = new ArrayList();
ArrayList faxRoleValue = new ArrayList();
ArrayList routingTableRoleValue = new ArrayList();
try
{
voiceRoleValue.add( new
ObjectName("JMXBookAgent:name=phoneCard,slot=1" ) );
voiceRoleValue.add( new
ObjectName("JMXBookAgent:name=phoneCard,slot=2") );
Role voiceProcessorRole = new Role("VoiceProcessor",
voiceRoleValue);
faxRoleValue.add(
new ObjectName("JMXBookAgent:name=faxCard") );
Role faxProcessorRole =
new Role("FaxProcessor", faxRoleValue);
routingTableRoleValue.add( new ObjectName(
"JMXBookAgent:name=routingTable" ) );
Role routingTableRole = new Role("CallRouter",
routingTableRoleValue);
roleList.add(voiceProcessorRole);
roleList.add(faxProcessorRole);
roleList.add(routingTableRole);
Search WWH ::




Custom Search