Class CoreMethods

java.lang.Object
io.toro.martini.CoreMethods

public final class CoreMethods extends Object
Contains methods for getting objects and invoking services from Martini's context.
  • Constructor Details

  • Method Details

    • bean

      @Deprecated public static <T> T bean(String name) throws ToroException

      Get a bean by name from the Spring context of the Martini package the calling script is in.

      If the bean isn't defined in the Spring context of the Martini package, it will look for the bean in the shared, instance-wide Spring context.

      Example usage:

       def bean = 'beanName'.bean()
       

      Parameters:
      name - the name of the Spring bean
      Returns:
      the spring bean
      Throws:
      ToroException
      Since:
      1.0
    • jndi

      public static <T> T jndi(String name) throws ToroException

      Get an object from the JNDI context of the instance.

      If the object isn't defined in the context, an exception will be thrown.

      Example usage:

           def bean = 'beanName'.jndi()
       

      Parameters:
      name - the name of the JNDI location to access
      Returns:
      the JNDI object
      Throws:
      ToroException
      Since:
      1.0
    • invoke

      public static Object invoke(String serviceName, Map<String,Object> parameters) throws Throwable

      Invoke a Martini service using reflection.

      Example usage:

       def input = [ name:'Gromit', likes:'cheese', id:1234 ]
       def output = 'serviceName'.invoke( input )
       

      Parameters:
      serviceName - the name of the service to call
      parameters - the parameters to pass to the service
      Returns:
      the value returned from the invoked service; if the return type is void, null is returned
      Throws:
      Throwable
      Since:
      1.0
    • invoke

      public static Object invoke(String packageName, String serviceName, Map<String,Object> parameters) throws Throwable

      Invoke a Martini service using reflection.

      Example usage:

       def input = [ name:'Gromit', likes:'cheese', id:1234 ]
       def output = 'packageName'.invoke('serviceName', input )
       

      Parameters:
      packageName - the name of the package that contains the service
      serviceName - the name of the service to call
      parameters - the parameters to pass to the service
      Returns:
      the value returned from the invoked service; if the return type is void, null is returned
      Throws:
      Throwable
      Since:
      1.0
    • invoke

      public static Object invoke(String packageName, String serviceName) throws Throwable

      Invoke a Martini service using reflection.

      Example usage:

       def output = 'packageName'.invoke('serviceName')
       

      Parameters:
      packageName - the name of the package that contains the service
      serviceName - the name of the service to call
      Returns:
      the value returned from the invoked service; if the return type is void, null is returned
      Throws:
      Throwable
      Since:
      1.0
    • invoke

      public static Object invoke(String serviceName) throws Throwable

      Invoke a Martini service using reflection.

      Example usage:

       def output = 'serviceName'.invoke()
       

      Parameters:
      serviceName - the name of the service to invoke
      Returns:
      the value returned from the invoked service; if the return type is void, null is returned
      Throws:
      Throwable
      Since:
      1.0
    • resolveCode

      public static String resolveCode(String localeISO, MessageSourceResolvable resolvable) throws ToroException, NoSuchMessageException

      Try to resolve the message using all the attributes contained within the MessageSourceResolvable argument that was passed in.

      When resolving the message, Martini will use the MessageSource bean declared on your webapp. If a MessageSource, or the resolvable could not be found within your webapp, Martini will use its default MessageSource to resolve the message.

      Example usage:

       println 'en'.resolveCode( resolvable );
       

      Parameters:
      localeISO - the locale in which to do the lookup
      resolvable - object storing attributes required to properly resolve a message
      Returns:
      the resolved message
      Throws:
      NoSuchMessageException - if the message wasn't found
      ToroException
      Since:
      1.0
      See Also:
    • resolveCode

      public static String resolveCode(String localeISO, String code, Object... args) throws ToroException, NoSuchMessageException

      Try to resolve the message. Treat as an error if the message can't be found.

      When resolving the message, Martini will use the MessageSource bean declared on your webapp. If a MessageSource, or the code could not be found within your webapp, Martini will use its default MessageSource to resolve the message.

      Example usage:

       println 'en'.resolveCode( 'message', ['param1','param2'] as String[] );
       println 'en'.resolveCode( 'sayName' );
       

      Parameters:
      localeISO - the locale in which to do the lookup
      code - the code to lookup up
      args - array of arguments that will be filled in for params within the message; pass null if no params are needed for the message
      Returns:
      the resolved message
      Throws:
      NoSuchMessageException - if the message wasn't found
      ToroException
      Since:
      1.0
      See Also:
    • resolveCode

      public static String resolveCode(String localeISO, String code, String defaultMessage, Object... args) throws ToroException, NoSuchMessageException

      Try to resolve the message. Return default message if no message was found.

      When resolving the message, Martini will use the MessageSource bean declared on your webapp. If a MessageSource, or the code could not be found within your webapp, Martini will use its default MessageSource to resolve the message.

      Example usage:

       println 'en'.resolveCode( 'message', 'defaultMessageCode', ['param1','param2'] as String[] );
       println 'en'.resolveCode( 'sayName', 'defaultMessageCode' );
       

      Parameters:
      localeISO - the locale in which to do the lookup
      code - the code to lookup up
      defaultMessage - string to return if the lookup fails
      args - array of arguments that will be filled in for params within the message; pass null if no params are needed for the message
      Returns:
      the resolved message; or the defaultMessage if lookup fails
      Throws:
      ToroException
      NoSuchMessageException
      Since:
      1.0
      See Also:
    • setMessageSource

      void setMessageSource(MessageSource messageSource)