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.

Type.java 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. @VaadinApache2LicenseForJavaFiles@
  3. */
  4. package com.vaadin.client.metadata;
  5. import java.util.Collection;
  6. import com.vaadin.client.communication.JSONSerializer;
  7. public class Type {
  8. private final String name;
  9. private final Type[] parameterTypes;
  10. public Type(Class<?> clazz) {
  11. name = clazz.getName();
  12. parameterTypes = null;
  13. }
  14. public Type(String baseTypeName, Type[] parameterTypes) {
  15. name = baseTypeName;
  16. this.parameterTypes = parameterTypes;
  17. }
  18. public String getBaseTypeName() {
  19. return name;
  20. }
  21. public Type[] getParameterTypes() {
  22. return parameterTypes;
  23. }
  24. public Object createInstance() throws NoDataException {
  25. Invoker invoker = TypeDataStore.getConstructor(this);
  26. return invoker.invoke(null);
  27. }
  28. public Method getMethod(String name) {
  29. return new Method(this, name);
  30. }
  31. public Collection<Property> getProperties() throws NoDataException {
  32. return TypeDataStore.getProperties(this);
  33. }
  34. public Property getProperty(String propertyName) {
  35. return new Property(this, propertyName);
  36. }
  37. public String getSignature() {
  38. String string = name;
  39. if (parameterTypes != null && parameterTypes.length != 0) {
  40. string += '<';
  41. for (int i = 0; i < parameterTypes.length; i++) {
  42. if (i != 0) {
  43. string += ',';
  44. }
  45. string += parameterTypes[i].toString();
  46. }
  47. string += '>';
  48. }
  49. return string;
  50. }
  51. @Override
  52. public String toString() {
  53. return getSignature();
  54. }
  55. @Override
  56. public boolean equals(Object obj) {
  57. if (obj == this) {
  58. return true;
  59. } else if (obj instanceof Type) {
  60. Type other = (Type) obj;
  61. return other.getSignature().equals(getSignature());
  62. } else {
  63. return false;
  64. }
  65. }
  66. @Override
  67. public int hashCode() {
  68. return getSignature().hashCode();
  69. }
  70. public Object createProxy(InvokationHandler invokationHandler)
  71. throws NoDataException {
  72. return TypeDataStore.get().getProxyHandler(this)
  73. .createProxy(invokationHandler);
  74. }
  75. public JSONSerializer<?> findSerializer() {
  76. return TypeDataStore.findSerializer(this);
  77. }
  78. public boolean hasProperties() {
  79. return TypeDataStore.hasProperties(this);
  80. }
  81. }