KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > appserv > management > ext > logging > LogQueryEntryImpl


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 package com.sun.appserv.management.ext.logging;
24
25 import java.util.Map JavaDoc;
26 import java.util.HashMap JavaDoc;
27 import java.util.Date JavaDoc;
28 import java.util.logging.Level JavaDoc;
29
30 import com.sun.appserv.management.util.misc.ArrayUtil;
31 import com.sun.appserv.management.util.misc.ObjectUtil;
32
33 import static com.sun.appserv.management.ext.logging.LogRecordFields.*;
34
35 //import static com.sun.appserv.management.ext.logging.LogRecordFields;
36

37 /**
38     <b>INTERNAL USE ONLY--not part of the API</b>
39     
40     @since AS 9.0
41  */

42 public final class LogQueryEntryImpl
43     implements LogQueryEntry
44 {
45     private transient Map JavaDoc<String JavaDoc,String JavaDoc> mNameValuePairsMap;
46     
47     final long mRecordNumber;
48     final Date JavaDoc mDate;
49     final String JavaDoc mLevel;
50     final String JavaDoc mProductName;
51     final String JavaDoc mMessage;
52     final String JavaDoc mMessageID;
53     final String JavaDoc mModule;
54     final String JavaDoc mNameValuePairs;
55     
56        public
57     LogQueryEntryImpl(
58         final long recordNumber,
59         final Date JavaDoc date,
60         final String JavaDoc level,
61         final String JavaDoc productName,
62         final String JavaDoc message,
63         final String JavaDoc messageID,
64         final String JavaDoc module,
65         final String JavaDoc nameValuePairs)
66     {
67         if ( date == null || level == null || message == null ||
68             module == null || nameValuePairs == null )
69         {
70             throw new IllegalArgumentException JavaDoc();
71         }
72         
73         mRecordNumber = recordNumber;
74         mDate = date;
75         mLevel = Level.parse( level ).toString();
76         mProductName = productName;
77         mModule = module;
78         mMessage = message;
79         mMessageID = messageID;
80         mNameValuePairs = nameValuePairs;
81     }
82     
83         public
84     LogQueryEntryImpl( final Object JavaDoc[] values )
85     {
86         if ( values.length != NUM_FIELDS )
87         {
88             throw new IllegalArgumentException JavaDoc( "wrong number of fields: " + values.length);
89         }
90    
91         mRecordNumber = (Long JavaDoc)values[ RECORD_NUMBER_INDEX ];
92         mDate = (Date JavaDoc)values[ DATE_INDEX ];
93         mLevel = Level.parse( (String JavaDoc)values[ LEVEL_INDEX ] ).toString();
94         mProductName = (String JavaDoc)values[ PRODUCT_NAME_INDEX ];
95         mMessageID = (String JavaDoc)values[ MESSAGE_ID_INDEX ];
96         mModule = (String JavaDoc)values[ MODULE_INDEX ];
97         mMessage = (String JavaDoc)values[ MESSAGE_INDEX ];
98         mNameValuePairs = (String JavaDoc)values[ NAME_VALUE_PAIRS_INDEX ];
99     }
100     
101         public Object JavaDoc[]
102     getFields()
103     {
104         final Object JavaDoc[] fields = new Object JavaDoc[ NUM_FIELDS ];
105         
106         fields[ RECORD_NUMBER_INDEX ] = mRecordNumber;
107         fields[ DATE_INDEX ] = mDate;
108         fields[ LEVEL_INDEX ] = mLevel;
109         fields[ PRODUCT_NAME_INDEX ] = mProductName;
110         fields[ MESSAGE_ID_INDEX ] = mMessageID;
111         fields[ MODULE_INDEX ] = mModule;
112         fields[ MESSAGE_INDEX ] = mMessage;
113         fields[ NAME_VALUE_PAIRS_INDEX ]= mNameValuePairs;
114         
115         return fields;
116     }
117     
118     /*
119         public
120     LogQueryEntryImpl( final CompositeData data )
121     {
122         this( OpenMBeanUtil.compositeDataToMap( data ) );
123     }
124         public CompositeType
125     getCompositeType()
126         throws OpenDataException
127     {
128         return OpenMBeanUtil.mapToCompositeType( getMapClassName(),
129             getMapClassName(), asMap(), null );
130     }
131     
132         public CompositeData
133     asCompositeData()
134         throws OpenDataException
135     {
136         return new CompositeDataSupport( getCompositeType(), asMap() );
137     }
138     
139     */

140
141
142         public long
143     getRecordNumber()
144     {
145         return mRecordNumber;
146     }
147     
148         public Date JavaDoc
149     getDate()
150     {
151         return mDate;
152     }
153     
154         public String JavaDoc
155     getModule()
156     {
157         return mModule;
158     }
159     
160         public String JavaDoc
161     getLevel()
162     {
163         return mLevel;
164     }
165     
166         public String JavaDoc
167     getProductName()
168     {
169         return mProductName;
170     }
171     
172         public String JavaDoc
173     getMessage()
174     {
175         return mMessage;
176     }
177     
178         public String JavaDoc
179     getMessageID()
180     {
181         return mMessageID;
182     }
183     
184         public String JavaDoc
185     getNameValuePairs()
186     {
187         return mNameValuePairs;
188     }
189     
190     /** delimiter between name/value pairs */
191     private static final String JavaDoc NVP_PAIRS_DELIM = ";";
192     /** delimiter between name and value */
193     private static final String JavaDoc PAIR_DELIM = "=";
194     
195         private Map JavaDoc<String JavaDoc,String JavaDoc>
196     parseNameValuePairs()
197     {
198         final String JavaDoc src = getNameValuePairs();
199         final Map JavaDoc<String JavaDoc,String JavaDoc> m = new HashMap JavaDoc<String JavaDoc,String JavaDoc>();
200         
201         final String JavaDoc[] pairs = src.split( NVP_PAIRS_DELIM );
202         
203         for( String JavaDoc pair : pairs )
204         {
205             final int idx = pair.indexOf( PAIR_DELIM );
206             if ( idx < 0 )
207             {
208                 throw new IllegalArgumentException JavaDoc( src );
209             }
210             final String JavaDoc name = pair.substring( 0, idx ).trim();
211             final String JavaDoc value = pair.substring( idx + 1, pair.length() ).trim();
212             
213             m.put( name, value );
214         }
215         
216         return m;
217     }
218     
219         public Map JavaDoc<String JavaDoc,String JavaDoc>
220     getNameValuePairsMap()
221     {
222         if ( mNameValuePairsMap == null )
223         {
224             mNameValuePairsMap = parseNameValuePairs();
225         }
226         
227         return mNameValuePairsMap;
228     }
229     
230         public String JavaDoc
231     getThreadID()
232     {
233         return getNameValuePairsMap().get( THREAD_ID_KEY );
234     }
235     
236         public String JavaDoc
237     getObjectName()
238     {
239         return getNameValuePairsMap().get( OBJECTNAME_KEY );
240     }
241     
242         public String JavaDoc
243     toString()
244     {
245         final String JavaDoc D = "|";
246         
247         // [#|DATE|LEVEL|PRODUCT_NAME|MODULE|NAME_VALUE_PAIRS|MESSAGE|#]
248
return "[#" +
249             getRecordNumber() + D +
250             getDate() + D +
251             getLevel() + D +
252             getProductName() + D +
253             getModule() + D +
254             getNameValuePairs() + D +
255             getMessage() + D +
256             getMessageID() + D +
257             "]";
258     }
259     
260         public int
261     hashCode()
262     {
263         return ObjectUtil.hashCode( mDate, mLevel,
264             mProductName, mMessage, mMessageID, mModule, mNameValuePairs) ^
265             ObjectUtil.hashCode( mRecordNumber );
266     }
267     
268         public boolean
269     equals( final Object JavaDoc rhs )
270     {
271         boolean equal = false;
272         
273         if ( this == rhs )
274         {
275             equal = true;
276         }
277         else if ( rhs instanceof LogQueryEntry )
278         {
279            final LogQueryEntry e = (LogQueryEntry)rhs;
280            
281            equal = ArrayUtil.arraysEqual( getFields(), e.getFields() );
282         }
283
284         return equal;
285     }
286 }
287
288
289
290
291
292
293
Popular Tags