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 Summary
Constructors Constructor Description CoreMethods(MartiniPackageProvider packageProvider)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static <T> T
bean(String name)
Deprecated.static Object
invoke(String serviceName)
Invoke a Martini service using reflection.static Object
invoke(String packageName, String serviceName)
Invoke a Martini service using reflection.static Object
invoke(String packageName, String serviceName, Map<String,Object> parameters)
Invoke a Martini service using reflection.static Object
invoke(String serviceName, Map<String,Object> parameters)
Invoke a Martini service using reflection.static <T> T
jndi(String name)
Get an object from the JNDI context of the instance.static String
resolveCode(String localeISO, String code, Object... args)
Try to resolve the message.static String
resolveCode(String localeISO, String code, String defaultMessage, Object... args)
Try to resolve the message.static String
resolveCode(String localeISO, MessageSourceResolvable resolvable)
Try to resolve the message using all the attributes contained within theMessageSourceResolvable
argument that was passed in.(package private) void
setMessageSource(MessageSource messageSource)
-
-
-
Constructor Detail
-
CoreMethods
@Autowired CoreMethods(MartiniPackageProvider packageProvider)
-
-
Method Detail
-
bean
@Deprecated public static <T> T bean(String name) throws ToroException
Deprecated.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 callparameters
- 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 serviceserviceName
- the name of the service to callparameters
- 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 serviceserviceName
- 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 aMessageSource
, or theresolvable
could not be found within your webapp, Martini will use its defaultMessageSource
to resolve the message.Example usage:
println 'en'.resolveCode( resolvable );
- Parameters:
localeISO
- the locale in which to do the lookupresolvable
- object storing attributes required to properly resolve a message- Returns:
- the resolved message
- Throws:
NoSuchMessageException
- if the message wasn't foundToroException
- Since:
- 1.0
- See Also:
MessageFormat
-
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 aMessageSource
, or thecode
could not be found within your webapp, Martini will use its defaultMessageSource
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 lookupcode
- the code to lookup upargs
- array of arguments that will be filled in for params within the message; passnull
if no params are needed for the message- Returns:
- the resolved message
- Throws:
NoSuchMessageException
- if the message wasn't foundToroException
- Since:
- 1.0
- See Also:
MessageFormat
-
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 aMessageSource
, or thecode
could not be found within your webapp, Martini will use its defaultMessageSource
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 lookupcode
- the code to lookup updefaultMessage
- string to return if the lookup failsargs
- array of arguments that will be filled in for params within the message; passnull
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:
MessageFormat
-
setMessageSource
void setMessageSource(MessageSource messageSource)
-
-