Package net.sourceforge.javautil.common.coersion

Examples of net.sourceforge.javautil.common.coersion.CoersionException


   
    try {
      // Last Attempt, try to coerce to a string and then to the target type
      return this.coerce(this.coerce(original, String.class), targetType);
    } catch (CoersionException e) {
      throw new CoersionException("Cannot coerce: " + original + " to " + targetType, e);
    }
  }
View Full Code Here


        Constructor c = target.getConstructor(type);
        return (T) c.newInstance(str);
      } catch (Exception e) {}
    }
   
    throw new CoersionException("Unsupported char sequence type: " + target);
  }
View Full Code Here

    else {
      try {
        Constructor c = type.getConstructor(String.class);
        return c.newInstance(original);
      } catch (Exception e) {
        throw new CoersionException("Could not coerce: " + original + " to type " + type, e);
      }
    }
  }
View Full Code Here

      }
    } else if (original instanceof URL) {
      return ((URL)original).toExternalForm();
    }

    throw new CoersionException("Could not coerce: " + original + " into a " + target);
  }
View Full Code Here

      if (original instanceof IVirtualDirectory && !url.endsWith("/")) url += "/";
     
      return url;
    }

    throw new CoersionException("Could not convert " + original + " to " + target);
  }
View Full Code Here

        return format.parse( String.valueOf(original) );
      } else if (original instanceof Date) {
        return format.format( (Date) original );
      }
    } catch (ParseException e) {
      throw new CoersionException(e);
    }

    throw new CoersionException("Could not convert: " + original + " to " + target);
  }
View Full Code Here

      }
    } else if (original instanceof Date) {
      return format[0].format( (Date) original );
    }

    throw new CoersionException("Could not convert: " + original + " to " + target);
  }
View Full Code Here

      return new GStringImpl(new Object[0], new String[] { (String) original });
    } else if (original instanceof GString) {
      return original.toString();
    }
   
    throw new CoersionException("Cannot coerce: " + original + " to " + target);
  }
View Full Code Here

        if (parts.length == 2)
          return new ClassArtifactReferenceImpl(parts[0], parts[1]);
        else if (parts.length == 3 || parts.length == 4)
          return new ClassPackageReferenceImpl(parts[0], parts[1], parts[2], parts.length == 4 ? parts[3] : null);
        else
          throw new CoersionException("Invalid package reference: " + original);
      }
    } else if (target == String.class) {
      if (original instanceof IClassArtifactReference) {
        IClassArtifactReference ref = (IClassArtifactReference) original;
        StringBuffer sb = new StringBuffer();
       
        sb.append(ref.getGroupId()).append(":").append(ref.getArtifactId()).append(":");
       
        if (ref instanceof IClassPackageReference) {
          IClassPackageReference pref = (IClassPackageReference) ref;
          sb.append(":").append(pref.getVersion().toVersionString());
       
          if (pref.getClassifier() != null) sb.append(":").append(pref.getClassifier());
        }
       
        return sb.toString();
      }
    }
   
    throw new CoersionException("Cannot coerce: " + original + " to " + target);
  }
View Full Code Here

TOP

Related Classes of net.sourceforge.javautil.common.coersion.CoersionException

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.