Package org.cruxframework.crux.core.rebind

Examples of org.cruxframework.crux.core.rebind.CruxGeneratorException


          sourceWriter.println(parentVariable+"."+setterMethodName+"("+valueVariable+");");
        }
      }
      catch (Exception e)
      {
        throw new CruxGeneratorException("Property ["+field.getName()+"] could not be created. This is not visible neither has a getter/setter method.");
      }
    }
  }
View Full Code Here


    if (field.isPublic() || (allowProtected && field.isProtected()))
    {
      return parentVariable+"."+field.getName();
    }

    throw new CruxGeneratorException("Property ["+propertyName+"] could not be created. It is not visible neither has a getter/setter method.");
  }
View Full Code Here

        {
          Class<?> dataClass = Class.forName(cellClass);
          CustomCell annot = dataClass.getAnnotation(CustomCell.class);
          if (customCells.containsKey(annot.value()))
          {
            throw new CruxGeneratorException("Duplicated CustomCell found: ["+annot.value()+"].");
          }
         
          customCells.put(annot.value(), dataClass.getCanonicalName());
        }
        catch (ClassNotFoundException e)
View Full Code Here

        for (Class<?> restException : restExceptionTypes)
        {
          JClassType exceptionType = context.getTypeOracle().findType(restException.getCanonicalName());
          if (exceptionType == null)
          {
            throw new CruxGeneratorException("Exception type ["+restException.getCanonicalName()+"] can not be used on client code. Add this exeption to a GWT client package.");
          }
          if (!first)
          {
            srcWriter.print("else ");
          }
          first = false;
          srcWriter.println("if (StringUtils.unsafeEquals(hash,"+EscapeUtils.quote(EncryptUtils.hash(exceptionType.getParameterizedQualifiedSourceName()))+")){");
          String serializerName = new JSonSerializerProxyCreator(context, logger, exceptionType).create();
          srcWriter.println("Exception ex = new "+serializerName+"().decode(jsonObject.get(\"exData\"));");
          srcWriter.println(callbackParameterName+".onError(ex);");
          srcWriter.println("}");
        }
        srcWriter.println("else {");
        srcWriter.println(callbackParameterName+".onError(new RestError("+responseVariable+".getStatusCode(), jsonObject.get(\"exData\").toString()));");
        srcWriter.println("}");

        srcWriter.println("}");
      }
      else
      {
        srcWriter.println(callbackParameterName+".onError(new RestError("+responseVariable+".getStatusCode(), (jsonObject.get(\"message\") != null && jsonObject.get(\"message\").isString() != null) ? jsonObject.get(\"message\").isString().stringValue() : \"\"));");
      }
    }
    catch (Exception e)
    {
      throw new CruxGeneratorException("Error generatirng exception handlers for type ["+baseIntf.getParameterizedQualifiedSourceName()+"].", e);
    }
  }
View Full Code Here

  private Class<?> getRestImplementationClass(JClassType baseIntf)
  {
    TargetRestService restService = baseIntf.getAnnotation(TargetRestService.class);
    if (restService == null)
    {
      throw new CruxGeneratorException("Can not create the rest proxy. Use @RestProxy.TargetRestService annotation to inform the target of current proxy.");
    }
    String serviceName = restService.value();
    try
    {
      return RestServiceFactoryInitializer.getServiceFactory().getServiceClass(serviceName);
    }
    catch (Exception e)
    {
      throw new CruxGeneratorException("Can not create the rest proxy. Can not found the implementationClass for service name ["+serviceName+"].");
    }
  }
