Package org.soybeanMilk.core.bean

Examples of org.soybeanMilk.core.bean.ConvertException


   
    //空字符串到其他类型认为是null
    if(sourceStr==null || "".equals(sourceStr))
    {
      if(tc.isPrimitive())
        throw new ConvertException(sourceObj, targetType, "can not convert "+SbmUtils.toString(sourceObj)+" to primitive type "+SbmUtils.toString(targetType));
      else
        return null;
    }
    else
    {
      try
      {
        return (T)convertStringToType(sourceStr, tc);
      }
      catch(Exception e)
      {
        if(e instanceof ConvertException)
          throw (ConvertException)e;
        else
          throw new ConvertException(sourceObj, targetType, e);
      }
    }
  }
View Full Code Here


   * @throws ConvertException
   * @date 2012-5-23
   */
  protected Object convertNotSupportedThrow(Object sourceObj, Type targetType) throws ConvertException
  {
    throw new ConvertException(sourceObj, targetType, "convert "+SbmUtils.toString(sourceObj)+" to "+SbmUtils.toString(targetType)+" is not supported");
  }
View Full Code Here

      InvocationExecuteException ite=(InvocationExecuteException)cause;
      msg=ite.getCause().getMessage();
    }
    else if(cause instanceof ConvertExecuteException)
    {
      ConvertException cvte=((ConvertExecuteException)cause).getCause();
     
      if(cvte instanceof ParamConvertException)
      {
        ParamConvertException pce=(ParamConvertException)cvte;
       
        msg="The parameter [name: \""+pce.getParamName()+"\", value: \""+pce.getSourceObject()+"\"]";
       
        Type targetType=pce.getTargetType();
        if(Integer.class.equals(targetType)
            || int.class.equals(targetType))
          msg+=" is not valid integer.";
        else
          msg+=" is invalid";
      }
      else
        msg+=cvte.getMessage();
    }
    else
      msg="unknown error";
   
    return msg+" (\""+execution.getExecutable().getName()+"\")";
View Full Code Here

  @Test
  public void convert_emptyStringToPrimitive() throws Exception
  {
    String src="";
   
    ConvertException re=null;
   
    try
    {
      converter.convert(src, int.class);
    }
    catch(ConvertException e)
    {
      re=e;
    }
   
    Assert.assertTrue( (re.getMessage().endsWith(" to primitive type "+SbmUtils.toString(int.class))) );
  }
View Full Code Here

  @Test
  public void convert_convertException() throws Exception
  {
    String src="sdf";
   
    ConvertException re=null;
   
    try
    {
      converter.convert(src, Integer.class);
    }
    catch(ConvertException e)
    {
      re=e;
    }
   
    Assert.assertEquals(src, re.getSourceObject());
    Assert.assertEquals(Integer.class, re.getTargetType());
  }
View Full Code Here

TOP

Related Classes of org.soybeanMilk.core.bean.ConvertException

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.