You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ComponentLocator.java 26KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720
  1. /*
  2. * Copyright 2000-2014 Vaadin Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.vaadin.client;
  17. import java.util.ArrayList;
  18. import java.util.Iterator;
  19. import java.util.List;
  20. import com.google.gwt.core.client.JavaScriptObject;
  21. import com.google.gwt.user.client.DOM;
  22. import com.google.gwt.user.client.Element;
  23. import com.google.gwt.user.client.ui.HasWidgets;
  24. import com.google.gwt.user.client.ui.RootPanel;
  25. import com.google.gwt.user.client.ui.Widget;
  26. import com.vaadin.client.ui.SubPartAware;
  27. import com.vaadin.client.ui.VCssLayout;
  28. import com.vaadin.client.ui.VGridLayout;
  29. import com.vaadin.client.ui.VOverlay;
  30. import com.vaadin.client.ui.VTabsheetPanel;
  31. import com.vaadin.client.ui.VUI;
  32. import com.vaadin.client.ui.VWindow;
  33. import com.vaadin.client.ui.orderedlayout.Slot;
  34. import com.vaadin.client.ui.orderedlayout.VAbstractOrderedLayout;
  35. import com.vaadin.client.ui.window.WindowConnector;
  36. import com.vaadin.shared.AbstractComponentState;
  37. import com.vaadin.shared.Connector;
  38. import com.vaadin.shared.communication.SharedState;
  39. /**
  40. * ComponentLocator provides methods for generating a String locator for a given
  41. * DOM element and for locating a DOM element using a String locator.
  42. */
  43. public class ComponentLocator {
  44. /**
  45. * Separator used in the String locator between a parent and a child widget.
  46. */
  47. private static final String PARENTCHILD_SEPARATOR = "/";
  48. /**
  49. * Separator used in the String locator between the part identifying the
  50. * containing widget and the part identifying the target element within the
  51. * widget.
  52. */
  53. private static final String SUBPART_SEPARATOR = "#";
  54. /**
  55. * String that identifies the root panel when appearing first in the String
  56. * locator.
  57. */
  58. private static final String ROOT_ID = "Root";
  59. /**
  60. * Reference to ApplicationConnection instance.
  61. */
  62. private ApplicationConnection client;
  63. /**
  64. * Construct a ComponentLocator for the given ApplicationConnection.
  65. *
  66. * @param client
  67. * ApplicationConnection instance for the application.
  68. */
  69. public ComponentLocator(ApplicationConnection client) {
  70. this.client = client;
  71. }
  72. /**
  73. * Generates a String locator which uniquely identifies the target element.
  74. * The {@link #getElementByPath(String)} method can be used for the inverse
  75. * operation, i.e. locating an element based on the return value from this
  76. * method.
  77. * <p>
  78. * Note that getElementByPath(getPathForElement(element)) == element is not
  79. * always true as {@link #getPathForElement(Element)} can return a path to
  80. * another element if the widget determines an action on the other element
  81. * will give the same result as the action on the target element.
  82. * </p>
  83. *
  84. * @since 5.4
  85. * @param targetElement
  86. * The element to generate a path for.
  87. * @return A String locator that identifies the target element or null if a
  88. * String locator could not be created.
  89. */
  90. public String getPathForElement(Element targetElement) {
  91. String pid = null;
  92. targetElement = getElement(targetElement);
  93. Element e = targetElement;
  94. while (true) {
  95. pid = ConnectorMap.get(client).getConnectorId(e);
  96. if (pid != null) {
  97. break;
  98. }
  99. e = DOM.getParent(e);
  100. if (e == null) {
  101. break;
  102. }
  103. }
  104. Widget w = null;
  105. if (pid != null) {
  106. // If we found a Paintable then we use that as reference. We should
  107. // find the Paintable for all but very special cases (like
  108. // overlays).
  109. w = ((ComponentConnector) ConnectorMap.get(client)
  110. .getConnector(pid)).getWidget();
  111. /*
  112. * Still if the Paintable contains a widget that implements
  113. * SubPartAware, we want to use that as a reference
  114. */
  115. Widget targetParent = findParentWidget(targetElement, w);
  116. while (targetParent != w && targetParent != null) {
  117. if (targetParent instanceof SubPartAware) {
  118. /*
  119. * The targetParent widget is a child of the Paintable and
  120. * the first parent (of the targetElement) that implements
  121. * SubPartAware
  122. */
  123. w = targetParent;
  124. break;
  125. }
  126. targetParent = targetParent.getParent();
  127. }
  128. }
  129. if (w == null) {
  130. // Check if the element is part of a widget that is attached
  131. // directly to the root panel
  132. RootPanel rootPanel = RootPanel.get();
  133. int rootWidgetCount = rootPanel.getWidgetCount();
  134. for (int i = 0; i < rootWidgetCount; i++) {
  135. Widget rootWidget = rootPanel.getWidget(i);
  136. if (rootWidget.getElement().isOrHasChild(targetElement)) {
  137. // The target element is contained by this root widget
  138. w = findParentWidget(targetElement, rootWidget);
  139. break;
  140. }
  141. }
  142. if (w != null) {
  143. // We found a widget but we should still see if we find a
  144. // SubPartAware implementor (we cannot find the Paintable as
  145. // there is no link from VOverlay to its paintable/owner).
  146. Widget subPartAwareWidget = findSubPartAwareParentWidget(w);
  147. if (subPartAwareWidget != null) {
  148. w = subPartAwareWidget;
  149. }
  150. }
  151. }
  152. if (w == null) {
  153. // Containing widget not found
  154. return null;
  155. }
  156. // Determine the path for the target widget
  157. String path = getPathForWidget(w);
  158. if (path == null) {
  159. /*
  160. * No path could be determined for the target widget. Cannot create
  161. * a locator string.
  162. */
  163. return null;
  164. }
  165. // The parent check is a work around for Firefox 15 which fails to
  166. // compare elements properly (#9534)
  167. if (w.getElement() == targetElement) {
  168. /*
  169. * We are done if the target element is the root of the target
  170. * widget.
  171. */
  172. return path;
  173. } else if (w instanceof SubPartAware) {
  174. /*
  175. * If the widget can provide an identifier for the targetElement we
  176. * let it do that
  177. */
  178. String elementLocator = ((SubPartAware) w)
  179. .getSubPartName(targetElement);
  180. if (elementLocator != null) {
  181. return path + SUBPART_SEPARATOR + elementLocator;
  182. }
  183. }
  184. /*
  185. * If everything else fails we use the DOM path to identify the target
  186. * element
  187. */
  188. String domPath = getDOMPathForElement(targetElement, w.getElement());
  189. if (domPath == null) {
  190. return path;
  191. } else {
  192. return path + domPath;
  193. }
  194. }
  195. /**
  196. * Returns the element passed to the method. Or in case of Firefox 15,
  197. * returns the real element that is in the DOM instead of the element passed
  198. * to the method (which is the same element but not ==).
  199. *
  200. * @param targetElement
  201. * the element to return
  202. * @return the element passed to the method
  203. */
  204. private Element getElement(Element targetElement) {
  205. if (targetElement == null) {
  206. return null;
  207. }
  208. if (!BrowserInfo.get().isFirefox()) {
  209. return targetElement;
  210. }
  211. if (BrowserInfo.get().getBrowserMajorVersion() != 15) {
  212. return targetElement;
  213. }
  214. // Firefox 15, you make me sad
  215. if (targetElement.getNextSibling() != null) {
  216. return (Element) targetElement.getNextSibling()
  217. .getPreviousSibling();
  218. }
  219. if (targetElement.getPreviousSibling() != null) {
  220. return (Element) targetElement.getPreviousSibling()
  221. .getNextSibling();
  222. }
  223. // No siblings so this is the only child
  224. return (Element) targetElement.getParentNode().getChild(0);
  225. }
  226. /**
  227. * Finds the first widget in the hierarchy (moving upwards) that implements
  228. * SubPartAware. Returns the SubPartAware implementor or null if none is
  229. * found.
  230. *
  231. * @param w
  232. * The widget to start from. This is returned if it implements
  233. * SubPartAware.
  234. * @return The first widget (upwards in hierarchy) that implements
  235. * SubPartAware or null
  236. */
  237. private Widget findSubPartAwareParentWidget(Widget w) {
  238. while (w != null) {
  239. if (w instanceof SubPartAware) {
  240. return w;
  241. }
  242. w = w.getParent();
  243. }
  244. return null;
  245. }
  246. /**
  247. * Returns the first widget found when going from {@code targetElement}
  248. * upwards in the DOM hierarchy, assuming that {@code ancestorWidget} is a
  249. * parent of {@code targetElement}.
  250. *
  251. * @param targetElement
  252. * @param ancestorWidget
  253. * @return The widget whose root element is a parent of
  254. * {@code targetElement}.
  255. */
  256. private Widget findParentWidget(Element targetElement, Widget ancestorWidget) {
  257. /*
  258. * As we cannot resolve Widgets from the element we start from the
  259. * widget and move downwards to the correct child widget, as long as we
  260. * find one.
  261. */
  262. if (ancestorWidget instanceof HasWidgets) {
  263. for (Widget w : ((HasWidgets) ancestorWidget)) {
  264. if (w.getElement().isOrHasChild(targetElement)) {
  265. return findParentWidget(targetElement, w);
  266. }
  267. }
  268. }
  269. // No children found, this is it
  270. return ancestorWidget;
  271. }
  272. /**
  273. * Locates an element based on a DOM path and a base element.
  274. *
  275. * @param baseElement
  276. * The base element which the path is relative to
  277. * @param path
  278. * String locator (consisting of domChild[x] parts) that
  279. * identifies the element
  280. * @return The element identified by path, relative to baseElement or null
  281. * if the element could not be found.
  282. */
  283. private Element getElementByDOMPath(Element baseElement, String path) {
  284. String parts[] = path.split(PARENTCHILD_SEPARATOR);
  285. Element element = baseElement;
  286. for (String part : parts) {
  287. if (part.startsWith("domChild[")) {
  288. String childIndexString = part.substring("domChild[".length(),
  289. part.length() - 1);
  290. if (Util.findWidget(baseElement, null) instanceof VAbstractOrderedLayout) {
  291. if (element.hasChildNodes()) {
  292. Element e = element.getFirstChildElement().cast();
  293. String cn = e.getClassName();
  294. if (cn != null
  295. && (cn.equals("v-expand") || cn
  296. .contains("v-has-caption"))) {
  297. element = e;
  298. }
  299. }
  300. }
  301. try {
  302. int childIndex = Integer.parseInt(childIndexString);
  303. element = DOM.getChild(element, childIndex);
  304. } catch (Exception e) {
  305. return null;
  306. }
  307. if (element == null) {
  308. return null;
  309. }
  310. }
  311. }
  312. return element;
  313. }
  314. /**
  315. * Generates a String locator using domChild[x] parts for the element
  316. * relative to the baseElement.
  317. *
  318. * @param element
  319. * The target element
  320. * @param baseElement
  321. * The starting point for the locator. The generated path is
  322. * relative to this element.
  323. * @return A String locator that can be used to locate the target element
  324. * using {@link #getElementByDOMPath(Element, String)} or null if
  325. * the locator String cannot be created.
  326. */
  327. private String getDOMPathForElement(Element element, Element baseElement) {
  328. Element e = element;
  329. String path = "";
  330. while (true) {
  331. int childIndex = -1;
  332. Element siblingIterator = e;
  333. while (siblingIterator != null) {
  334. childIndex++;
  335. siblingIterator = siblingIterator.getPreviousSiblingElement()
  336. .cast();
  337. }
  338. path = PARENTCHILD_SEPARATOR + "domChild[" + childIndex + "]"
  339. + path;
  340. JavaScriptObject parent = e.getParentElement();
  341. if (parent == null) {
  342. return null;
  343. }
  344. // The parent check is a work around for Firefox 15 which fails to
  345. // compare elements properly (#9534)
  346. if (parent == baseElement) {
  347. break;
  348. }
  349. e = parent.cast();
  350. }
  351. return path;
  352. }
  353. /**
  354. * Locates an element using a String locator (path) which identifies a DOM
  355. * element. The {@link #getPathForElement(Element)} method can be used for
  356. * the inverse operation, i.e. generating a string expression for a DOM
  357. * element.
  358. *
  359. * @since 5.4
  360. * @param path
  361. * The String locater which identifies the target element.
  362. * @return The DOM element identified by {@code path} or null if the element
  363. * could not be located.
  364. */
  365. public Element getElementByPath(String path) {
  366. /*
  367. * Path is of type "targetWidgetPath#componentPart" or
  368. * "targetWidgetPath".
  369. */
  370. String parts[] = path.split(SUBPART_SEPARATOR, 2);
  371. String widgetPath = parts[0];
  372. Widget w = getWidgetFromPath(widgetPath);
  373. if (w == null || !Util.isAttachedAndDisplayed(w)) {
  374. return null;
  375. }
  376. if (parts.length == 1) {
  377. int pos = widgetPath.indexOf("domChild");
  378. if (pos == -1) {
  379. return w.getElement();
  380. }
  381. // Contains dom reference to a sub element of the widget
  382. String subPath = widgetPath.substring(pos);
  383. return getElementByDOMPath(w.getElement(), subPath);
  384. } else if (parts.length == 2) {
  385. if (w instanceof SubPartAware) {
  386. return ((SubPartAware) w).getSubPartElement(parts[1]);
  387. }
  388. }
  389. return null;
  390. }
  391. /**
  392. * Creates a locator String for the given widget. The path can be used to
  393. * locate the widget using {@link #getWidgetFromPath(String)}.
  394. *
  395. * Returns null if no path can be determined for the widget or if the widget
  396. * is null.
  397. *
  398. * @param w
  399. * The target widget
  400. * @return A String locator for the widget
  401. */
  402. private String getPathForWidget(Widget w) {
  403. if (w == null) {
  404. return null;
  405. }
  406. String elementId = w.getElement().getId();
  407. if (elementId != null && !elementId.isEmpty()
  408. && !elementId.startsWith("gwt-uid-")) {
  409. // Use PID_S+id if the user has set an id but do not use it for auto
  410. // generated id:s as these might not be consistent
  411. return "PID_S" + elementId;
  412. } else if (w instanceof VUI) {
  413. return "";
  414. } else if (w instanceof VWindow) {
  415. Connector windowConnector = ConnectorMap.get(client)
  416. .getConnector(w);
  417. List<WindowConnector> subWindowList = client.getUIConnector()
  418. .getSubWindows();
  419. int indexOfSubWindow = subWindowList.indexOf(windowConnector);
  420. return PARENTCHILD_SEPARATOR + "VWindow[" + indexOfSubWindow + "]";
  421. } else if (w instanceof RootPanel) {
  422. return ROOT_ID;
  423. }
  424. Widget parent = w.getParent();
  425. String basePath = getPathForWidget(parent);
  426. if (basePath == null) {
  427. return null;
  428. }
  429. String simpleName = Util.getSimpleName(w);
  430. /*
  431. * Check if the parent implements Iterable. At least VPopupView does not
  432. * implement HasWdgets so we cannot check for that.
  433. */
  434. if (!(parent instanceof Iterable<?>)) {
  435. // Parent does not implement Iterable so we cannot find out which
  436. // child this is
  437. return null;
  438. }
  439. Iterator<?> i = ((Iterable<?>) parent).iterator();
  440. int pos = 0;
  441. while (i.hasNext()) {
  442. Object child = i.next();
  443. if (child == w) {
  444. return basePath + PARENTCHILD_SEPARATOR + simpleName + "["
  445. + pos + "]";
  446. }
  447. String simpleName2 = Util.getSimpleName(child);
  448. if (simpleName.equals(simpleName2)) {
  449. pos++;
  450. }
  451. }
  452. return null;
  453. }
  454. /**
  455. * Locates the widget based on a String locator.
  456. *
  457. * @param path
  458. * The String locator that identifies the widget.
  459. * @return The Widget identified by the String locator or null if the widget
  460. * could not be identified.
  461. */
  462. private Widget getWidgetFromPath(String path) {
  463. Widget w = null;
  464. String parts[] = path.split(PARENTCHILD_SEPARATOR);
  465. for (int i = 0; i < parts.length; i++) {
  466. String part = parts[i];
  467. if (part.equals(ROOT_ID)) {
  468. w = RootPanel.get();
  469. } else if (part.equals("")) {
  470. w = client.getUIConnector().getWidget();
  471. } else if (w == null) {
  472. String id = part;
  473. // Must be old static pid (PID_S*)
  474. ServerConnector connector = ConnectorMap.get(client)
  475. .getConnector(id);
  476. if (connector == null) {
  477. // Lookup by component id
  478. // TODO Optimize this
  479. connector = findConnectorById(client.getUIConnector(),
  480. id.substring(5));
  481. }
  482. if (connector instanceof ComponentConnector) {
  483. w = ((ComponentConnector) connector).getWidget();
  484. } else {
  485. // Not found
  486. return null;
  487. }
  488. } else if (part.startsWith("domChild[")) {
  489. // The target widget has been found and the rest identifies the
  490. // element
  491. break;
  492. } else if (w instanceof Iterable) {
  493. // W identifies a widget that contains other widgets, as it
  494. // should. Try to locate the child
  495. Iterable<?> parent = (Iterable<?>) w;
  496. // Part is of type "VVerticalLayout[0]", split this into
  497. // VVerticalLayout and 0
  498. String[] split = part.split("\\[", 2);
  499. String widgetClassName = split[0];
  500. String indexString = split[1].substring(0,
  501. split[1].length() - 1);
  502. int widgetPosition = Integer.parseInt(indexString);
  503. // AbsolutePanel in GridLayout has been removed -> skip it
  504. if (w instanceof VGridLayout
  505. && "AbsolutePanel".equals(widgetClassName)) {
  506. continue;
  507. }
  508. // FlowPane in CSSLayout has been removed -> skip it
  509. if (w instanceof VCssLayout
  510. && "VCssLayout$FlowPane".equals(widgetClassName)) {
  511. continue;
  512. }
  513. // ChildComponentContainer and VOrderedLayout$Slot have been
  514. // replaced with Slot
  515. if (w instanceof VAbstractOrderedLayout
  516. && ("ChildComponentContainer".equals(widgetClassName) || "VOrderedLayout$Slot"
  517. .equals(widgetClassName))) {
  518. widgetClassName = "Slot";
  519. }
  520. if (w instanceof VTabsheetPanel && widgetPosition != 0) {
  521. // TabSheetPanel now only contains 1 connector => the index
  522. // is always 0 which indicates the widget in the active tab
  523. widgetPosition = 0;
  524. }
  525. if (w instanceof VOverlay
  526. && "VCalendarPanel".equals(widgetClassName)) {
  527. // Vaadin 7.1 adds a wrapper for datefield popups
  528. parent = (Iterable<?>) ((Iterable) parent).iterator()
  529. .next();
  530. }
  531. /*
  532. * The new grid and ordered layotus do not contain
  533. * ChildComponentContainer widgets. This is instead simulated by
  534. * constructing a path step that would find the desired widget
  535. * from the layout and injecting it as the next search step
  536. * (which would originally have found the widget inside the
  537. * ChildComponentContainer)
  538. */
  539. if ((w instanceof VGridLayout)
  540. && "ChildComponentContainer".equals(widgetClassName)
  541. && i + 1 < parts.length) {
  542. HasWidgets layout = (HasWidgets) w;
  543. String nextPart = parts[i + 1];
  544. String[] nextSplit = nextPart.split("\\[", 2);
  545. String nextWidgetClassName = nextSplit[0];
  546. // Find the n:th child and count the number of children with
  547. // the same type before it
  548. int nextIndex = 0;
  549. for (Widget child : layout) {
  550. boolean matchingType = nextWidgetClassName.equals(Util
  551. .getSimpleName(child));
  552. if (matchingType && widgetPosition == 0) {
  553. // This is the n:th child that we looked for
  554. break;
  555. } else if (widgetPosition < 0) {
  556. // Error if we're past the desired position without
  557. // a match
  558. return null;
  559. } else if (matchingType) {
  560. // If this was another child of the expected type,
  561. // increase the count for the next step
  562. nextIndex++;
  563. }
  564. // Don't count captions
  565. if (!(child instanceof VCaption)) {
  566. widgetPosition--;
  567. }
  568. }
  569. // Advance to the next step, this time checking for the
  570. // actual child widget
  571. parts[i + 1] = nextWidgetClassName + '[' + nextIndex + ']';
  572. continue;
  573. }
  574. // Locate the child
  575. Iterator<? extends Widget> iterator;
  576. /*
  577. * VWindow and VContextMenu workarounds for backwards
  578. * compatibility
  579. */
  580. if (widgetClassName.equals("VWindow")) {
  581. List<WindowConnector> windows = client.getUIConnector()
  582. .getSubWindows();
  583. List<VWindow> windowWidgets = new ArrayList<VWindow>(
  584. windows.size());
  585. for (WindowConnector wc : windows) {
  586. windowWidgets.add(wc.getWidget());
  587. }
  588. iterator = windowWidgets.iterator();
  589. } else if (widgetClassName.equals("VContextMenu")) {
  590. return client.getContextMenu();
  591. } else {
  592. iterator = (Iterator<? extends Widget>) parent.iterator();
  593. }
  594. boolean ok = false;
  595. // Find the widgetPosition:th child of type "widgetClassName"
  596. while (iterator.hasNext()) {
  597. Widget child = iterator.next();
  598. String simpleName2 = Util.getSimpleName(child);
  599. if (!widgetClassName.equals(simpleName2)
  600. && child instanceof Slot) {
  601. /*
  602. * Support legacy tests without any selector for the
  603. * Slot widget (i.e. /VVerticalLayout[0]/VButton[0]) by
  604. * directly checking the stuff inside the slot
  605. */
  606. child = ((Slot) child).getWidget();
  607. simpleName2 = Util.getSimpleName(child);
  608. }
  609. if (widgetClassName.equals(simpleName2)) {
  610. if (widgetPosition == 0) {
  611. w = child;
  612. ok = true;
  613. break;
  614. }
  615. widgetPosition--;
  616. }
  617. }
  618. if (!ok) {
  619. // Did not find the child
  620. return null;
  621. }
  622. } else {
  623. // W identifies something that is not a "HasWidgets". This
  624. // should not happen as all widget containers should implement
  625. // HasWidgets.
  626. return null;
  627. }
  628. }
  629. return w;
  630. }
  631. private ServerConnector findConnectorById(ServerConnector root, String id) {
  632. SharedState state = root.getState();
  633. if (state instanceof AbstractComponentState
  634. && id.equals(((AbstractComponentState) state).id)) {
  635. return root;
  636. }
  637. for (ServerConnector child : root.getChildren()) {
  638. ServerConnector found = findConnectorById(child, id);
  639. if (found != null) {
  640. return found;
  641. }
  642. }
  643. return null;
  644. }
  645. }