View Full Code Here

  private void validateImplementationMethod(JMethod method, Method implementationMethod)
  {
    if (implementationMethod == null)
    {
      throw new CruxGeneratorException("Invalid signature for rest proxy method. Can not found the implementation method: "+
          method.getName()+", on class: "+restImplementationClass.getCanonicalName());
    }
   
    if (!Modifier.isPublic(implementationMethod.getModifiers()))
    {
      throw new CruxGeneratorException("Invalid signature for rest proxy method. Implementation method: "+
          method.getName()+", on class: "+restImplementationClass.getCanonicalName()+", is not public.");
    }

    Class<?>[] implTypes = implementationMethod.getParameterTypes();
    JType[] proxyTypes = method.getParameterTypes();

    if ((proxyTypes.length -1)!= implTypes.length)
    {
      throw new CruxGeneratorException("Invalid signature for rest proxy method. The implementation method: "+
          method.getName()+", on class: "+restImplementationClass.getCanonicalName() + " does not match the parameters list.");
    }
    for (int i=0; i<implTypes.length; i++)
    {
      if (!isTypesCompatiblesForSerialization(implTypes[i], proxyTypes[i]))
      {
        throw new CruxGeneratorException("Invalid signature for rest proxy method. Incompatible parameters on method["+method.getReadableDeclaration()+"]");
      }
    }

    JClassType lastParameterType = proxyTypes[proxyTypes.length - 1].isClassOrInterface();
    if (!isTypesCompatiblesForSerialization(implementationMethod.getReturnType(), JClassUtils.getTypeArgForGenericType(lastParameterType)))
    {
      throw new CruxGeneratorException("Invalid signature for rest proxy method. Return type of implementation method is not compatible with Callback's type. Method["+method.getReadableDeclaration()+"]");
    }
  }
View Full Code Here

        {
          Class<?> dataClass = Class.forName(cellClass);
          CustomCell annot = dataClass.getAnnotation(CustomCell.class);
          if (customCells.containsKey(annot.value()))
          {
            throw new CruxGeneratorException("Duplicated CustomCell found: ["+annot.value()+"].");
          }
         
          customCells.put(annot.value(), dataClass.getCanonicalName());
        }
        catch (ClassNotFoundException e)
View Full Code Here

      String controller = ClientControllers.getController(event.getController(), getDevice());
      JClassType controllerClass = getContext().getTypeOracle().findType(controller);
      JMethod loadDataProviderMethod = JClassUtils.getMethod(controllerClass, event.getMethod(), new JType[]{});
      if (loadDataProviderMethod == null)
      {
        throw new CruxGeneratorException("DataProvider factory method not found: Controller["+event.getController()+"], Method["+event.getMethod()+"].");
      }
      JType returnType = loadDataProviderMethod.getReturnType();
      if (returnType instanceof JClassType)
      {
        context.asyncDataProvider =
View Full Code Here

      Annotation[] annotations = methodInfo.parameterAnnotations[i];
      if (annotations == null || annotations.length == 0)
      { // JSON on body
        if(hasBodyObject)
        {
          throw new CruxGeneratorException("Invalid Method: " + methodInfo.method.getEnclosingType().getName() + "." + methodInfo.method.getName() + "(). " +
          "Request body can not contain more than one body parameter (JSON serialized object).");
        }

        hasBodyObject = true;
        String serializerName = new JSonSerializerProxyCreator(context, logger, parameters[i].getType()).create();
        srcWriter.println(builder+".setHeader(\""+HttpHeaderNames.CONTENT_TYPE+"\", \"application/json\");");
        srcWriter.println("JSONValue serialized = new "+serializerName+"().encode("+parameters[i].getName()+");");
        srcWriter.println("String requestData = (serialized==null||serialized.isNull()!=null)?null:serialized.toString();");
      }
      else
      {
        for (Annotation annotation : annotations)
        {
          JParameter parameter = parameters[i];
          JType parameterType = parameter.getType();
          String parameterName = parameter.getName();
          formEncoded = generateMethodParamToBodyCodeForAnnotatedParameter(srcWriter, builder, parameters, formEncoded, i, annotation, parameterType, parameterName);
        }
      }
    }
    if (hasBodyObject && formEncoded)
    {
      throw new CruxGeneratorException("Invalid Method: " + methodInfo.method.getEnclosingType().getName() + "." + methodInfo.method.getName() + "(). " +
      "Request body can not contain form parameters and a JSON serialized object.");
    }
    if (hasBodyObject || formEncoded)
    {
      if (httpMethod.equals("GET"))
      {
        throw new CruxGeneratorException("Invalid Method: " + methodInfo.method.getEnclosingType().getName() + "." + methodInfo.method.getName() + "(). " +
        "Can not use request body parameters on a GET operation.");
      }
      srcWriter.println(builder+".setRequestData(requestData);");
    }
  }
View Full Code Here

        }
      }
    }
    catch (UnsupportedEncodingException e)
    {
      throw new CruxGeneratorException("Unsupported encoding for parameter name on method ["+methodInfo.method.toString()+"]");
    }
    return str.toString();
  }
View Full Code Here

TOP

Related Classes of org.cruxframework.crux.core.rebind.CruxGeneratorException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.