KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > versant > core > storagemanager > logging > SmStatesReturnedEvent


1
2 /*
3  * Copyright (c) 1998 - 2005 Versant Corporation
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  * Versant Corporation - initial API and implementation
11  */

12 package com.versant.core.storagemanager.logging;
13
14 import com.versant.core.metadata.MDStatics;
15
16 import java.util.List JavaDoc;
17 import java.util.ArrayList JavaDoc;
18 import java.util.Collections JavaDoc;
19
20 /**
21  * Base class for events logged for operations that return states.
22  */

23 public class SmStatesReturnedEvent extends StorageManagerEvent {
24
25     protected int returnedSize;
26     private String JavaDoc[] returnedOIDs;
27     private int[] lookupClassIDs;
28     private String JavaDoc[] lookupClassNames;
29
30     public SmStatesReturnedEvent(int storageManagerId, int type) {
31         super(storageManagerId, type);
32     }
33
34     /**
35      * How many states were returned in the packet? This includes the state
36      * asked for and all prefetched data.
37      */

38     public int getReturnedSize() {
39         return returnedSize;
40     }
41
42     public void setReturnedSize(int returnedSize) {
43         this.returnedSize = returnedSize;
44     }
45
46     /**
47      * Get all the OIDs for all of the states included in the response packet.
48      */

49     public String JavaDoc[] getReturnedOIDs() {
50         return returnedOIDs;
51     }
52
53     public void setReturnedOIDs(String JavaDoc[] returnedOIDs) {
54         this.returnedOIDs = returnedOIDs;
55     }
56
57     /**
58      * Set the classIDs and corresponding class names for all classID lookup
59      * for this event. This information can be used to display the class names
60      * for the classIDs in this event.
61      * @see #getNameForClassID(int)
62      */

63     public void setLookupClasses(int[] classIDs, String JavaDoc[] classNames) {
64         this.lookupClassIDs = classIDs;
65         this.lookupClassNames = classNames;
66     }
67
68     public int[] getLookupClassIDs() {
69         return lookupClassIDs;
70     }
71
72     public String JavaDoc[] getLookupClassNames() {
73         return lookupClassNames;
74     }
75
76     /**
77      * Convert a class ID for a class in this event into its name. Returns
78      * null if no match found.
79      */

80     public String JavaDoc getNameForClassID(int id) {
81         int n = lookupClassIDs.length;
82         for (int i = 0; i < n; i++) {
83             if (lookupClassIDs[i] == id) return lookupClassNames[i];
84         }
85         return null;
86     }
87
88     /**
89      * Get a list of all the ClassAndOID's for all the data in the return
90      * packet.
91      */

92     public List JavaDoc getPacketEntries() {
93         if (returnedOIDs == null) return Collections.EMPTY_LIST;
94         int n = returnedOIDs.length;
95         ArrayList JavaDoc a = new ArrayList JavaDoc(n);
96         for (int i = 0; i < n; i++) {
97             String JavaDoc oid = returnedOIDs[i];
98             int j = oid.indexOf(MDStatics.OID_CHAR_SEPERATOR);
99             int classId = Integer.parseInt(oid.substring(0, j));
100             a.add(new ClassAndOID(oid, getNameForClassID(classId)));
101         }
102         return a;
103     }
104
105     /**
106      * An entry in the data packet.
107      */

108     public static class ClassAndOID {
109
110         private String JavaDoc oid;
111         private String JavaDoc className;
112
113         public ClassAndOID(String JavaDoc oid, String JavaDoc className) {
114             this.oid = oid;
115             this.className = className;
116         }
117
118         public String JavaDoc getOid() {
119             return oid;
120         }
121
122         public String JavaDoc getClassName() {
123             return className;
124         }
125
126         public void setOid(String JavaDoc oid) {
127             this.oid = oid;
128         }
129
130         public void setClassName(String JavaDoc className) {
131             this.className = className;
132         }
133     }
134
135 }
136
Popular Tags