587
|
1 |
/*
|
|
2 |
* Copyright (c) 2007-2008 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of the License "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
package com.nokia.helium.internaldata.ant.listener;
|
628
|
19 |
import java.util.Date;
|
587
|
20 |
import java.util.Iterator;
|
|
21 |
import java.util.Vector;
|
|
22 |
|
|
23 |
/**
|
|
24 |
* Data node object to iterate, keep timing, name, maintain parallel tasks for the node.
|
|
25 |
*
|
|
26 |
*/
|
|
27 |
public abstract class DataNode {
|
|
28 |
|
|
29 |
// Job number management
|
|
30 |
private static long commonJobId;
|
|
31 |
private long jobId = commonJobId++;
|
|
32 |
// Parent node
|
|
33 |
private DataNode parent;
|
|
34 |
|
|
35 |
// children nodes.
|
|
36 |
private Vector<DataNode> children = new Vector<DataNode>();
|
|
37 |
|
|
38 |
|
|
39 |
|
|
40 |
// Statistics about the time.
|
|
41 |
private Date startTime;
|
|
42 |
private Date endTime;
|
|
43 |
|
|
44 |
// Get the thread id. this is important for parallel tasks.
|
|
45 |
private long threadId = Thread.currentThread().getId();
|
|
46 |
|
|
47 |
// reference for the data.
|
|
48 |
private Object reference;
|
|
49 |
|
|
50 |
public DataNode(DataNode parent, Object reference) {
|
|
51 |
this.parent = parent;
|
|
52 |
if (parent != null) {
|
|
53 |
parent.add(this);
|
|
54 |
}
|
|
55 |
this.setStartTime(new Date());
|
|
56 |
this.setReference(reference);
|
|
57 |
}
|
|
58 |
|
|
59 |
/**
|
|
60 |
* Method used to register a child to it's parent.
|
|
61 |
* @param child, the child to register.
|
|
62 |
*/
|
|
63 |
public void add(DataNode child) {
|
|
64 |
children.add(child);
|
|
65 |
}
|
|
66 |
|
|
67 |
/**
|
|
68 |
* Return an iterator on this node children
|
|
69 |
* @return the iterator
|
|
70 |
*/
|
|
71 |
public Iterator<DataNode> iterator() {
|
|
72 |
return children.iterator();
|
|
73 |
}
|
|
74 |
|
|
75 |
/**
|
|
76 |
* Method used to remove a node from it's parent
|
|
77 |
* @param child, the child to remove.
|
|
78 |
*/
|
|
79 |
public void remove(DataNode child) {
|
|
80 |
children.remove(child);
|
|
81 |
}
|
|
82 |
|
|
83 |
/**
|
|
84 |
* Is the node containing any children.
|
|
85 |
* @return true is the node is empty
|
|
86 |
*/
|
|
87 |
public boolean isEmpty() {
|
|
88 |
return children.isEmpty();
|
|
89 |
}
|
|
90 |
|
|
91 |
/**
|
|
92 |
* Returns the parent node, or null if the root.
|
|
93 |
* @return a DataNode.
|
|
94 |
*/
|
|
95 |
public DataNode getParent() {
|
|
96 |
return parent;
|
|
97 |
}
|
|
98 |
|
|
99 |
public Date getStartTime() {
|
|
100 |
return startTime;
|
|
101 |
}
|
|
102 |
|
|
103 |
public void setStartTime(Date startTime) {
|
|
104 |
this.startTime = startTime;
|
|
105 |
}
|
|
106 |
|
|
107 |
/**
|
|
108 |
* Make is reliable: if end time doesn't exists let's use the start time.
|
|
109 |
*/
|
|
110 |
public Date getEndTime() {
|
628
|
111 |
if (endTime != null) {
|
587
|
112 |
return endTime;
|
628
|
113 |
} else {
|
587
|
114 |
return this.getStartTime();
|
628
|
115 |
}
|
587
|
116 |
}
|
|
117 |
|
|
118 |
public void setEndTime(Date endTime) {
|
|
119 |
this.endTime = endTime;
|
|
120 |
}
|
|
121 |
|
|
122 |
/**
|
|
123 |
* Return the thread where the class has been created under.
|
|
124 |
* @return thread id as a long.
|
|
125 |
*/
|
|
126 |
public long getThreadId() {
|
|
127 |
return this.threadId;
|
|
128 |
}
|
|
129 |
|
|
130 |
public Object getReference() {
|
|
131 |
return reference;
|
|
132 |
}
|
|
133 |
|
|
134 |
public void setReference(Object reference) {
|
|
135 |
this.reference = reference;
|
|
136 |
}
|
|
137 |
|
|
138 |
public long getJobId() {
|
|
139 |
return jobId;
|
|
140 |
}
|
|
141 |
|
|
142 |
/**
|
|
143 |
* Find a node using its reference.
|
|
144 |
* @param reference object
|
|
145 |
* @return
|
|
146 |
*/
|
|
147 |
public DataNode find(Object reference) {
|
628
|
148 |
if (this.reference == reference) {
|
|
149 |
return this;
|
|
150 |
}
|
587
|
151 |
for (Iterator<DataNode> i = children.iterator() ; i.hasNext() ; ) {
|
|
152 |
DataNode node = i.next();
|
|
153 |
DataNode result = node.find(reference);
|
628
|
154 |
if (result != null) {
|
587
|
155 |
return result;
|
628
|
156 |
}
|
587
|
157 |
}
|
|
158 |
return null;
|
|
159 |
}
|
|
160 |
|
|
161 |
|
|
162 |
/**
|
|
163 |
* Name of the node.
|
|
164 |
* @return name of the node (e.g target name for targets)
|
|
165 |
*/
|
|
166 |
public abstract String getName();
|
|
167 |
|
|
168 |
/**
|
|
169 |
* Default string representation.
|
|
170 |
*/
|
|
171 |
public String toString() {
|
|
172 |
return getName();
|
|
173 |
}
|
|
174 |
}
|