Package net.sourceforge.javautil.groovy.coerce

Source Code of net.sourceforge.javautil.groovy.coerce.GStringCoersion

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);
  }

}
TOP

Related Classes of net.sourceforge.javautil.groovy.coerce.GStringCoersion

TOP
Copyright © 2018 www.massapi.com. 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.