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.

ConnectorHelper.java 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. * Copyright 2000-2018 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.util;
  17. import java.util.LinkedList;
  18. import com.vaadin.server.ClientConnector;
  19. import com.vaadin.ui.Component;
  20. /**
  21. * Provides various helper methods for connectors. Meant for internal use.
  22. *
  23. * @since 7.1
  24. * @author Vaadin Ltd
  25. */
  26. public class ConnectorHelper {
  27. /**
  28. * Creates a string containing debug info for the connector.
  29. *
  30. * @since 7.1
  31. * @param connector
  32. * The connector to print debug info about
  33. * @return A string with debug information
  34. */
  35. public static String getDebugInformation(ClientConnector connector) {
  36. StringBuilder sb = new StringBuilder();
  37. sb.append("*** Debug details of a connector: *** \n");
  38. sb.append("Type: ");
  39. sb.append(connector.getClass().getName());
  40. sb.append("\nId:");
  41. sb.append(connector.getConnectorId());
  42. if (connector instanceof Component) {
  43. Component component = (Component) connector;
  44. if (component.getCaption() != null) {
  45. sb.append("\nCaption:");
  46. sb.append(component.getCaption());
  47. }
  48. }
  49. writeHierarchyInformation(connector, sb);
  50. return sb.toString();
  51. }
  52. /**
  53. * Creates a string containing hierarchy information for the connector.
  54. *
  55. * @since 7.1
  56. * @param connector
  57. * The connector to get hierarchy information for
  58. * @param builder
  59. * The StringBuilder where the information should be written
  60. */
  61. public static void writeHierarchyInformation(ClientConnector connector,
  62. StringBuilder builder) {
  63. LinkedList<ClientConnector> h = new LinkedList<>();
  64. h.add(connector);
  65. ClientConnector parent = connector.getParent();
  66. while (parent != null) {
  67. h.addFirst(parent);
  68. parent = parent.getParent();
  69. }
  70. builder.append("\nConnector hierarchy:\n");
  71. int l = 0;
  72. for (ClientConnector connector2 : h) {
  73. if (l != 0) {
  74. builder.append("\n");
  75. for (int i = 0; i < l; i++) {
  76. builder.append(" ");
  77. }
  78. }
  79. l++;
  80. Class<? extends ClientConnector> connectorClass = connector2
  81. .getClass();
  82. Class<?> topClass = connectorClass;
  83. while (topClass.getEnclosingClass() != null) {
  84. topClass = topClass.getEnclosingClass();
  85. }
  86. builder.append(connectorClass.getName());
  87. builder.append('(');
  88. builder.append(topClass.getSimpleName());
  89. builder.append(".java:1)");
  90. }
  91. }
  92. private ConnectorHelper() {
  93. }
  94. }