PageRenderTime 28ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/asterixdb/asterix-external-data/src/test/java/org/apache/asterix/external/classad/ClassAd.java

https://gitlab.com/mohiuddin-shuvo/asterixdb
Java | 1258 lines | 971 code | 136 blank | 151 comment | 233 complexity | 3a3bb32dd3e2beb119cd11a9715bb95d MD5 | raw file
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing,
  13. * software distributed under the License is distributed on an
  14. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15. * KIND, either express or implied. See the License for the
  16. * specific language governing permissions and limitations
  17. * under the License.
  18. */
  19. package org.apache.asterix.external.classad;
  20. import java.io.IOException;
  21. import java.util.ArrayList;
  22. import java.util.HashMap;
  23. import java.util.Iterator;
  24. import java.util.Map;
  25. import java.util.Map.Entry;
  26. import java.util.TreeSet;
  27. import org.apache.asterix.external.classad.Value.NumberFactor;
  28. import org.apache.asterix.external.classad.object.pool.ClassAdObjectPool;
  29. import org.apache.asterix.external.library.ClassAdParser;
  30. import org.apache.asterix.om.base.AMutableDouble;
  31. import org.apache.asterix.om.base.AMutableInt32;
  32. import org.apache.asterix.om.base.AMutableInt64;
  33. import org.apache.asterix.om.base.AMutableString;
  34. import org.apache.commons.lang3.mutable.MutableBoolean;
  35. import org.apache.hyracks.api.exceptions.HyracksDataException;
  36. public class ClassAd extends ExprTree {
  37. /*
  38. * Static Variables
  39. */
  40. public static final int ERR_OK = 0;
  41. public static final int ERR_MEM_ALLOC_FAILED = 1;
  42. public static final int ERR_BAD_VALUE = 255;
  43. public static final int ERR_FAILED_SET_VIEW_NAME = 256;
  44. public static final int ERR_NO_RANK_EXPR = 257;
  45. public static final int ERR_NO_REQUIREMENTS_EXPR = 258;
  46. public static final int ERR_BAD_PARTITION_EXPRS = 259;
  47. public static final int ERR_PARTITION_EXISTS = 260;
  48. public static final int ERR_MISSING_ATTRNAME = 261;
  49. public static final int ERR_BAD_EXPRESSION = 262;
  50. public static final int ERR_INVALID_IDENTIFIER = 263;
  51. public static final int ERR_MISSING_ATTRIBUTE = 264;
  52. public static final int ERR_NO_SUCH_VIEW = 265;
  53. public static final int ERR_VIEW_PRESENT = 266;
  54. public static final int ERR_TRANSACTION_EXISTS = 267;
  55. public static final int ERR_NO_SUCH_TRANSACTION = 268;
  56. public static final int ERR_NO_REPRESENTATIVE = 269;
  57. public static final int ERR_NO_PARENT_VIEW = 270;
  58. public static final int ERR_BAD_VIEW_INFO = 271;
  59. public static final int ERR_BAD_TRANSACTION_STATE = 272;
  60. public static final int ERR_NO_SUCH_CLASSAD = 273;
  61. public static final int ERR_BAD_CLASSAD = 275;
  62. public static final int ERR_NO_KEY = 276;
  63. public static final int ERR_LOG_OPEN_FAILED = 277;
  64. public static final int ERR_BAD_LOG_FILENAME = 278;
  65. public static final int ERR_NO_VIEW_NAME = 379;
  66. public static final int ERR_RENAME_FAILED = 280;
  67. public static final int ERR_NO_TRANSACTION_NAME = 281;
  68. public static final int ERR_PARSE_ERROR = 282;
  69. public static final int ERR_INTERNAL_CACHE_ERROR = 283;
  70. public static final int ERR_FILE_WRITE_FAILED = 284;
  71. public static final int ERR_FATAL_ERROR = 285;
  72. public static final int ERR_CANNOT_CHANGE_MODE = 286;
  73. public static final int ERR_CONNECT_FAILED = 287;
  74. public static final int ERR_CLIENT_NOT_CONNECTED = 288;
  75. public static final int ERR_COMMUNICATION_ERROR = 289;
  76. public static final int ERR_BAD_CONNECTION_TYPE = 290;
  77. public static final int ERR_BAD_SERVER_ACK = 291;
  78. public static final int ERR_CANNOT_REPLACE = 292;
  79. public static final int ERR_CACHE_SWITCH_ERROR = 293;
  80. public static final int ERR_CACHE_FILE_ERROR = 294;
  81. public static final int ERR_CACHE_CLASSAD_ERROR = 295;
  82. public static final int ERR_CANT_LOAD_DYNAMIC_LIBRARY = 296;
  83. public static final String ATTR_TOPLEVEL = "toplevel";
  84. public static final String ATTR_ROOT = "root";
  85. public static final String ATTR_SELF = "self";
  86. public static final String ATTR_PARENT = "parent";
  87. // The two names below are for compatibility
  88. public static final String ATTR_MY = "my";
  89. public static final String ATTR_CURRENT_TIME = "CurrentTime";
  90. // These versions are actually taken from an external file in the original cpp source code
  91. private static final int CLASSAD_VERSION_MAJOR = 8;
  92. private static final int CLASSAD_VERSION_MINOR = 0;
  93. private static final int CLASSAD_VERSION_PATCH = 0;
  94. private static final String CLASSAD_VERSION = "8.0.0";
  95. public static final ArrayList<String> specialAttrNames = new ArrayList<String>();
  96. static {
  97. specialAttrNames.add(ATTR_TOPLEVEL);
  98. specialAttrNames.add(ATTR_ROOT);
  99. specialAttrNames.add(ATTR_SELF);
  100. specialAttrNames.add(ATTR_PARENT);
  101. }
  102. public static final FunctionCall curr_time_expr = FunctionCall.createFunctionCall("time",
  103. new ExprList(new ClassAdObjectPool()), new ClassAdObjectPool());
  104. private ClassAd alternateScope;
  105. private final Map<CaseInsensitiveString, ExprTree> attrList;
  106. private ClassAd chainedParentAd;
  107. private ClassAdParser parser = null;
  108. private ClassAd newAd;
  109. /*
  110. * Constructors
  111. */
  112. public ClassAd(ClassAdObjectPool objectPool) {
  113. super(objectPool);
  114. parser = new ClassAdParser(this.objectPool);
  115. attrList = new HashMap<CaseInsensitiveString, ExprTree>();
  116. }
  117. @Override
  118. public void reset() {
  119. clear();
  120. }
  121. public boolean isReset() {
  122. return false;
  123. }
  124. public ClassAd getAlternateScope() {
  125. return alternateScope;
  126. }
  127. public void setAlternateScope(ClassAd alternateScope) {
  128. this.alternateScope = alternateScope;
  129. }
  130. public Map<CaseInsensitiveString, ExprTree> getAttrList() {
  131. return attrList;
  132. }
  133. public void classAdLibraryVersion(AMutableInt32 major, AMutableInt32 minor, AMutableInt32 patch) {
  134. major.setValue(CLASSAD_VERSION_MAJOR);
  135. minor.setValue(CLASSAD_VERSION_MINOR);
  136. patch.setValue(CLASSAD_VERSION_PATCH);
  137. }
  138. public static void classAdLibraryVersion(AMutableString version_string) {
  139. version_string.setValue(CLASSAD_VERSION);
  140. }
  141. public static ArrayList<String> getSpecialAttrNames() {
  142. return specialAttrNames;
  143. }
  144. public static FunctionCall getCurrentTimeExpr() {
  145. return curr_time_expr;
  146. }
  147. public boolean copyFrom(ClassAd ad) throws HyracksDataException {
  148. boolean succeeded = true;
  149. if (this == ad) {
  150. succeeded = false;
  151. } else {
  152. clear();
  153. // copy scoping attributes
  154. super.copyFrom(ad);
  155. chainedParentAd = ad.chainedParentAd;
  156. alternateScope = ad.alternateScope;
  157. for (Entry<CaseInsensitiveString, ExprTree> attr : ad.attrList.entrySet()) {
  158. ExprTree tree = objectPool.mutableExprPool.get();
  159. CaseInsensitiveString key = objectPool.caseInsensitiveStringPool.get();
  160. tree.copyFrom(attr.getValue());
  161. key.set(attr.getKey().get());
  162. attrList.put(key, tree);
  163. }
  164. }
  165. return succeeded;
  166. }
  167. public boolean update(ClassAd ad) throws HyracksDataException {
  168. for (Entry<CaseInsensitiveString, ExprTree> attr : ad.attrList.entrySet()) {
  169. ExprTree tree = objectPool.mutableExprPool.get();
  170. CaseInsensitiveString key = objectPool.caseInsensitiveStringPool.get();
  171. tree.copyFrom(attr.getValue());
  172. key.set(attr.getKey().get());
  173. attrList.put(key, tree);
  174. }
  175. return true;
  176. }
  177. public boolean updateFromChain(ClassAd ad) throws HyracksDataException {
  178. ClassAd parent = ad.chainedParentAd;
  179. if (parent != null) {
  180. if (!updateFromChain(parent)) {
  181. return false;
  182. }
  183. }
  184. return update(ad);
  185. }
  186. public boolean copyFromChain(ClassAd ad) throws HyracksDataException {
  187. if (this == ad) {
  188. return false;
  189. }
  190. clear();
  191. super.copyFrom(ad);
  192. return updateFromChain(ad);
  193. }
  194. @Override
  195. public boolean sameAs(ExprTree tree) {
  196. boolean is_same;
  197. ExprTree pSelfTree = tree.self();
  198. if (this == pSelfTree) {
  199. is_same = true;
  200. } else if (pSelfTree.getKind() != NodeKind.CLASSAD_NODE) {
  201. is_same = false;
  202. } else {
  203. ClassAd other_classad;
  204. other_classad = (ClassAd) pSelfTree;
  205. if (attrList.size() != other_classad.attrList.size()) {
  206. is_same = false;
  207. } else {
  208. is_same = true;
  209. for (Entry<CaseInsensitiveString, ExprTree> attr : attrList.entrySet()) {
  210. ExprTree this_tree = attr.getValue();
  211. ExprTree other_tree = other_classad.lookup(attr.getKey());
  212. if (other_tree == null) {
  213. is_same = false;
  214. break;
  215. } else if (!this_tree.sameAs(other_tree)) {
  216. is_same = false;
  217. break;
  218. }
  219. }
  220. }
  221. }
  222. return is_same;
  223. }
  224. public void clear() {
  225. unchain();
  226. attrList.clear();
  227. if (alternateScope != null) {
  228. alternateScope.clear();
  229. }
  230. }
  231. public void unchain() {
  232. if (chainedParentAd != null) {
  233. chainedParentAd.clear();
  234. }
  235. }
  236. public void getComponents(Map<CaseInsensitiveString, ExprTree> attrs, ClassAdObjectPool objectPool)
  237. throws HyracksDataException {
  238. attrs.clear();
  239. for (Entry<CaseInsensitiveString, ExprTree> attr : this.attrList.entrySet()) {
  240. ExprTree tree = objectPool.mutableExprPool.get();
  241. CaseInsensitiveString key = objectPool.caseInsensitiveStringPool.get();
  242. tree.copyFrom(attr.getValue());
  243. key.set(attr.getKey().get());
  244. attrs.put(key, tree);
  245. }
  246. }
  247. public ClassAd privateGetDeepScope(ExprTree tree) throws HyracksDataException {
  248. if (tree == null) {
  249. return (null);
  250. }
  251. ClassAd scope = objectPool.classAdPool.get();
  252. Value val = objectPool.valuePool.get();
  253. tree.setParentScope(this);
  254. if (!tree.publicEvaluate(val) || !val.isClassAdValue(scope)) {
  255. return (null);
  256. }
  257. return (scope);
  258. }
  259. // --- begin integer attribute insertion ----
  260. public boolean insertAttr(String name, int value, NumberFactor f) throws HyracksDataException {
  261. ExprTree plit;
  262. Value val = objectPool.valuePool.get();
  263. val.setIntegerValue(value);
  264. plit = Literal.createLiteral(val, f, objectPool);
  265. return insert(name, plit);
  266. }
  267. public boolean insertAttr(String name, int value) throws HyracksDataException {
  268. return insertAttr(name, value, NumberFactor.NO_FACTOR);
  269. }
  270. public boolean insertAttr(String name, long value, NumberFactor f) throws HyracksDataException {
  271. ExprTree plit;
  272. Value val = objectPool.valuePool.get();
  273. val.setIntegerValue(value);
  274. plit = Literal.createLiteral(val, f, objectPool);
  275. return (insert(name, plit));
  276. }
  277. public boolean insertAttr(String name, long value) throws HyracksDataException {
  278. return insertAttr(name, value, NumberFactor.NO_FACTOR);
  279. }
  280. public boolean deepInsertAttr(ExprTree scopeExpr, String name, int value, NumberFactor f)
  281. throws HyracksDataException {
  282. ClassAd ad = privateGetDeepScope(scopeExpr);
  283. if (ad == null) {
  284. return (false);
  285. }
  286. return (ad.insertAttr(name, value, f));
  287. }
  288. public boolean deepInsertAttr(ExprTree scopeExpr, String name, long value, NumberFactor f)
  289. throws HyracksDataException {
  290. ClassAd ad = privateGetDeepScope(scopeExpr);
  291. if (ad == null) {
  292. return (false);
  293. }
  294. return (ad.insertAttr(name, value, f));
  295. }
  296. // --- end integer attribute insertion ---
  297. // --- begin real attribute insertion ---
  298. public boolean insertAttr(String name, double value, NumberFactor f) throws HyracksDataException {
  299. ExprTree plit;
  300. Value val = objectPool.valuePool.get();
  301. val.setRealValue(value);
  302. plit = Literal.createLiteral(val, f, objectPool);
  303. return (insert(name, plit));
  304. }
  305. public boolean deepInsertAttr(ExprTree scopeExpr, String name, double value, NumberFactor f)
  306. throws HyracksDataException {
  307. ClassAd ad = privateGetDeepScope(scopeExpr);
  308. if (ad == null) {
  309. return (false);
  310. }
  311. return (ad.insertAttr(name, value, f));
  312. }
  313. // --- end real attribute insertion
  314. // --- begin boolean attribute insertion
  315. public boolean insertAttr(String name, boolean value) throws HyracksDataException {
  316. ExprTree plit;
  317. Value val = objectPool.valuePool.get();
  318. val.setBooleanValue(value);
  319. plit = Literal.createLiteral(val, objectPool);
  320. return (insert(name, plit));
  321. }
  322. public boolean deepInsertAttr(ExprTree scopeExpr, String name, boolean value) throws HyracksDataException {
  323. ClassAd ad = privateGetDeepScope(scopeExpr);
  324. if (ad == null) {
  325. return (false);
  326. }
  327. return (ad.insertAttr(name, value));
  328. }
  329. // --- end boolean attribute insertion
  330. // --- begin string attribute insertion
  331. public boolean insertAttr(String name, AMutableCharArrayString value) throws HyracksDataException {
  332. ExprTree plit;
  333. Value val = objectPool.valuePool.get();
  334. val.setStringValue(value);
  335. plit = Literal.createLiteral(val, objectPool);
  336. return (insert(name, plit));
  337. }
  338. public boolean deepInsertAttr(ExprTree scopeExpr, String name, AMutableCharArrayString value)
  339. throws HyracksDataException {
  340. ClassAd ad = privateGetDeepScope(scopeExpr);
  341. if (ad == null) {
  342. return (false);
  343. }
  344. return (ad.insertAttr(name, value));
  345. }
  346. public boolean insertAttr(String name, String value) throws HyracksDataException {
  347. ExprTree plit;
  348. Value val = objectPool.valuePool.get();
  349. val.setStringValue(value);
  350. plit = Literal.createLiteral(val, objectPool);
  351. return (insert(name, plit));
  352. }
  353. public boolean deepInsertAttr(ExprTree scopeExpr, String name, String value) throws HyracksDataException {
  354. ClassAd ad = privateGetDeepScope(scopeExpr);
  355. if (ad == null) {
  356. return (false);
  357. }
  358. return (ad.insertAttr(name, value));
  359. }
  360. // --- end string attribute insertion
  361. public boolean insert(String serialized_nvp) throws IOException {
  362. boolean bRet = false;
  363. String name, szValue;
  364. int pos, npos, vpos;
  365. int bpos = 0;
  366. // comes in as "name = value" "name= value" or "name =value"
  367. npos = pos = serialized_nvp.indexOf('=');
  368. // only try to process if the string is valid
  369. if (pos >= 0) {
  370. while (npos > 0 && serialized_nvp.charAt(npos - 1) == ' ') {
  371. npos--;
  372. }
  373. while (bpos < npos && serialized_nvp.charAt(bpos) == ' ') {
  374. bpos++;
  375. }
  376. name = serialized_nvp.substring(bpos, npos);
  377. vpos = pos + 1;
  378. while (serialized_nvp.charAt(vpos) == ' ') {
  379. vpos++;
  380. }
  381. szValue = serialized_nvp.substring(vpos);
  382. if (name.charAt(0) == '\'') {
  383. // We don't handle quoted attribute names for caching here.
  384. // Hand the name-value-pair off to the parser as a one-attribute
  385. // ad and merge the results into this ad.
  386. newAd.clear();
  387. name = "[" + serialized_nvp.toString() + "]";
  388. if (parser.parseClassAd(name, newAd, true)) {
  389. return update(newAd);
  390. } else {
  391. return false;
  392. }
  393. }
  394. ExprTree newTree;
  395. // we did not hit in the cache... parse the expression
  396. newTree = parser.ParseExpression(szValue);
  397. if (newTree != null) {
  398. // if caching is enabled, and we got to here then we know that the
  399. // cache doesn't already have an entry for this name:value, so add
  400. // it to the cache now.
  401. if (newTree.getKind() != NodeKind.LITERAL_NODE) {
  402. Literal lit = objectPool.literalPool.get();
  403. lit.getValue().setStringValue(szValue);
  404. bRet = insert(name, lit, false);
  405. } else {
  406. bRet = insert(name, newTree, false);
  407. }
  408. }
  409. } // end if pos >=0
  410. return bRet;
  411. }
  412. public boolean insert(String attrName, ExprTree expr) throws HyracksDataException {
  413. ExprTree tree = expr.copy();
  414. boolean result = insert(attrName, tree.isTreeHolder() ? ((ExprTreeHolder) tree).getInnerTree() : tree, false);
  415. return result;
  416. }
  417. public boolean insert(String attrName, ExprTree pRef, boolean cache) throws HyracksDataException {
  418. boolean bRet = false;
  419. ExprTree tree = pRef;
  420. // sanity checks
  421. if (attrName.isEmpty() || pRef == null) {
  422. throw new HyracksDataException("Attribute name is empty");
  423. }
  424. if (tree != null) {
  425. CaseInsensitiveString pstrAttr = objectPool.caseInsensitiveStringPool.get();
  426. pstrAttr.set(attrName);
  427. ExprTreeHolder mutableTree = objectPool.mutableExprPool.get();
  428. mutableTree.copyFrom(tree);
  429. // parent of the expression is this classad
  430. tree.setParentScope(this);
  431. attrList.put(pstrAttr, mutableTree);
  432. bRet = true;
  433. }
  434. return (bRet);
  435. }
  436. public boolean deepInsert(ExprTree scopeExpr, String name, ExprTree tree) throws HyracksDataException {
  437. ClassAd ad = privateGetDeepScope(scopeExpr);
  438. if (ad == null) {
  439. return (false);
  440. }
  441. return (ad.insert(name, tree));
  442. }
  443. // --- end expression insertion
  444. // --- begin lookup methods
  445. public ExprTree lookup(String name) {
  446. CaseInsensitiveString aString = objectPool.caseInsensitiveStringPool.get();
  447. aString.set(name);
  448. ExprTree expr = lookup(aString);
  449. return expr;
  450. }
  451. public ExprTree lookup(CaseInsensitiveString name) {
  452. /*
  453. * System.out.println("Lookup Printing all attributes with their values:");
  454. * for (Entry<String, ExprTree> entry : attrList.entrySet()) {
  455. * System.out.println(entry.getKey() + ":" + entry.getValue().getKind());
  456. * }
  457. */
  458. ExprTree attr = attrList.get(name);
  459. if (attr != null) {
  460. return attr;
  461. } else if (chainedParentAd != null) {
  462. return chainedParentAd.lookup(name);
  463. } else {
  464. return null;
  465. }
  466. }
  467. public ExprTree lookupInScope(AMutableCharArrayString name, ClassAd finalScope) throws HyracksDataException {
  468. EvalState state = objectPool.evalStatePool.get();
  469. ExprTreeHolder tree = objectPool.mutableExprPool.get();
  470. int rval;
  471. state.setScopes(this);
  472. rval = lookupInScope(name.toString(), tree, state);
  473. if (rval == EvalResult.EVAL_OK.ordinal()) {
  474. finalScope.setValue(state.getCurAd());
  475. return (tree);
  476. }
  477. finalScope.setValue(null);
  478. return null;
  479. }
  480. public int lookupInScope(String name, ExprTreeHolder expr, EvalState state) throws HyracksDataException {
  481. ClassAd current = this;
  482. ClassAd superScope = objectPool.classAdPool.get();
  483. expr.setInnerTree(null);
  484. while (expr.getInnerTree() == null && current != null) {
  485. // lookups/eval's being done in the 'current' ad
  486. state.getCurAd().setValue(current);
  487. // lookup in current scope
  488. expr.setInnerTree(current.lookup(name));
  489. if ((expr.getInnerTree() != null)) {
  490. return EvalResult.EVAL_OK.ordinal();
  491. }
  492. try {
  493. if (state.getRootAd() == null) {
  494. return (EvalResult.EVAL_UNDEF.ordinal());
  495. } else if (state.getRootAd().equals(current)) {
  496. superScope = null;
  497. } else {
  498. superScope = current.parentScope;
  499. }
  500. } catch (Throwable th) {
  501. th.printStackTrace();
  502. throw th;
  503. }
  504. if (!getSpecialAttrNames().contains(name)) {
  505. // continue searching from the superScope ...
  506. current = superScope;
  507. if (current == this) { // NAC - simple loop checker
  508. return (EvalResult.EVAL_UNDEF.ordinal());
  509. }
  510. } else if (name.equalsIgnoreCase(ATTR_TOPLEVEL) || name.equalsIgnoreCase(ATTR_ROOT)) {
  511. // if the "toplevel" attribute was requested ...
  512. expr.setInnerTree(state.getRootAd());
  513. if (expr.getInnerTree() == null) { // NAC - circularity so no root
  514. return EvalResult.EVAL_FAIL.ordinal(); // NAC
  515. } // NAC
  516. return (expr.getInnerTree() != null ? EvalResult.EVAL_OK.ordinal() : EvalResult.EVAL_UNDEF.ordinal());
  517. } else if (name.equalsIgnoreCase(ATTR_SELF) || name.equalsIgnoreCase(ATTR_MY)) {
  518. // if the "self" ad was requested
  519. expr.setInnerTree(state.getCurAd());
  520. return (expr.getInnerTree() != null ? EvalResult.EVAL_OK.ordinal() : EvalResult.EVAL_UNDEF.ordinal());
  521. } else if (name.equalsIgnoreCase(ATTR_PARENT)) {
  522. // the lexical parent
  523. expr.setInnerTree(superScope);
  524. return (expr.getInnerTree() != null ? EvalResult.EVAL_OK.ordinal() : EvalResult.EVAL_UNDEF.ordinal());
  525. } else if (name.equalsIgnoreCase(ATTR_CURRENT_TIME)) {
  526. // an alias for time() from old ClassAds
  527. expr.setInnerTree(getCurrentTimeExpr());
  528. return (expr.getInnerTree() != null ? EvalResult.EVAL_OK.ordinal() : EvalResult.EVAL_UNDEF.ordinal());
  529. }
  530. }
  531. return (EvalResult.EVAL_UNDEF.ordinal());
  532. }
  533. // --- end lookup methods
  534. // --- begin deletion methods
  535. public boolean delete(String name) throws HyracksDataException {
  536. CaseInsensitiveString aString = objectPool.caseInsensitiveStringPool.get();
  537. aString.set(name);
  538. boolean success = delete(aString);
  539. return success;
  540. }
  541. public boolean delete(CaseInsensitiveString name) throws HyracksDataException {
  542. boolean deleted_attribute;
  543. deleted_attribute = false;
  544. if (attrList.containsKey(name)) {
  545. attrList.remove(name);
  546. deleted_attribute = true;
  547. }
  548. // If the attribute is in the chained parent, we delete define it
  549. // here as undefined, whether or not it was defined here. This is
  550. // behavior copied from old ClassAds. It's also one reason you
  551. // probably don't want to use this feature in the future.
  552. if (chainedParentAd != null && chainedParentAd.lookup(name) != null) {
  553. Value undefined_value = objectPool.valuePool.get();
  554. undefined_value.setUndefinedValue();
  555. deleted_attribute = true;
  556. ExprTree plit = Literal.createLiteral(undefined_value, objectPool);
  557. insert(name.get(), plit);
  558. }
  559. return deleted_attribute;
  560. }
  561. public boolean deepDelete(ExprTree scopeExpr, String name) throws HyracksDataException {
  562. ClassAd ad = privateGetDeepScope(scopeExpr);
  563. if (ad == null) {
  564. return (false);
  565. }
  566. CaseInsensitiveString aString = objectPool.caseInsensitiveStringPool.get();
  567. aString.set(name);;
  568. boolean success = ad.delete(aString);
  569. return success;
  570. }
  571. // --- end deletion methods
  572. // --- begin removal methods
  573. public ExprTree remove(String name) throws HyracksDataException {
  574. ExprTree tree = null;
  575. if (attrList.containsKey(name)) {
  576. tree = attrList.remove(name);
  577. }
  578. // If the attribute is in the chained parent, we delete define it
  579. // here as undefined, whether or not it was defined here. This is
  580. // behavior copied from old ClassAds. It's also one reason you
  581. // probably don't want to use this feature in the future.
  582. if (chainedParentAd != null && chainedParentAd.lookup(name) != null) {
  583. if (tree == null) {
  584. tree = chainedParentAd.lookup(name);
  585. }
  586. Value undefined_value = objectPool.valuePool.get();
  587. undefined_value.setUndefinedValue();
  588. ExprTree plit = Literal.createLiteral(undefined_value, objectPool);
  589. //why??
  590. insert(name, plit);
  591. }
  592. return tree;
  593. }
  594. public ExprTree deepRemove(ExprTree scopeExpr, String name) throws HyracksDataException {
  595. ClassAd ad = privateGetDeepScope(scopeExpr);
  596. if (ad == null) {
  597. return (null);
  598. }
  599. return (ad.remove(name));
  600. }
  601. // --- end removal methods
  602. @Override
  603. public void privateSetParentScope(ClassAd ad) {
  604. // already set by base class for this node; we shouldn't propagate
  605. // the call to sub-expressions because this is a new scope
  606. }
  607. public void modify(ClassAd mod) throws HyracksDataException {
  608. ClassAd ctx;
  609. ExprTree expr;
  610. Value val = objectPool.valuePool.get();
  611. // Step 0: Determine Context
  612. if ((expr = mod.lookup(Common.ATTR_CONTEXT)) != null) {
  613. if ((ctx = privateGetDeepScope(expr)) == null) {
  614. return;
  615. }
  616. } else {
  617. ctx = this;
  618. }
  619. // Step 1: Process Replace attribute
  620. if ((expr = mod.lookup(Common.ATTR_REPLACE)) != null) {
  621. ClassAd ad = objectPool.classAdPool.get();
  622. if (expr.publicEvaluate(val) && val.isClassAdValue(ad)) {
  623. ctx.clear();
  624. ctx.update(ad);
  625. }
  626. }
  627. // Step 2: Process Updates attribute
  628. if ((expr = mod.lookup(Common.ATTR_UPDATES)) != null) {
  629. ClassAd ad = objectPool.classAdPool.get();
  630. if (expr.publicEvaluate(val) && val.isClassAdValue(ad)) {
  631. ctx.update(ad);
  632. }
  633. }
  634. // Step 3: Process Deletes attribute
  635. if ((expr = mod.lookup(Common.ATTR_DELETES)) != null) {
  636. ExprList list = objectPool.exprListPool.get();
  637. AMutableCharArrayString attrName = objectPool.strPool.get();
  638. // make a first pass to check that it is a list of strings ...
  639. if (!expr.publicEvaluate(val) || !val.isListValue(list)) {
  640. return;
  641. }
  642. for (ExprTree aExpr : list.getExprList()) {
  643. if (!aExpr.publicEvaluate(val) || !val.isStringValue(attrName)) {
  644. return;
  645. }
  646. }
  647. // now go through and delete all the named attributes ...
  648. for (ExprTree aExpr : list.getExprList()) {
  649. if (aExpr.publicEvaluate(val) && val.isStringValue(attrName)) {
  650. ctx.delete(attrName.toString());
  651. }
  652. }
  653. }
  654. }
  655. @Override
  656. public ExprTree copy() throws HyracksDataException {
  657. ClassAd newAd = objectPool.classAdPool.get();
  658. newAd.parentScope = (parentScope == null) ? null : (ClassAd) parentScope.copy();
  659. newAd.chainedParentAd = chainedParentAd == null ? null : (ClassAd) chainedParentAd.copy();
  660. for (Entry<CaseInsensitiveString, ExprTree> entry : attrList.entrySet()) {
  661. newAd.insert(entry.getKey().get(), entry.getValue(), false);
  662. }
  663. return newAd;
  664. }
  665. @Override
  666. public boolean publicEvaluate(EvalState state, Value val) throws HyracksDataException {
  667. val.setClassAdValue(this);
  668. return (true);
  669. }
  670. @Override
  671. public boolean privateEvaluate(EvalState state, Value val, ExprTreeHolder tree) throws HyracksDataException {
  672. val.setClassAdValue(this);
  673. tree.setInnerTree(copy());
  674. return true;
  675. }
  676. @Override
  677. public boolean privateFlatten(EvalState state, Value val, ExprTreeHolder tree, AMutableInt32 i)
  678. throws HyracksDataException {
  679. ClassAd newAd = objectPool.classAdPool.get();
  680. Value eval = objectPool.valuePool.get();
  681. ExprTreeHolder etree = objectPool.mutableExprPool.get();;
  682. ClassAd oldAd;
  683. tree.setInnerTree(null); // Just to be safe... wenger 2003-12-11.
  684. oldAd = state.getCurAd();
  685. state.setCurAd(this);
  686. for (Entry<CaseInsensitiveString, ExprTree> entry : attrList.entrySet()) {
  687. // flatten expression
  688. if (!entry.getValue().publicFlatten(state, eval, etree)) {
  689. tree.setInnerTree(null);;
  690. eval.setUndefinedValue();
  691. state.setCurAd(oldAd);
  692. return false;
  693. }
  694. // if a value was obtained, convert it to a literal
  695. if (etree.getInnerTree() == null) {
  696. etree.setInnerTree(Literal.createLiteral(eval, objectPool));
  697. if (etree.getInnerTree() == null) {
  698. tree.setInnerTree(null);
  699. eval.setUndefinedValue();
  700. state.setCurAd(oldAd);
  701. return false;
  702. }
  703. }
  704. CaseInsensitiveString key = objectPool.caseInsensitiveStringPool.get();
  705. ExprTreeHolder value = objectPool.mutableExprPool.get();
  706. key.set(entry.getKey().get());
  707. value.copyFrom(etree);
  708. newAd.attrList.put(key, value);
  709. eval.setUndefinedValue();
  710. }
  711. tree.setInnerTree(newAd);
  712. state.setCurAd(oldAd);
  713. return true;
  714. }
  715. public boolean evaluateAttr(String attr, Value val) throws HyracksDataException {
  716. EvalState state = objectPool.evalStatePool.get();
  717. ExprTreeHolder tree = objectPool.mutableExprPool.get();
  718. state.setScopes(this);
  719. switch (lookupInScope(attr, tree, state)) {
  720. case ExprTree.EVAL_FAIL_Int:
  721. return false;
  722. case ExprTree.EVAL_OK_Int:
  723. return (tree.publicEvaluate(state, val));
  724. case ExprTree.EVAL_UNDEF_Int:
  725. val.setUndefinedValue();
  726. return (true);
  727. case ExprTree.EVAL_ERROR_Int:
  728. val.setErrorValue();
  729. return (true);
  730. default:
  731. return false;
  732. }
  733. }
  734. public boolean evaluateExpr(String buf, Value result) throws HyracksDataException {
  735. boolean successfully_evaluated;
  736. ExprTreeHolder tree = objectPool.mutableExprPool.get();
  737. ClassAdParser parser = objectPool.classAdParserPool.get();
  738. try {
  739. if (parser.parseExpression(buf, tree)) {
  740. successfully_evaluated = evaluateExpr(tree, result);
  741. } else {
  742. successfully_evaluated = false;
  743. }
  744. } catch (IOException e) {
  745. throw new HyracksDataException(e);
  746. }
  747. return successfully_evaluated;
  748. }
  749. public boolean evaluateExpr(ExprTreeHolder tree, Value val) throws HyracksDataException {
  750. EvalState state = objectPool.evalStatePool.get();
  751. state.setScopes(this);
  752. return (tree.publicEvaluate(state, val));
  753. }
  754. public boolean evaluateExpr(ExprTreeHolder tree, Value val, ExprTreeHolder sig) throws HyracksDataException {
  755. EvalState state = objectPool.evalStatePool.get();
  756. state.setScopes(this);
  757. return (tree.publicEvaluate(state, val, sig));
  758. }
  759. public boolean evaluateAttrInt(String attr, AMutableInt64 i) throws HyracksDataException {
  760. Value val = objectPool.valuePool.get();
  761. return (evaluateAttr(attr, val) && val.isIntegerValue(i));
  762. }
  763. public boolean evaluateAttrReal(String attr, AMutableDouble r) throws HyracksDataException {
  764. Value val = objectPool.valuePool.get();
  765. return (evaluateAttr(attr, val) && val.isRealValue(r));
  766. }
  767. public boolean evaluateAttrNumber(String attr, AMutableInt64 i) throws HyracksDataException {
  768. Value val = objectPool.valuePool.get();
  769. return (evaluateAttr(attr, val) && val.isNumber(i));
  770. }
  771. public boolean evaluateAttrNumber(String attr, AMutableDouble r) throws HyracksDataException {
  772. Value val = objectPool.valuePool.get();
  773. return (evaluateAttr(attr, val) && val.isNumber(r));
  774. }
  775. public boolean evaluateAttrString(String attr, AMutableCharArrayString buf, int len) throws HyracksDataException {
  776. Value val = objectPool.valuePool.get();
  777. return (evaluateAttr(attr, val) && val.isStringValue(buf, len));
  778. }
  779. public boolean evaluateAttrString(String attr, AMutableCharArrayString buf) throws HyracksDataException {
  780. Value val = objectPool.valuePool.get();
  781. return (evaluateAttr(attr, val) && val.isStringValue(buf));
  782. }
  783. public boolean evaluateAttrBool(String attr, MutableBoolean b) throws HyracksDataException {
  784. Value val = objectPool.valuePool.get();
  785. return (evaluateAttr(attr, val) && val.isBooleanValue(b));
  786. }
  787. public boolean evaluateAttrBoolEquiv(String attr, MutableBoolean b) throws HyracksDataException {
  788. Value val = objectPool.valuePool.get();
  789. return (evaluateAttr(attr, val) && val.isBooleanValueEquiv(b));
  790. }
  791. /*
  792. * Reference is an ordered set of Strings <The ordering uses less than ignore case>. Example
  793. * below
  794. * TreeSet<String> references = new TreeSet<String>(
  795. * new Comparator<String>(){
  796. * public int compare(String o1, String o2) {
  797. * return o1.compareToIgnoreCase(o2);
  798. * }
  799. * });
  800. *
  801. * // PortReferences is a Map<ClassAd,OrderedSet<Strings>>
  802. */
  803. public boolean getExternalReferences(ExprTree tree, TreeSet<String> refs, boolean fullNames)
  804. throws HyracksDataException {
  805. EvalState state = objectPool.evalStatePool.get();
  806. // Treat this ad as the root of the tree for reference tracking.
  807. // If an attribute is only present in a parent scope of this ad,
  808. // then we want to treat it as an external reference.
  809. state.setRootAd(this);
  810. state.setCurAd(this);
  811. return (privateGetExternalReferences(tree, this, state, refs, fullNames));
  812. }
  813. public boolean privateGetExternalReferences(ExprTree expr, ClassAd ad, EvalState state, TreeSet<String> refs,
  814. boolean fullNames) throws HyracksDataException {
  815. if (expr.isTreeHolder()) {
  816. expr = ((ExprTreeHolder) expr).getInnerTree();
  817. }
  818. switch (expr.getKind()) {
  819. case LITERAL_NODE:
  820. // no external references here
  821. return (true);
  822. case ATTRREF_NODE: {
  823. ClassAd start = objectPool.classAdPool.get();
  824. ExprTreeHolder tree = objectPool.mutableExprPool.get();
  825. ExprTreeHolder result = objectPool.mutableExprPool.get();
  826. AMutableCharArrayString attr = objectPool.strPool.get();
  827. Value val = objectPool.valuePool.get();
  828. MutableBoolean abs = objectPool.boolPool.get();
  829. ((AttributeReference) expr).getComponents(tree, attr, abs);
  830. // establish starting point for attribute search
  831. if (tree.getInnerTree() == null) {
  832. start = abs.booleanValue() ? state.getRootAd() : state.getCurAd();
  833. if (abs.booleanValue() && (start == null)) {// NAC - circularity so no root
  834. return false; // NAC
  835. } // NAC
  836. } else {
  837. if (!tree.publicEvaluate(state, val)) {
  838. return (false);
  839. }
  840. // if the tree evals to undefined, the external references
  841. // are in the tree part
  842. if (val.isUndefinedValue()) {
  843. if (fullNames) {
  844. AMutableCharArrayString fullName = objectPool.strPool.get();
  845. if (tree.getInnerTree() != null) {
  846. ClassAdUnParser unparser = objectPool.prettyPrintPool.get();
  847. unparser.unparse(fullName, tree);
  848. fullName.appendChar('.');
  849. }
  850. fullName.appendString(attr);
  851. refs.add(fullName.toString());
  852. return true;
  853. } else {
  854. if (state.getDepthRemaining() <= 0) {
  855. return false;
  856. }
  857. state.decrementDepth();
  858. boolean ret = privateGetExternalReferences(tree, ad, state, refs, fullNames);
  859. state.incrementDepth();
  860. return ret;
  861. }
  862. }
  863. // otherwise, if the tree didn't evaluate to a classad,
  864. // we have a problem
  865. if (!val.isClassAdValue(start)) {
  866. return (false);
  867. }
  868. }
  869. // lookup for attribute
  870. ClassAd curAd = state.getCurAd();
  871. switch (start.lookupInScope(attr.toString(), result, state)) {
  872. case EVAL_ERROR_Int:
  873. // some error
  874. return (false);
  875. case EVAL_UNDEF_Int:
  876. // attr is external
  877. refs.add(attr.toString());
  878. state.setCurAd(curAd);
  879. return (true);
  880. case EVAL_OK_Int: {
  881. // attr is internal; find external refs in result
  882. if (state.getDepthRemaining() <= 0) {
  883. state.setCurAd(curAd);
  884. return false;
  885. }
  886. state.decrementDepth();
  887. boolean rval = privateGetExternalReferences(result, ad, state, refs, fullNames);
  888. state.incrementDepth();
  889. state.setCurAd(curAd);
  890. return (rval);
  891. }
  892. case EVAL_FAIL_Int:
  893. default:
  894. // enh??
  895. return (false);
  896. }
  897. }
  898. case OP_NODE: {
  899. // recurse on subtrees
  900. AMutableInt32 opKind = objectPool.int32Pool.get();
  901. ExprTreeHolder t1 = objectPool.mutableExprPool.get();
  902. ExprTreeHolder t2 = objectPool.mutableExprPool.get();
  903. ExprTreeHolder t3 = objectPool.mutableExprPool.get();
  904. ((Operation) expr).getComponents(opKind, t1, t2, t3);
  905. if (t1.getInnerTree() != null && !privateGetExternalReferences(t1, ad, state, refs, fullNames)) {
  906. return (false);
  907. }
  908. if (t2.getInnerTree() != null && !privateGetExternalReferences(t2, ad, state, refs, fullNames)) {
  909. return (false);
  910. }
  911. if (t3.getInnerTree() != null && !privateGetExternalReferences(t3, ad, state, refs, fullNames)) {
  912. return (false);
  913. }
  914. return (true);
  915. }
  916. case FN_CALL_NODE: {
  917. // recurse on subtrees
  918. AMutableCharArrayString fnName = objectPool.strPool.get();
  919. ExprList args = objectPool.exprListPool.get();
  920. ((FunctionCall) expr).getComponents(fnName, args);
  921. for (ExprTree tree : args.getExprList()) {
  922. if (!privateGetExternalReferences(tree, ad, state, refs, fullNames)) {
  923. return (false);
  924. }
  925. }
  926. return (true);
  927. }
  928. case CLASSAD_NODE: {
  929. // recurse on subtrees
  930. Map<CaseInsensitiveString, ExprTree> attrs = objectPool.strToExprPool.get();
  931. ((ClassAd) expr).getComponents(attrs, objectPool);
  932. for (Entry<CaseInsensitiveString, ExprTree> entry : attrs.entrySet()) {
  933. if (state.getDepthRemaining() <= 0) {
  934. return false;
  935. }
  936. state.decrementDepth();
  937. boolean ret = privateGetExternalReferences(entry.getValue(), ad, state, refs, fullNames);
  938. state.incrementDepth();
  939. if (!ret) {
  940. return (false);
  941. }
  942. }
  943. return (true);
  944. }
  945. case EXPR_LIST_NODE: {
  946. // recurse on subtrees
  947. ExprList exprs = objectPool.exprListPool.get();
  948. ((ExprList) expr).getComponents(exprs);
  949. for (ExprTree exprTree : exprs.getExprList()) {
  950. if (state.getDepthRemaining() <= 0) {
  951. return false;
  952. }
  953. state.decrementDepth();
  954. boolean ret = privateGetExternalReferences(exprTree, ad, state, refs, fullNames);
  955. state.incrementDepth();
  956. if (!ret) {
  957. return (false);
  958. }
  959. }
  960. return (true);
  961. }
  962. default:
  963. return false;
  964. }
  965. }
  966. // PortReferences is a Map<ClassAd,TreeSet<Strings>>
  967. public boolean getExternalReferences(ExprTree tree, Map<ClassAd, TreeSet<String>> refs)
  968. throws HyracksDataException {
  969. EvalState state = objectPool.evalStatePool.get();
  970. // Treat this ad as the root of the tree for reference tracking.
  971. // If an attribute is only present in a parent scope of this ad,
  972. // then we want to treat it as an external reference.
  973. state.setRootAd(this);
  974. state.setCurAd(this);
  975. return (privateGetExternalReferences(tree, this, state, refs));
  976. }
  977. public boolean privateGetExternalReferences(ExprTree expr, ClassAd ad, EvalState state,
  978. Map<ClassAd, TreeSet<String>> refs) throws HyracksDataException {
  979. switch (expr.getKind()) {
  980. case LITERAL_NODE:
  981. // no external references here
  982. return (true);
  983. case ATTRREF_NODE: {
  984. ClassAd start = objectPool.classAdPool.get();
  985. ExprTreeHolder tree = objectPool.mutableExprPool.get();
  986. ExprTreeHolder result = objectPool.mutableExprPool.get();
  987. AMutableCharArrayString attr = objectPool.strPool.get();
  988. Value val = objectPool.valuePool.get();
  989. MutableBoolean abs = objectPool.boolPool.get();
  990. ((AttributeReference) expr).getComponents(tree, attr, abs);
  991. // establish starting point for attribute search
  992. if (tree.getInnerTree() == null) {
  993. start = abs.booleanValue() ? state.getRootAd() : state.getCurAd();
  994. if (abs.booleanValue() && (start == null)) {// NAC - circularity so no root
  995. return false; // NAC
  996. } // NAC
  997. } else {
  998. if (!tree.publicEvaluate(state, val)) {
  999. return (false);
  1000. }
  1001. // if the tree evals to undefined, the external references
  1002. // are in the tree part
  1003. if (val.isUndefinedValue()) {
  1004. return (privateGetExternalReferences(tree, ad, state, refs));
  1005. }
  1006. // otherwise, if the tree didn't evaluate to a classad,
  1007. // we have a problem
  1008. if (!val.isClassAdValue(start)) {
  1009. return (false);
  1010. }
  1011. // make sure that we are starting from a "valid" scope
  1012. if (!refs.containsKey(start) && start != this) {
  1013. return (false);
  1014. }
  1015. }
  1016. // lookup for attribute
  1017. ClassAd curAd = state.getCurAd();
  1018. TreeSet<String> pitr = refs.get(start);
  1019. if (pitr == null) {
  1020. pitr = objectPool.strSetPool.get();
  1021. refs.put(start, pitr);
  1022. }
  1023. switch (start.lookupInScope(attr.toString(), result, state)) {
  1024. case EVAL_ERROR_Int:
  1025. // some error
  1026. return (false);
  1027. case EVAL_UNDEF_Int:
  1028. // attr is external
  1029. pitr.add(attr.toString());
  1030. state.setCurAd(curAd);
  1031. return (true);
  1032. case EVAL_OK_Int: {
  1033. // attr is internal; find external refs in result
  1034. boolean rval = privateGetExternalReferences(result, ad, state, refs);
  1035. state.setCurAd(curAd);
  1036. return (rval);
  1037. }
  1038. case EVAL_FAIL_Int:
  1039. default:
  1040. // enh??
  1041. return (false);
  1042. }
  1043. }
  1044. case OP_NODE: {
  1045. // recurse on subtrees
  1046. AMutableInt32 opKind = objectPool.int32Pool.get();
  1047. ExprTreeHolder t1 = objectPool.mutableExprPool.get();
  1048. ExprTreeHolder t2 = objectPool.mutableExprPool.get();
  1049. ExprTreeHolder t3 = objectPool.mutableExprPool.get();
  1050. ((Operation) expr).getComponents(opKind, t1, t2, t3);
  1051. if (t1.getInnerTree() != null && !privateGetExternalReferences(t1, ad, state, refs)) {
  1052. return (false);
  1053. }
  1054. if (t2.getInnerTree() != null && !privateGetExternalReferences(t2, ad, state, refs)) {
  1055. return (false);
  1056. }
  1057. if (t3.getInnerTree() != null && !privateGetExternalReferences(t3, ad, state, refs)) {
  1058. return (false);
  1059. }
  1060. return (true);
  1061. }
  1062. case FN_CALL_NODE: {
  1063. // recurse on subtrees
  1064. AMutableCharArrayString fnName = objectPool.strPool.get();
  1065. ExprList args = objectPool.exprListPool.get();
  1066. ((FunctionCall) expr).getComponents(fnName, args);
  1067. for (ExprTree exprTree : args.getExprList()) {
  1068. if (!privateGetExternalReferences(exprTree, ad, state, refs)) {
  1069. return (false);
  1070. }
  1071. }
  1072. return (true);
  1073. }
  1074. case CLASSAD_NODE: {
  1075. // recurse on subtrees
  1076. HashMap<CaseInsensitiveString, ExprTree> attrs = objectPool.strToExprPool.get();
  1077. ((ClassAd) expr).getComponents(attrs, objectPool);
  1078. for (Entry<CaseInsensitiveString, ExprTree> entry : attrs.entrySet()) {
  1079. if (!privateGetExternalReferences(entry.getValue(), ad, state, refs)) {
  1080. return (false);
  1081. }
  1082. }
  1083. return (true);
  1084. }
  1085. case EXPR_LIST_NODE: {
  1086. // recurse on subtrees
  1087. ExprList exprs = objectPool.exprListPool.get();
  1088. ((ExprList) expr).getComponents(exprs);
  1089. for (ExprTree exprTree : exprs.getExprList()) {
  1090. if (!privateGetExternalReferences(exprTree, ad, state, refs)) {
  1091. return (false);
  1092. }
  1093. }
  1094. return (true);
  1095. }
  1096. default:
  1097. return false;
  1098. }
  1099. }
  1100. /*
  1101. * Reference is an ordered set of Strings <The ordering uses less than ignore case>. Example
  1102. * below
  1103. * TreeSet<String> references = new TreeSet<String>(
  1104. * new Comparator<String>(){
  1105. * public int compare(String o1, String o2) {
  1106. * return o1.compareToIgnoreCase(o2);
  1107. * }
  1108. * });
  1109. *
  1110. * // PortReferences is a Map<ClassAd,OrderedSet<Strings>>
  1111. */
  1112. public boolean getInternalReferences(ExprTree tree, TreeSet<String> refs, boolean fullNames)
  1113. throws HyracksDataException {
  1114. EvalState state = objectPool.evalStatePool.get();
  1115. // Treat this ad as the root of the tree for reference tracking.
  1116. // If an attribute is only present in a parent scope of this ad,
  1117. // then we want to treat it as an external reference.
  1118. state.setRootAd(this);
  1119. state.setCurAd(this);
  1120. return (privateGetInternalReferences(tree, this, state, refs, fullNames));
  1121. }
  1122. //this is closely modelled off of _GetExternalRefere