package net.sourceforge.javautil.groovy.coerce;
import org.codehaus.groovy.runtime.GStringImpl;
import groovy.lang.GString;
import net.sourceforge.javautil.common.coersion.Coersion;
import net.sourceforge.javautil.common.coersion.CoersionException;
import net.sourceforge.javautil.common.coersion.CoersionProvider;
import net.sourceforge.javautil.common.coersion.impl.CoersionAbstract;
/**
* This will handle {@link GString} coersion.
*
* @author elponderador
* @author $Author$
* @version $Id$
*/
public class GStringCoersion extends CoersionAbstract<String, GString> {
public GStringCoersion() {
super(String.class, GString.class);
}
public Object coerce(Object original, Class target) {
if (original instanceof String) {
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);
}
}