public final class CoreMethods extends Object
Constructor and Description |
---|
CoreMethods(io.toro.martini.ipackage.MartiniPackageProvider packageProvider) |
Modifier and Type | Method and Description |
---|---|
static <T> T |
bean(String name)
Deprecated.
|
static Object |
invoke(String serviceName)
Invoke a Martini service using reflection.
|
static Object |
invoke(String serviceName,
Map<String,Object> parameters)
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 <T> T |
jndi(String name)
Get an object from the JNDI context of the instace.
|
static String |
resolveCode(String localeISO,
MessageSourceResolvable resolvable)
Try to resolve the message using all the attributes contained within the
MessageSourceResolvable argument
that was passed in. |
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.
|
(package private) void |
setMessageSource(MessageSource messageSource) |
@Autowired CoreMethods(io.toro.martini.ipackage.MartiniPackageProvider packageProvider)
@Deprecated public static <T> T bean(String name) throws ToroException
SpringMethods.getBean(String, String)
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()
name
- the name of the Spring beanToroException
public static <T> T jndi(String name) throws ToroException
Get an object from the JNDI context of the instace.
If the object isn't defined in the context, an exception will be thrown.
Example usage:
def bean = 'beanName'.jndi()
name
- the name of the JNDI location to accessToroException
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 )
serviceName
- the name of the service to callparameters
- the parameters to pass to the servicevoid
, null
is returnedThrowable
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 )
packageName
- the name of the package that contains the serviceserviceName
- the name of the service to callparameters
- the parameters to pass to the servicevoid
, null
is returnedThrowable
public static Object invoke(String packageName, String serviceName) throws Throwable
Invoke a Martini service using reflection.
Example usage:
def output = 'packageName'.invoke('serviceName')
packageName
- the name of the package that contains the serviceserviceName
- the name of the service to callvoid
, null
is returnedThrowable
public static Object invoke(String serviceName) throws Throwable
Invoke a Martini service using reflection.
Example usage:
def output = 'serviceName'.invoke()
serviceName
- the name of the service to invokevoid
, null
is returnedThrowable
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 );
localeISO
- the locale in which to do the lookupresolvable
- object storing attributes required to properly resolve a messageNoSuchMessageException
- if the message wasn't foundToroException
MessageFormat
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' );
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;
pass null
if no params are needed for the messageNoSuchMessageException
- if the message wasn't foundToroException
MessageFormat
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' );
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;
pass null
if no params are needed for the messagedefaultMessage
if lookup failsToroException
NoSuchMessageException
MessageFormat
void setMessageSource(MessageSource messageSource)
Copyright © 2020. All rights reserved.