All Downloads are FREE. Search and download functionalities are using the official Maven repository.

gw.lang.parser.coercers.BaseCoercer Maven / Gradle / Ivy

There is a newer version: 1.18.2
Show newest version
/*
 * Copyright 2014 Guidewire Software, Inc.
 */

package gw.lang.parser.coercers;

import gw.lang.parser.ICoercer;

import java.lang.reflect.Method;
import java.lang.reflect.Modifier;

public abstract class BaseCoercer implements ICoercer
{
  public BaseCoercer()
  {
    Class thisClass = this.getClass();
    if( !thisClass.getName().endsWith( "Coercer" ) )
    {
      throw new IllegalStateException( "All coercers must have a name ending with 'Coercer': " + this.getClass().getName() );
    }
    if (!(this instanceof BasePrimitiveCoercer)) {
      Method method = null;
      try
      {
        method = thisClass.getMethod( "instance" );
        if( !Modifier.isStatic( method.getModifiers() ) || !method.getReturnType().equals( thisClass ) )
        {
          method = null;
        }
      }
      catch( NoSuchMethodException e )
      {
        //dealt with below
      }
      if( method == null )
      {
        throw new IllegalStateException( "This coercer must be a singleton that has a static method 'instance' with the return type " + thisClass.getName() );
      }
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy