KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > cli > util > stringifier > NotificationStringifier


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/util/stringifier/NotificationStringifier.java,v 1.3 2005/12/25 03:46:08 tcfujii Exp $
26  * $Revision: 1.3 $
27  * $Date: 2005/12/25 03:46:08 $
28  */

29  
30
31 package com.sun.cli.util.stringifier;
32
33 import java.util.Date JavaDoc;
34 import javax.management.Notification JavaDoc;
35
36
37 public class NotificationStringifier implements Stringifier
38 {
39     public static NotificationStringifier DEFAULT = new NotificationStringifier();
40     
41     protected Options mOptions;
42     
43     public final static class Options
44     {
45         // don't make 'final' fields; allow changes after instantiation
46
public boolean mIncludeObjectName;
47         public boolean mIncludeTimeStamp;
48         public boolean mIncludeType;
49         public boolean mIncludeSequenceNumber;
50         public boolean mIncludeUserData;
51         public String JavaDoc mDelim;
52         
53             public
54         Options()
55         {
56             mIncludeObjectName = true;
57             mIncludeTimeStamp = true;
58             mIncludeType = true;
59             mIncludeSequenceNumber = true;
60             mIncludeUserData = false;
61             mDelim = "\n";
62         }
63         
64     }
65     
66     
67         public
68     NotificationStringifier( )
69     {
70         mOptions = new Options();
71     }
72     
73         public
74     NotificationStringifier( Options options )
75     {
76         mOptions = options;
77     }
78         
79         protected void
80     append( StringBuffer JavaDoc b, Object JavaDoc o)
81     {
82         if ( b.length() != 0 )
83         {
84             b.append( mOptions.mDelim );
85         }
86         
87         b.append( SmartStringifier.toString( o ) );
88     }
89     
90         public String JavaDoc
91     stringify( Object JavaDoc o )
92     {
93         final Notification JavaDoc notif = (Notification JavaDoc)o;
94         
95         return( _stringify( notif ).toString() );
96     }
97     
98         protected StringBuffer JavaDoc
99     _stringify( Notification JavaDoc notif )
100     {
101         final StringBuffer JavaDoc b = new StringBuffer JavaDoc();
102         
103         if ( mOptions.mIncludeSequenceNumber )
104         {
105             append( b, "" + notif.getSequenceNumber() );
106         }
107
108         if ( mOptions.mIncludeTimeStamp )
109         {
110             append( b, new Date JavaDoc( notif.getTimeStamp() ) );
111         }
112
113         if ( mOptions.mIncludeObjectName )
114         {
115             append( b, notif.getSource() );
116         }
117
118         if ( mOptions.mIncludeType )
119         {
120             append( b, notif.getType() );
121         }
122
123         if ( mOptions.mIncludeUserData )
124         {
125             append( b, notif.getUserData() );
126         }
127         
128         return( b );
129     }
130 }
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
Popular Tags