Source code: com/flexstor/common/gui/registrydebugger/RegistryParser.java
1 /*
2 * RegistryParser.java
3 *
4 * Copyright $Date: 2003/08/11 02:22:38 $ FLEXSTOR.net Inc.
5 *
6 * This work is licensed for use and distribution under license terms found at
7 * http://www.flexstor.org/license.html
8 *
9 */
10
11 package com.flexstor.common.gui.registrydebugger;
12
13 import java.util.ArrayList;
14 import java.util.Collection;
15 import java.util.Collections;
16 import java.util.Iterator;
17 import java.util.List;
18 import java.util.Set;
19
20 import com.flexstor.common.modules.registry.BaseInstanceI;
21 import com.flexstor.common.modules.registry.InstanceId;
22 import com.flexstor.common.modules.registry.InstanceTypesI;
23 import com.flexstor.common.modules.registry.RegistryHelper;
24 import com.flexstor.common.modules.registry.SharedAssetId;
25 import com.flexstor.common.modules.registry.SharedAssetInstanceId;
26 import com.flexstor.common.modules.registry.SharedRecordId;
27 import com.flexstor.common.modules.registry.asset.AssetInstanceI;
28 import com.flexstor.common.modules.registry.asset.AssetInstanceRecord;
29 import com.flexstor.common.modules.registry.asset.AssetRecord;
30 import com.flexstor.common.modules.registry.bucket.BucketRegistry;
31 import com.flexstor.common.modules.registry.element.ElementRegistry;
32 import com.flexstor.common.modules.registry.manager.RegistryDebuggerHooks;
33
34 public class RegistryParser
35 {
36 private RegistryDebuggerHooks hook;
37
38 public RegistryParser ( )
39 {
40 hook = new RegistryDebuggerHooks();
41 }
42
43 public void refresh ( RegistryDebuggerNode root )
44 {
45 Object o;
46 ArrayList list;
47 RegistryDebuggerNode parent;
48
49 // Use a HashSet to sort the Set.
50 Set keySet = hook.getCollection().keySet();
51
52 // Root Records
53 parent = new RegistryDebuggerNode ( root, "Root Records", false, "Roots" );
54 list = new ArrayList();
55 for ( Iterator i = keySet.iterator(); i.hasNext(); )
56 {
57 o = i.next();
58 if ( o instanceof InstanceId && ((InstanceId)o).getInstanceType() == InstanceTypesI.ROOT )
59 list.add ( o );
60 }
61 scanEntryList ( parent, list );
62
63 // Result Set Records
64 parent = new RegistryDebuggerNode ( root, "Result Set Records", false, "ResultSets" );
65 list = new ArrayList();
66 for ( Iterator i = keySet.iterator(); i.hasNext(); )
67 {
68 o = i.next();
69 if ( o instanceof InstanceId && ((InstanceId)o).getInstanceType() == InstanceTypesI.RESULT_SET )
70 list.add ( o );
71 }
72 scanEntryList ( parent, list );
73
74 // Disguise Records
75 parent = new RegistryDebuggerNode ( root, "Disguise Records", false, "Disguises" );
76 list = new ArrayList();
77 for ( Iterator i = keySet.iterator(); i.hasNext(); )
78 {
79 o = i.next();
80 if ( o instanceof InstanceId && ((InstanceId)o).getInstanceType() == InstanceTypesI.DISGUISE )
81 list.add ( o );
82 }
83 scanEntryList ( parent, list );
84
85 // Bucket Records
86 parent = new RegistryDebuggerNode ( root, "Bucket Records", false, "Buckets" );
87 list = new ArrayList();
88 for ( Iterator i = keySet.iterator(); i.hasNext(); )
89 {
90 o = i.next();
91 if ( o instanceof SharedRecordId && ((SharedRecordId)o).getType() == InstanceTypesI.BUCKET )
92 list.add ( o );
93 }
94 scanEntryList ( parent, list );
95
96 // Element Records
97 parent = new RegistryDebuggerNode ( root, "Element Records", false, "Elements" );
98 list = new ArrayList();
99 for ( Iterator i = keySet.iterator(); i.hasNext(); )
100 {
101 o = i.next();
102 if ( o instanceof SharedRecordId && ((SharedRecordId)o).getType() == InstanceTypesI.ELEMENT )
103 list.add ( o );
104 }
105 scanEntryList ( parent, list );
106
107 // Asset Records
108 parent = new RegistryDebuggerNode ( root, "Asset Records", false, "Assets" );
109 list = new ArrayList();
110 for ( Iterator i = keySet.iterator(); i.hasNext(); )
111 {
112 o = i.next();
113 if ( o instanceof SharedAssetId )
114 list.add ( o );
115 }
116 scanEntryList ( parent, list );
117 }
118
119 public void scanEntryList ( RegistryDebuggerNode parent, List list )
120 {
121 Collections.sort ( list );
122 for ( Iterator i = list.iterator(); i.hasNext(); )
123 scanEntry ( parent, i.next(), true );
124 }
125
126 public void scanEntry ( RegistryDebuggerNode parent, Object o, boolean bLoadVersions )
127 {
128 try
129 {
130 if ( o instanceof InstanceId )
131 {
132 InstanceId id = (InstanceId)o;
133 BaseInstanceI inst = RegistryHelper.getInstance ( id );
134
135 String sLabel = id.toString();
136 if ( !id.isAsset() || (id.isAsset() && ((AssetInstanceI)inst).isDataLoaded()) )
137 sLabel += " [" + inst.getLabel() + "]";
138
139 parent = new RegistryDebuggerNode ( parent, sLabel, false, id );
140
141 // Process children.
142 if ( !id.isAsset() )
143 {
144 addChildren ( inst, parent );
145 }
146
147 if ( id.isAsset() && bLoadVersions)
148 {
149 // Display any loaded versions
150 AssetInstanceI ainst = (AssetInstanceI)inst;
151
152 if ( ainst.isCurrentVersion() && ainst.areVersionsLoaded() )
153 {
154 List l = ainst.getVersions();
155 if ( l != null && !l.isEmpty() )
156 {
157 RegistryDebuggerNode ver = new RegistryDebuggerNode ( parent, "Versions", false, "Versions" );
158 for ( Iterator i = l.iterator(); i.hasNext(); )
159 scanEntry ( ver, ((BaseInstanceI)i.next()).getInstanceId(), false );
160 }
161 }
162 }
163 }
164 else if ( o instanceof SharedRecordId )
165 {
166 SharedRecordId sid = (SharedRecordId)o;
167
168 Collection c;
169 if ( sid.getType() == InstanceTypesI.BUCKET )
170 c = BucketRegistry.getRegistry().getInstanceIds ( sid.getRecordId() );
171 else
172 c = ElementRegistry.getRegistry().getInstanceIds ( sid.getRecordId() );
173
174 parent = new RegistryDebuggerNode ( parent, sid.toString(), false, sid );
175
176 if ( c != null )
177 for ( Iterator i = c.iterator(); i.hasNext(); )
178 scanEntry ( parent, (InstanceId)i.next(), true );
179 }
180
181 else if ( o instanceof SharedAssetInstanceId )
182 {
183 SharedAssetInstanceId id = (SharedAssetInstanceId)o;
184 parent = new RegistryDebuggerNode ( parent, id.toString(), false, id );
185 }
186
187 else if ( o instanceof SharedAssetId )
188 {
189 SharedAssetId said = (SharedAssetId)o;
190 parent = new RegistryDebuggerNode ( parent, "" + said, false, said );
191
192 AssetRecord rec = (AssetRecord)hook.getCollection().get ( o );
193
194 RegistryDebuggerNode instNode, instNode2;
195 SharedAssetInstanceId assetInstanceId;
196 InstanceId instanceId;
197 AssetInstanceRecord instRec;
198 for ( Iterator i = rec.getAssetInstanceList().iterator(); i.hasNext(); )
199 {
200 assetInstanceId = (SharedAssetInstanceId)i.next();
201 instNode = new RegistryDebuggerNode ( parent, ""+assetInstanceId, false, assetInstanceId );
202
203 instRec = (AssetInstanceRecord)hook.getCollection().get ( assetInstanceId );
204 for ( Iterator i2 = instRec.getAssetInstanceList().iterator(); i2.hasNext(); )
205 scanEntry ( instNode, i2.next(), true );
206 }
207 }
208
209 else
210 new RegistryDebuggerNode ( parent, "Unknown record type: " + o.toString(), true, "???" );
211 }
212 catch ( Exception e )
213 {
214 new RegistryDebuggerNode ( parent, "Internal error: " + e, true, "Error" );
215 }
216 }
217
218 public void addChildren ( BaseInstanceI inst, RegistryDebuggerNode parent )
219 {
220 RegistryDebuggerNode node = new RegistryDebuggerNode ( parent, "Children", false, "Children" );
221
222 ArrayList l = inst.getChildren ( false, InstanceTypesI.ALL );
223 InstanceId cid;
224 BaseInstanceI cinst;
225 for ( Iterator i = l.iterator(); i.hasNext(); )
226 {
227 cinst = (BaseInstanceI)i.next();
228 cid = cinst.getInstanceId();
229
230 String sLabel = cid.toString();
231 if ( !cid.isAsset() || (cid.isAsset() && ((AssetInstanceI)cinst).isDataLoaded()) )
232 sLabel += " [" + cinst.getLabel() + "]";
233
234 new RegistryDebuggerNode ( node, sLabel, false, cid );
235 }
236 }
237 }
238