KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jmanage > core > management > data > CompositeDataFormat


1 /**
2 * Copyright (c) 2004-2005 jManage.org
3 *
4 * This is a free software; you can redistribute it and/or
5 * modify it under the terms of the license at
6 * http://www.jmanage.org.
7 *
8 * Unless required by applicable law or agreed to in writing, software
9 * distributed under the License is distributed on an "AS IS" BASIS,
10 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 * See the License for the specific language governing permissions and
12 * limitations under the License.
13 */

14 package org.jmanage.core.management.data;
15
16 import org.jmanage.util.display.Table;
17
18 import javax.management.openmbean.CompositeData JavaDoc;
19 import javax.management.openmbean.CompositeType JavaDoc;
20 import java.util.Iterator JavaDoc;
21 import java.util.Set JavaDoc;
22
23 /**
24  * Formats javax.management.openmbbean.CompositeData
25  * <p>
26  * Date: Sep 27, 2005
27  * @author Rakesh Kalra
28  */

29 public abstract class CompositeDataFormat implements DataFormat {
30
31     public String JavaDoc format(Object JavaDoc data){
32         CompositeData JavaDoc compositeData = (CompositeData JavaDoc)data;
33         CompositeType JavaDoc type = compositeData.getCompositeType();
34
35         Set JavaDoc itemNamesSet = type.keySet();
36         String JavaDoc[] itemNames = new String JavaDoc[itemNamesSet.size() + 1];
37         String JavaDoc[] itemValues = new String JavaDoc[itemNamesSet.size() + 1];
38
39         itemNames[0] = "CompositeType";
40         itemValues[0] = type.getTypeName();
41
42         int index = 1;
43         for(Iterator JavaDoc it=itemNamesSet.iterator();it.hasNext();){
44             itemNames[index] = (String JavaDoc)it.next();
45             Object JavaDoc value = compositeData.get(itemNames[index]);
46             itemValues[index] = DataFormatUtil.format(value);
47             index ++;
48         }
49
50         /* draw the table */
51         Table table = getTable();
52         table.setHeader(itemNames);
53         table.addRow(itemValues);
54         return table.draw();
55     }
56
57     protected abstract Table getTable();
58 }
59
Popular Tags