author | Eugene Ostroukhov <eugeneo@symbian.org> |
Mon, 07 Jun 2010 16:51:19 -0700 | |
changeset 355 | 8726e95bcbba |
parent 276 | f2f4a1259de8 |
permissions | -rw-r--r-- |
2 | 1 |
// Copyright (c) 2009 The Chromium Authors. All rights reserved. |
2 |
// Use of this source code is governed by a BSD-style license that can be |
|
3 |
// found in the LICENSE file. |
|
4 |
||
5 |
package org.chromium.sdk.internal; |
|
6 |
||
355
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
7 |
import java.util.Collections; |
2 | 8 |
import java.util.List; |
355
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
9 |
import java.util.logging.Level; |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
10 |
import java.util.logging.Logger; |
2 | 11 |
|
355
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
12 |
import org.chromium.sdk.LiveEditDebugEventListener; |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
13 |
import org.chromium.sdk.LiveEditExtension; |
2 | 14 |
import org.chromium.sdk.Script; |
355
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
15 |
import org.chromium.sdk.SyncCallback; |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
16 |
import org.chromium.sdk.UpdatableScript; |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
17 |
import org.chromium.sdk.internal.protocol.ChangeLiveBody; |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
18 |
import org.chromium.sdk.internal.protocol.SuccessCommandResponse; |
2 | 19 |
import org.chromium.sdk.internal.protocol.data.ScriptHandle; |
20 |
import org.chromium.sdk.internal.protocol.data.SomeHandle; |
|
21 |
import org.chromium.sdk.internal.protocolparser.JsonProtocolParseException; |
|
355
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
22 |
import org.chromium.sdk.internal.tools.v8.V8CommandCallbackBase; |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
23 |
import org.chromium.sdk.internal.tools.v8.V8CommandProcessor; |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
24 |
import org.chromium.sdk.internal.tools.v8.V8Helper; |
2 | 25 |
import org.chromium.sdk.internal.tools.v8.V8ProtocolUtil; |
355
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
26 |
import org.chromium.sdk.internal.tools.v8.V8Helper.ScriptLoadCallback; |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
27 |
import org.chromium.sdk.internal.tools.v8.request.ChangeLiveMessage; |
2 | 28 |
|
29 |
/** |
|
30 |
* An objects that holds data for a "script" which is a part of a resource |
|
31 |
* loaded into the browser, identified by its original document URL, line offset |
|
32 |
* in the original document, and the line count this script spans. |
|
33 |
*/ |
|
355
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
34 |
public class ScriptImpl implements Script, UpdatableScript { |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
35 |
|
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
36 |
/** The class logger. */ |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
37 |
private static final Logger LOGGER = Logger.getLogger(ScriptImpl.class.getName()); |
2 | 38 |
|
39 |
/** |
|
40 |
* An object containing data that uniquely identify a V8 script chunk. |
|
41 |
*/ |
|
42 |
public static class Descriptor { |
|
43 |
public final Type type; |
|
44 |
||
45 |
public final String name; |
|
46 |
||
47 |
public final int lineOffset; |
|
48 |
||
355
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
49 |
public final int columnOffset; |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
50 |
|
2 | 51 |
public final int endLine; |
52 |
||
53 |
public final long id; |
|
54 |
||
355
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
55 |
public Descriptor(Type type, long id, String name, int lineOffset, int columnOffset, |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
56 |
int lineCount) { |
2 | 57 |
this.type = type; |
58 |
this.id = id; |
|
59 |
this.name = name; |
|
60 |
this.lineOffset = lineOffset; |
|
355
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
61 |
this.columnOffset = columnOffset; |
2 | 62 |
this.endLine = lineOffset + lineCount - 1; |
63 |
} |
|
64 |
||
65 |
@Override |
|
66 |
public int hashCode() { |
|
67 |
return |
|
68 |
name != null ? name.hashCode() : (int) id * 0x101 + |
|
355
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
69 |
lineOffset * 0x1001 + columnOffset * 0x10001 + |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
70 |
endLine * 0x100001; |
2 | 71 |
} |
72 |
||
73 |
@Override |
|
74 |
public boolean equals(Object obj) { |
|
75 |
if (obj == this) { |
|
76 |
return true; |
|
77 |
} |
|
78 |
if (!(obj instanceof Descriptor)) { |
|
79 |
return false; |
|
80 |
} |
|
81 |
Descriptor that = (Descriptor) obj; |
|
82 |
// The id equality is stronger than the name equality. |
|
83 |
return this.id == that.id && |
|
84 |
this.lineOffset == that.lineOffset && |
|
355
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
85 |
this.columnOffset == that.columnOffset && |
2 | 86 |
this.endLine == that.endLine; |
87 |
} |
|
88 |
||
89 |
public static Descriptor forResponse(ScriptHandle script, List<SomeHandle> refs, |
|
90 |
V8ContextFilter contextFilter) { |
|
91 |
script = V8ProtocolUtil.validScript(script, refs, contextFilter); |
|
92 |
if (script == null) { |
|
93 |
return null; |
|
94 |
} |
|
95 |
String name = script.name(); |
|
96 |
try { |
|
97 |
Long scriptType = script.scriptType(); |
|
98 |
Type type = V8ProtocolUtil.getScriptType(scriptType); |
|
99 |
if (type == null) { |
|
100 |
return null; |
|
101 |
} |
|
102 |
int lineOffset = (int) script.lineOffset(); |
|
355
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
103 |
int columnOffset = (int) script.columnOffset(); |
2 | 104 |
int lineCount = (int) script.lineCount(); |
105 |
int id = V8ProtocolUtil.getScriptIdFromResponse(script).intValue(); |
|
355
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
106 |
return new Descriptor(type, id, name, lineOffset, columnOffset, lineCount); |
2 | 107 |
} catch (Exception e) { |
108 |
// not a script object has been passed in |
|
109 |
return null; |
|
110 |
} |
|
111 |
} |
|
112 |
} |
|
113 |
||
114 |
private final Descriptor descriptor; |
|
115 |
||
276
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
116 |
private volatile String source = null; |
2 | 117 |
|
355
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
118 |
private final DebugSession debugSession; |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
119 |
|
2 | 120 |
/** |
121 |
* @param descriptor of the script retrieved from a "scripts" response |
|
122 |
*/ |
|
355
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
123 |
public ScriptImpl(Descriptor descriptor, DebugSession debugSession) { |
2 | 124 |
this.descriptor = descriptor; |
125 |
this.source = null; |
|
355
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
126 |
this.debugSession = debugSession; |
2 | 127 |
} |
128 |
||
129 |
public Type getType() { |
|
130 |
return this.descriptor.type; |
|
131 |
} |
|
132 |
||
133 |
public String getName() { |
|
134 |
return descriptor.name; |
|
135 |
} |
|
136 |
||
137 |
public int getStartLine() { |
|
138 |
return descriptor.lineOffset; |
|
139 |
} |
|
140 |
||
355
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
141 |
public int getStartColumn() { |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
142 |
return descriptor.columnOffset; |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
143 |
} |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
144 |
|
2 | 145 |
public int getEndLine() { |
146 |
return descriptor.endLine; |
|
147 |
} |
|
148 |
||
149 |
public long getId() { |
|
150 |
return descriptor.id; |
|
151 |
} |
|
152 |
||
153 |
public String getSource() { |
|
154 |
return source; |
|
155 |
} |
|
156 |
||
157 |
public boolean hasSource() { |
|
158 |
return source != null; |
|
159 |
} |
|
160 |
||
161 |
public void setSource(String source) { |
|
162 |
this.source = source; |
|
163 |
} |
|
164 |
||
355
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
165 |
public void setSourceOnRemote(String newSource, UpdateCallback callback, |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
166 |
SyncCallback syncCallback) { |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
167 |
V8CommandProcessor.V8HandlerCallback v8Callback = createScriptUpdateCallback(callback); |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
168 |
debugSession.sendMessageAsync(new ChangeLiveMessage(getId(), newSource), |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
169 |
true, v8Callback, syncCallback); |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
170 |
} |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
171 |
|
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
172 |
private V8CommandProcessor.V8HandlerCallback createScriptUpdateCallback( |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
173 |
final UpdateCallback callback) { |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
174 |
if (callback == null) { |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
175 |
return null; |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
176 |
} |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
177 |
return new V8CommandCallbackBase() { |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
178 |
@Override |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
179 |
public void success(SuccessCommandResponse successResponse) { |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
180 |
ChangeLiveBody body; |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
181 |
try { |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
182 |
body = successResponse.getBody().asChangeLiveBody(); |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
183 |
} catch (JsonProtocolParseException e) { |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
184 |
throw new RuntimeException(e); |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
185 |
} |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
186 |
|
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
187 |
ScriptLoadCallback scriptCallback = new ScriptLoadCallback() { |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
188 |
public void failure(String message) { |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
189 |
LOGGER.log(Level.SEVERE, |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
190 |
"Failed to reload script after LiveEdit script update; " + message); |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
191 |
} |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
192 |
public void success() { |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
193 |
LiveEditDebugEventListener listener = |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
194 |
LiveEditExtension.castToLiveEditListener(debugSession.getDebugEventListener()); |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
195 |
if (listener != null) { |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
196 |
listener.scriptContentChanged(ScriptImpl.this); |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
197 |
} |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
198 |
} |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
199 |
}; |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
200 |
V8Helper.reloadScriptAsync(debugSession, Collections.singletonList(getId()), |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
201 |
scriptCallback, null); |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
202 |
|
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
203 |
debugSession.recreateCurrentContext(); |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
204 |
|
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
205 |
callback.success(body.getChangeLog()); |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
206 |
} |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
207 |
|
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
208 |
@Override |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
209 |
public void failure(String message) { |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
210 |
callback.failure(message); |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
211 |
} |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
212 |
}; |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
213 |
} |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
214 |
|
2 | 215 |
@Override |
216 |
public int hashCode() { |
|
217 |
return |
|
218 |
descriptor.hashCode() * 0x101 + |
|
219 |
(hasSource() ? (source.hashCode() * 0x1001) : 0); |
|
220 |
} |
|
221 |
||
222 |
@Override |
|
223 |
public boolean equals(Object obj) { |
|
224 |
if (this == obj) { |
|
225 |
return true; |
|
226 |
} |
|
227 |
if (!(obj instanceof ScriptImpl)) { |
|
228 |
return false; |
|
229 |
} |
|
230 |
ScriptImpl that = (ScriptImpl) obj; |
|
231 |
return this.descriptor.equals(that.descriptor) && eq(this.source, that.source); |
|
232 |
} |
|
233 |
||
234 |
private static boolean eq(Object left, Object right) { |
|
235 |
return left == right || (left != null && left.equals(right)); |
|
236 |
} |
|
237 |
||
238 |
@Override |
|
239 |
public String toString() { |
|
240 |
StringBuilder sb = new StringBuilder(); |
|
241 |
sb.append("[Script (").append(hasSource() |
|
242 |
? "has" |
|
243 |
: "no").append(" source): name=").append(getName()).append(", lineRange=[").append( |
|
244 |
getStartLine()).append(';').append(getEndLine()).append("]]"); |
|
245 |
return sb.toString(); |
|
246 |
} |
|
247 |
||
248 |
public static Long getScriptId(HandleManager handleManager, long scriptRef) { |
|
249 |
SomeHandle handle = handleManager.getHandle(scriptRef); |
|
250 |
if (handle == null) { |
|
251 |
return -1L; // not found |
|
252 |
} |
|
253 |
ScriptHandle scriptHandle; |
|
254 |
try { |
|
255 |
scriptHandle = handle.asScriptHandle(); |
|
256 |
} catch (JsonProtocolParseException e) { |
|
257 |
throw new RuntimeException(e); |
|
258 |
} |
|
259 |
return scriptHandle.id(); |
|
260 |
} |
|
261 |
||
262 |
} |