public Class<? extends ServerConnector> getConnectorClassByEncodedTag(int tag) {
   Class<? extends ServerConnector> type = classes.get(tag);
   if (type == null && !classes.containsKey(tag)) {
     // Initialize if not already loaded
     Integer currentTag = Integer.valueOf(tag);
     while (type == null && currentTag != null) {
       String serverSideClassNameForTag = getServerSideClassNameForTag(currentTag);
       if (TypeData.hasIdentifier(serverSideClassNameForTag)) {
         try {
           type = (Class<? extends ServerConnector>) TypeData.getClass(serverSideClassNameForTag);
         } catch (NoDataException e) {
           throw new RuntimeException(e);
         }
       }
       currentTag = getParentTag(currentTag.intValue());
     }
     if (type == null) {
       type = UnknownComponentConnector.class;
       if (unknownComponents == null) {
         unknownComponents = new HashMap<Integer, String>();
       }
       unknownComponents.put(tag, getServerSideClassNameForTag(tag));
     }
     classes.put(tag, type);
   }
   return type;
 }
示例#2
0
 public static <T extends ServerRpc> T create(Class<T> rpcInterface, ServerConnector connector) {
   try {
     return (T)
         TypeData.getType(rpcInterface)
             .createProxy(new RpcInvokationHandler(rpcInterface, connector));
   } catch (NoDataException e) {
     throw new IllegalStateException(
         "There is no information about "
             + rpcInterface
             + ". Did you forget to compile the widgetset?");
   }
 }
示例#3
0
  /**
   * Create an uninitialized connector that best matches given UIDL. The connector must implement
   * {@link ServerConnector}.
   *
   * @param tag connector type tag for the connector to create
   * @param conf the application configuration to use when creating the connector
   * @return New uninitialized and unregistered connector that can paint given UIDL.
   */
  public ServerConnector createConnector(int tag, ApplicationConfiguration conf) {
    /*
     * Yes, this (including the generated code in WidgetMap) may look very
     * odd code, but due the nature of GWT, we cannot do this any cleaner.
     * Luckily this is mostly written by WidgetSetGenerator, here are just
     * some hacks. Extra instantiation code is needed if client side
     * connector has no "native" counterpart on client side.
     */
    Profiler.enter("WidgetSet.createConnector");

    Class<? extends ServerConnector> classType = resolveInheritedConnectorType(conf, tag);

    try {
      if (classType == null
          || classType == UnknownComponentConnector.class
          || classType == UnknownExtensionConnector.class) {
        String serverSideName = conf.getUnknownServerClassNameByTag(tag);
        if (classType == UnknownExtensionConnector.class) {
          // Display message in the console for non-visual connectors
          getLogger().severe(UnknownComponentConnector.createMessage(serverSideName));
          return GWT.create(UnknownExtensionConnector.class);
        } else {
          UnknownComponentConnector c = GWT.create(UnknownComponentConnector.class);
          // Set message to be shown in a widget for visual connectors
          c.setServerSideClassName(serverSideName);
          return c;
        }
      } else {
        /*
         * let the auto generated code instantiate this type
         */
        ServerConnector connector = (ServerConnector) TypeData.getType(classType).createInstance();
        if (connector instanceof HasJavaScriptConnectorHelper) {
          ((HasJavaScriptConnectorHelper) connector).getJavascriptConnectorHelper().setTag(tag);
        }
        return connector;
      }
    } catch (NoDataException e) {
      throw new IllegalStateException(
          "There is no information about "
              + classType
              + ". Did you remember to compile the right widgetset?",
          e);
    } finally {
      Profiler.leave("WidgetSet.createConnector");
    }
  }