KickJava   Java API By Example, From Geeks To Geeks.

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


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.List JavaDoc;
27 import java.util.HashMap JavaDoc;
28 import java.util.Date JavaDoc;
29
30 import java.util.logging.Level JavaDoc;
31
32 import java.io.Serializable JavaDoc;
33
34 import javax.management.openmbean.CompositeData JavaDoc;
35 import javax.management.openmbean.CompositeDataSupport JavaDoc;
36 import javax.management.openmbean.CompositeType JavaDoc;
37 import javax.management.openmbean.OpenType JavaDoc;
38 import javax.management.openmbean.ArrayType JavaDoc;
39 import javax.management.openmbean.SimpleType JavaDoc;
40 import javax.management.openmbean.OpenDataException JavaDoc;
41
42 import com.sun.appserv.management.util.jmx.OpenMBeanUtil;
43 import com.sun.appserv.management.util.misc.ArrayUtil;
44 import com.sun.appserv.management.util.misc.ObjectUtil;
45 import com.sun.appserv.management.util.stringifier.ArrayStringifier;
46
47 /**
48     <b>INTERNAL USE ONLY--not part of the API</b>
49     @since AS 9.0
50  */

51 public final class LogQueryResultImpl
52     implements LogQueryResult
53 {
54     private String JavaDoc[] mFieldNames;
55     private LogQueryEntry[] mEntries;
56     
57         public
58     LogQueryResultImpl(
59         final String JavaDoc[] fieldNames,
60         final LogQueryEntry[] entries )
61     {
62         mFieldNames = fieldNames;
63         mEntries = entries;
64     }
65     
66     /**
67         Instantiate using result from {@link Logging#queryServerLog}.
68         The first Object[] is a String[] of the field names.
69         Subsequent Object[] are the data values.
70      */

71         public
72     LogQueryResultImpl( final List JavaDoc<Serializable JavaDoc[]> records )
73     {
74         mFieldNames = (String JavaDoc[])records.get( 0 );
75         
76         mEntries = new LogQueryEntry[ records.size() - 1 ];
77         for( int i = 1; i < mEntries.length; ++i )
78         {
79             mEntries[ i ] = new LogQueryEntryImpl( records.get( i ) );
80         }
81     }
82     
83         public String JavaDoc[]
84     getFieldNames()
85     {
86         return mFieldNames;
87     }
88     
89         public LogQueryEntry[]
90     getEntries()
91     {
92         return mEntries;
93     }
94     
95     private static final String JavaDoc FIELD_DELIM = "\t";
96     private static final String JavaDoc NEWLINE = System.getProperty( "line.separator" );;
97     /**
98         Output a tab-delimited String with a header line. Each
99         subsequent line represents another log record.
100      */

101         public String JavaDoc
102     toString()
103     {
104         final StringBuilder JavaDoc builder = new StringBuilder JavaDoc();
105         
106         for( final String JavaDoc s : getFieldNames() )
107         {
108             builder.append( s );
109             builder.append( FIELD_DELIM );
110         }
111         builder.replace( builder.length() - 1, builder.length(), NEWLINE );
112         
113         for ( final LogQueryEntry entry : getEntries() )
114         {
115             final Object JavaDoc[] fields = entry.getFields();
116             for( final Object JavaDoc o : fields )
117             {
118                 builder.append( o.toString() );
119                 builder.append( FIELD_DELIM );
120             }
121             builder.replace( builder.length() - 1, builder.length(), NEWLINE );
122         }
123         
124         return builder.toString();
125     }
126     
127         public int
128     hashCode()
129     {
130         return ObjectUtil.hashCode( getFieldNames(), getEntries() );
131     }
132     
133         public boolean
134     equals( final Object JavaDoc rhs )
135     {
136         boolean equal = rhs instanceof LogQueryResult;
137         
138         if ( equal )
139         {
140             final LogQueryResult r = (LogQueryResult)rhs;
141             
142             equal = ArrayUtil.arraysEqual( getFieldNames(), r.getFieldNames() ) &&
143                       ArrayUtil.arraysEqual( getEntries(), r.getEntries() );
144                         
145         }
146         
147         return equal;
148     }
149     
150  
151 }
152
153
154
155
156
157
Popular Tags