예제 #1
0
 @SuppressWarnings("deprecation")
 private static String getScopeName(org.cruxframework.crux.core.client.ioc.Inject.Scope scope) {
   switch (scope) {
     case DOCUMENT:
       return Scope.SINGLETON.name();
     case DEFAULT:
       return Scope.LOCAL.name();
     default:
       return scope.name();
   }
 }
예제 #2
0
  /**
   * @param srcWriter
   * @param className
   */
  private void generateContainerInstatiationMethod(SourcePrinter srcWriter, String className) {
    try {
      srcWriter.println(
          "public  "
              + className
              + " get"
              + className.replace('.', '_')
              + "("
              + Scope.class.getCanonicalName()
              + " scope, String subscope){");
      JClassType type =
          JClassUtils.getType(context.getGeneratorContext().getTypeOracle(), className);

      IocConfigImpl<?> iocConfig = (IocConfigImpl<?>) configurations.get(className);
      Class<?> providerClass = iocConfig.getProviderClass();
      if (providerClass != null) {
        srcWriter.println(
            className
                + " result = _getScope(scope).getValue(GWT.create("
                + providerClass.getCanonicalName()
                + ".class), "
                + EscapeUtils.quote(className)
                + ", subscope, ");
        generateFieldsPopulationCallback(srcWriter, type);
        srcWriter.println(");");
      } else if (iocConfig.getToClass() != null) {
        srcWriter.println(
            className
                + " result = _getScope(scope).getValue(new "
                + IocProvider.class.getCanonicalName()
                + "<"
                + className
                + ">(){");
        srcWriter.println("public " + className + " get(){");
        srcWriter.println(
            "return GWT.create(" + iocConfig.getToClass().getCanonicalName() + ".class);");
        srcWriter.println("}");
        srcWriter.println("}, " + EscapeUtils.quote(className) + ", subscope, ");
        generateFieldsPopulationCallback(srcWriter, type);
        srcWriter.println(");");
      } else {
        srcWriter.println(
            className
                + " result = _getScope(scope).getValue(new "
                + IocProvider.class.getCanonicalName()
                + "<"
                + className
                + ">(){");
        srcWriter.println("public " + className + " get(){");
        String instantiationClass = getInstantiationClass(className);
        JClassType instantiationType =
            context.getGeneratorContext().getTypeOracle().findType(instantiationClass);
        if (instantiationType == null) {
          throw new CruxGeneratorException("Can not found type: " + instantiationClass);
        }
        if (instantiationType.isAssignableTo(remoteServiceType)
            && ConfigurationFactory.getConfigurations()
                .sendCruxViewNameOnClientRequests()
                .equals("true")) {
          srcWriter.println(className + " ret = GWT.create(" + instantiationClass + ".class);");
          srcWriter.println(
              "(("
                  + ServiceDefTarget.class.getCanonicalName()
                  + ")ret).setRpcRequestBuilder(new "
                  + CruxRpcRequestBuilder.class.getCanonicalName()
                  + "(getBoundCruxViewId()));");
          srcWriter.println("return ret;");
        } else {
          srcWriter.println("return GWT.create(" + instantiationClass + ".class);");
        }
        srcWriter.println("}");
        srcWriter.println("}, " + EscapeUtils.quote(className) + ", subscope, ");
        generateFieldsPopulationCallback(srcWriter, type);
        srcWriter.println(");");
      }

      if (type.isAssignableTo(viewBindableType)) {
        srcWriter.println(
            "if (scope != "
                + Scope.class.getCanonicalName()
                + "."
                + Scope.SINGLETON.name()
                + " && result.getBoundCruxViewId() == null){");
        srcWriter.println("result.bindCruxView(this.getBoundCruxViewId());");
        srcWriter.println("}");
      }
      srcWriter.println("return result;");
      srcWriter.println("}");
    } catch (NotFoundException e) {
      throw new IoCException("IoC Error Class [" + className + "] not found.", e);
    }
  }