KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > jmeter > module > nodes > JMeterElementChildren


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.apache.jmeter.module.nodes;
21
22 import java.text.Collator JavaDoc;
23 import java.util.Collection JavaDoc;
24 import java.util.Collections JavaDoc;
25 import java.util.Comparator JavaDoc;
26 import java.util.SortedSet JavaDoc;
27 import java.util.TreeSet JavaDoc;
28 import org.apache.jmeter.module.cookies.JMeterCookie;
29 import org.apache.jmeter.testelement.TestElement;
30 import org.apache.jorphan.collections.HashTree;
31 import org.openide.nodes.Children;
32 import org.openide.nodes.Node;
33
34 /**
35  *
36  * @author Jaroslav Bachorik
37  */

38 public class JMeterElementChildren extends Children.Keys implements Comparator JavaDoc<TestElement> {
39   private static Collator JavaDoc SORTER = Collator.getInstance();
40   
41   private SortedSet JavaDoc<TestElement> allTestElements;
42   private HashTree nodeTree = null;
43   
44   public JMeterElementChildren(final HashTree tree) {
45     nodeTree = tree;
46   }
47   
48   public void rebind(final HashTree tree) {
49     nodeTree = tree;
50     allTestElements = null;
51     refreshKeys(true);
52   }
53   
54   @Override JavaDoc
55   protected void addNotify() {
56     super.addNotify();
57     refreshKeys(true);
58   }
59   
60   @Override JavaDoc
61   protected void removeNotify() {
62     super.removeNotify();
63     setKeys(Collections.EMPTY_SET);
64     synchronized (this) {
65       allTestElements = null;
66     }
67   }
68   
69   @Override JavaDoc
70   protected Node[] createNodes(Object JavaDoc key) {
71     TestElement t = (TestElement) key;
72     
73 // return new Node[] {new JMeterElementNode(new JMeterCookie(t, cookie.getPath(), cookie.getScriptSource()))};
74
return new Node[] {new JMeterElementNode(t, nodeTree.getTree(t))};
75   }
76   
77   public int compare(TestElement t1, TestElement t2) {
78     int x = SORTER.compare(t1.getProperty("TestElement.name").getStringValue(), t2.getProperty("TestElement.name").getStringValue());
79     if (x != 0 || t1 == t2) {
80       return x;
81     } else {
82       // #44491: was not displaying overridden targets.
83
return System.identityHashCode(t1) - System.identityHashCode(t2);
84     }
85   }
86   
87   private void refreshKeys(boolean createKeys) {
88     Collection JavaDoc keys = null;
89     synchronized (this) {
90       if (allTestElements == null && !createKeys) {
91         // Aynch refresh after removeNotify; ignore. (#44428)
92
return;
93       }
94       allTestElements = new TreeSet JavaDoc<TestElement>(this);
95 // try {
96
for(Object JavaDoc elementObj : nodeTree.list()) {
97           allTestElements.add((TestElement)elementObj);
98         }
99 // allTestElements.addAll(JMeterIntegrationEngine.getDefault().getChildren(cookie.getPath(), cookie.getScriptSource()));
100
keys = allTestElements;
101 // } catch (InitializationException e) {
102
// e.printStackTrace();
103
// }
104
}
105     if (keys != null) { // #65235
106
setKeys(keys);
107     }
108   }
109   
110 }
111
Popular Tags