選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

Type.java 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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.client.metadata;
  17. import java.util.Collection;
  18. import com.google.gwt.core.client.JsArrayString;
  19. import com.vaadin.client.JsArrayObject;
  20. import com.vaadin.client.ServerConnector;
  21. import com.vaadin.client.communication.JSONSerializer;
  22. public class Type {
  23. private final String name;
  24. private final Type[] parameterTypes;
  25. private final String signature;
  26. public Type(Class<?> clazz) {
  27. this(clazz.getName(), null);
  28. }
  29. public Type(String baseTypeName, Type[] parameterTypes) {
  30. name = baseTypeName;
  31. this.parameterTypes = parameterTypes;
  32. // Cache derived signature value
  33. signature = calculateSignature(name, parameterTypes);
  34. }
  35. public String getBaseTypeName() {
  36. return name;
  37. }
  38. public Type[] getParameterTypes() {
  39. return parameterTypes;
  40. }
  41. public Object createInstance() throws NoDataException {
  42. Invoker invoker = TypeDataStore.getConstructor(this);
  43. Object ret = invoker.invoke(null);
  44. if (ret instanceof ServerConnector) {
  45. ConnectorBundleLoader.get().cval(name);
  46. }
  47. return ret;
  48. }
  49. public Method getMethod(String name) {
  50. return new Method(this, name);
  51. }
  52. /**
  53. * @return
  54. * @throws NoDataException
  55. *
  56. * @deprecated As of 7.0.1, use {@link #getPropertiesAsArray()} instead for
  57. * improved performance
  58. */
  59. @Deprecated
  60. public Collection<Property> getProperties() throws NoDataException {
  61. return TypeDataStore.getProperties(this);
  62. }
  63. public JsArrayObject<Property> getPropertiesAsArray()
  64. throws NoDataException {
  65. return TypeDataStore.getPropertiesAsArray(this);
  66. }
  67. public Property getProperty(String propertyName) {
  68. return new Property(this, propertyName);
  69. }
  70. private static String calculateSignature(String name,
  71. Type[] parameterTypes) {
  72. String string = name;
  73. if (parameterTypes != null && parameterTypes.length != 0) {
  74. string += '<';
  75. for (int i = 0; i < parameterTypes.length; i++) {
  76. if (i != 0) {
  77. string += ',';
  78. }
  79. string += parameterTypes[i];
  80. }
  81. string += '>';
  82. }
  83. return string;
  84. }
  85. /**
  86. * The unique signature used to identify this type. The structure of the
  87. * returned string may change without notice and should not be used for any
  88. * other purpose than identification. The signature is currently based on
  89. * the fully qualified name of the type.
  90. *
  91. * @return the unique signature of this type
  92. */
  93. public String getSignature() {
  94. return signature;
  95. }
  96. @Override
  97. public String toString() {
  98. return getSignature();
  99. }
  100. @Override
  101. public boolean equals(Object obj) {
  102. if (obj == this) {
  103. return true;
  104. } else if (obj instanceof Type) {
  105. Type other = (Type) obj;
  106. return other.getSignature().equals(getSignature());
  107. } else {
  108. return false;
  109. }
  110. }
  111. @Override
  112. public int hashCode() {
  113. return getSignature().hashCode();
  114. }
  115. public Object createProxy(InvokationHandler invokationHandler)
  116. throws NoDataException {
  117. return TypeDataStore.getProxyHandler(this)
  118. .createProxy(invokationHandler);
  119. }
  120. public JSONSerializer<?> findSerializer() {
  121. return TypeDataStore.findSerializer(this);
  122. }
  123. public boolean hasProperties() {
  124. return TypeDataStore.hasProperties(this);
  125. }
  126. public JsArrayString getDelegateToWidgetProperties() {
  127. return TypeDataStore.getDelegateToWidgetProperites(this);
  128. }
  129. }