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.

TypeDataStore.java 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /*
  2. @VaadinApache2LicenseForJavaFiles@
  3. */
  4. package com.vaadin.terminal.gwt.client.metadata;
  5. import java.util.HashMap;
  6. import java.util.HashSet;
  7. import java.util.Map;
  8. import java.util.Set;
  9. public class TypeDataStore {
  10. private static final String CONSTRUCTOR_NAME = "!new";
  11. private final Map<String, Class<?>> identifiers = new HashMap<String, Class<?>>();
  12. private final Map<Type, ProxyHandler> proxyHandlers = new HashMap<Type, ProxyHandler>();
  13. private final Set<Method> delayedMethods = new HashSet<Method>();
  14. private final Set<Method> lastonlyMethods = new HashSet<Method>();
  15. private final Map<Method, Type> returnTypes = new HashMap<Method, Type>();
  16. private final Map<Method, Invoker> invokers = new HashMap<Method, Invoker>();
  17. private final Map<Method, Type[]> paramTypes = new HashMap<Method, Type[]>();
  18. private final Map<Property, Invoker> getters = new HashMap<Property, Invoker>();
  19. private final Map<Property, String> delegateToWidget = new HashMap<Property, String>();
  20. public static TypeDataStore get() {
  21. return ConnectorBundleLoader.get().getTypeDataStore();
  22. }
  23. public void setClass(String identifier, Class<?> type) {
  24. identifiers.put(identifier, type);
  25. }
  26. public static Class<?> getClass(String identifier) throws NoDataException {
  27. Class<?> class1 = get().identifiers.get(identifier);
  28. if (class1 == null) {
  29. throw new NoDataException("There is not class for identifier "
  30. + identifier);
  31. }
  32. return class1;
  33. }
  34. public static Type getType(Class<?> clazz) {
  35. return new Type(clazz);
  36. }
  37. public static Type getReturnType(Method method) throws NoDataException {
  38. Type type = get().returnTypes.get(method);
  39. if (type == null) {
  40. throw new NoDataException("There is return type for "
  41. + method.getSignature());
  42. }
  43. return type;
  44. }
  45. public static Invoker getInvoker(Method method) throws NoDataException {
  46. Invoker invoker = get().invokers.get(method);
  47. if (invoker == null) {
  48. throw new NoDataException("There is invoker for "
  49. + method.getSignature());
  50. }
  51. return invoker;
  52. }
  53. public static Invoker getConstructor(Type type) throws NoDataException {
  54. Invoker invoker = get().invokers
  55. .get(new Method(type, CONSTRUCTOR_NAME));
  56. if (invoker == null) {
  57. throw new NoDataException("There is constructor for "
  58. + type.getSignature());
  59. }
  60. return invoker;
  61. }
  62. public static Invoker getGetter(Property property) throws NoDataException {
  63. Invoker getter = get().getters.get(property);
  64. if (getter == null) {
  65. throw new NoDataException("There is getter for "
  66. + property.getSignature());
  67. }
  68. return getter;
  69. }
  70. public static String getDelegateToWidget(Property property) {
  71. return get().delegateToWidget.get(property);
  72. }
  73. public void setReturnType(Class<?> type, String methodName, Type returnType) {
  74. returnTypes.put(new Method(getType(type), methodName), returnType);
  75. }
  76. public void setConstructor(Class<?> type, Invoker constructor) {
  77. setInvoker(type, CONSTRUCTOR_NAME, constructor);
  78. }
  79. public void setInvoker(Class<?> type, String methodName, Invoker invoker) {
  80. invokers.put(new Method(getType(type), methodName), invoker);
  81. }
  82. public static Type[] getParamTypes(Method method) throws NoDataException {
  83. Type[] types = get().paramTypes.get(method);
  84. if (types == null) {
  85. throw new NoDataException("There are no parameter type data for "
  86. + method.getSignature());
  87. }
  88. return types;
  89. }
  90. public void setParamTypes(Class<?> type, String methodName,
  91. Type[] paramTypes) {
  92. this.paramTypes.put(new Method(getType(type), methodName), paramTypes);
  93. }
  94. public static boolean hasIdentifier(String identifier) {
  95. return get().identifiers.containsKey(identifier);
  96. }
  97. public static ProxyHandler getProxyHandler(Type type)
  98. throws NoDataException {
  99. ProxyHandler proxyHandler = get().proxyHandlers.get(type);
  100. if (proxyHandler == null) {
  101. throw new NoDataException("No proxy handler for "
  102. + type.getSignature());
  103. }
  104. return proxyHandler;
  105. }
  106. public void setProxyHandler(Class<?> type, ProxyHandler proxyHandler) {
  107. proxyHandlers.put(getType(type), proxyHandler);
  108. }
  109. public static boolean isDelayed(Method method) {
  110. return get().delayedMethods.contains(method);
  111. }
  112. public void setDelayed(Class<?> type, String methodName) {
  113. delayedMethods.add(getType(type).getMethod(methodName));
  114. }
  115. public static boolean isLastonly(Method method) {
  116. return get().lastonlyMethods.contains(method);
  117. }
  118. public void setLastonly(Class<?> clazz, String methodName) {
  119. lastonlyMethods.add(getType(clazz).getMethod(methodName));
  120. }
  121. }