KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > cli > jmx > support > ResultsForGetSetStringifier


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23  
24 /*
25  * $Header: /cvs/glassfish/admin-cli/cli-api/src/java/com/sun/cli/jmx/support/ResultsForGetSetStringifier.java,v 1.3 2005/12/25 03:45:50 tcfujii Exp $
26  * $Revision: 1.3 $
27  * $Date: 2005/12/25 03:45:50 $
28  */

29  
30
31 package com.sun.cli.jmx.support;
32
33 import javax.management.Attribute JavaDoc;
34
35 import com.sun.cli.jmx.support.ResultsForGetSet;
36
37 import com.sun.cli.util.stringifier.*;
38
39
40 public class ResultsForGetSetStringifier implements Stringifier
41 {
42     final Options mOptions;
43     
44     public static final class Options
45     {
46         final static Options DEFAULT = new Options();
47         
48         final boolean mIncludeObjectName;
49         final int mDisplayType;
50         
51         public final static int DISPLAY_TERSE = 0;
52         public final static int DISPLAY_PRETTY = 1;
53         
54         
55             public
56         Options( boolean includeObjectName, int displayType )
57         {
58             mIncludeObjectName = includeObjectName;
59             mDisplayType = DISPLAY_PRETTY;
60         }
61         
62             public
63         Options( )
64         {
65             this( true, DISPLAY_PRETTY );
66         }
67     };
68     
69         public
70     ResultsForGetSetStringifier( )
71     {
72         mOptions = Options.DEFAULT;
73     }
74         public
75     ResultsForGetSetStringifier( Options options )
76     {
77         mOptions = options;
78     }
79
80         public String JavaDoc
81     stringify( Object JavaDoc o )
82     {
83         final ResultsForGetSet result = (ResultsForGetSet)o;
84         
85         String JavaDoc str = "";
86         
87         if ( mOptions.mIncludeObjectName )
88         {
89             str = "---" + result.getName().toString() + "---";
90         }
91         final boolean pretty = mOptions.mDisplayType == Options.DISPLAY_PRETTY;
92         
93         final Stringifier attrS = new AttributeStringifier();
94         final Object JavaDoc [] attrList = result.getAttributes().toArray();
95         
96         if ( pretty )
97         {
98             str = str + "\n";
99         }
100
101         if ( attrList.length == 0 )
102         {
103             str = str + "<no attributes found>";
104         }
105         else
106         {
107             String JavaDoc delim;
108             
109             if ( pretty )
110                 delim = "\n";
111             else
112                 delim = ",";
113                 
114             str = str + ArrayStringifier.stringify( attrList , delim, attrS );
115         }
116         
117         return( str );
118     }
119 }
120
Popular Tags