class StringToEnvelopeConverter implements Converter<String, Envelope> {

	public Envelope convert(String source) {
		if (source == null) {
			return null;
		} else {
			String[] args = source.trim().split("[\\s,]+");
			if (args.length != 4) {
				throw new IllegalArgumentException("Cannot parse envelope from " + source
						+ ", expected format is \"xmin,ymin,xmax,ymax\"");
			} else {
				double[] coords = new double[4];
				try {
					for (int i = 0; i < coords.length; i++) {
						coords[i] = Double.parseDouble(args[i]);
					}
					return new Envelope(coords[0], coords[1], coords[2], coords[3]);
				} catch (NumberFormatException nfe) {
					throw new IllegalArgumentException("Cannot parse envelope from " + source
							+ ", expected format is \"xmin,ymin,xmax,ymax\"", nfe);
				}
			}
		}
	}

}