grails.util
Class GrailsUtil

java.lang.Object
  extended by grails.util.GrailsUtil

public class GrailsUtil
extends Object

Grails utility methods for command line and GUI applications

Since:
0.2
Version:
$Revision$ First Created: 02-Jun-2006 Last Updated: $Date$
Author:
Graeme Rocher

Constructor Summary
GrailsUtil()
           
 
Method Summary
static ApplicationContext bootstrapGrailsFromApplication(GrailsApplication application)
          Bootstraps Grails with the given GrailsApplication instance
static ApplicationContext bootstrapGrailsFromClassPath()
          Bootstraps a Grails application from the current classpath.
static ApplicationContext bootstrapGrailsFromParentContext(ApplicationContext parent)
          Bootstraps Grails from the given parent ApplicationContext which should contain a bean definition called "grailsApplication" of type GrailsApplication
static Throwable deepSanitize(Throwable t)
          Sanitize the exception and ALL nested causes This will MODIFY the stacktrace of the exception instance and all its causes irreversibly
static void deprecated(Class clazz, String methodOrPropName)
          Logs warning message about deprecation of specified property or method of some class.
static void deprecated(Class clazz, String methodOrPropName, String version)
          Logs warning message about deprecation of specified property or method of some class.
static void deprecated(String message)
          Logs warning message about some deprecation and code style related hints.
static Throwable extractRootCause(Throwable t)
          Extracts the root cause of the exception, no matter how nested it is
static String getEnvironment()
          Deprecated. Use Environment.getCurrent() method instead
static String getGrailsVersion()
           
static boolean isApplicationClass(String className)
           
static boolean isDevelopmentEnv()
          Retrieves whether the current execution environment is the development one
static void printSanitizedStackTrace(Throwable t)
           
static void printSanitizedStackTrace(Throwable t, PrintWriter p)
           
static Throwable sanitize(Throwable t)
          Remove all apparently Grails-internal trace entries from the exception instance This modifies the original instance and returns it, it does not clone
static Throwable sanitizeRootCause(Throwable t)
          Get the root cause of an exception and sanitize it for display to the user This will MODIFY the stacktrace of the root cause exception object and return it
static void warn(String message)
          Logs warning message to grails.util.GrailsUtil logger which is turned on in development mode.
static void writeSlurperResult(groovy.util.slurpersupport.GPathResult result, Writer output)
          Deprecated. Will be removed in a future release or unwritable file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GrailsUtil

public GrailsUtil()
Method Detail

bootstrapGrailsFromClassPath

public static ApplicationContext bootstrapGrailsFromClassPath()

Bootstraps a Grails application from the current classpath. The method will look for an applicationContext.xml file in the classpath that must contain a bean of type GrailsApplication and id grailsApplication

The method will then bootstrap Grails with the GrailsApplication and load all Grails plug-ins found in the path

Returns:
The Grails ApplicationContext instance

bootstrapGrailsFromApplication

public static ApplicationContext bootstrapGrailsFromApplication(GrailsApplication application)
Bootstraps Grails with the given GrailsApplication instance

Parameters:
application - The GrailsApplication instance
Returns:
A Grails ApplicationContext

bootstrapGrailsFromParentContext

public static ApplicationContext bootstrapGrailsFromParentContext(ApplicationContext parent)
Bootstraps Grails from the given parent ApplicationContext which should contain a bean definition called "grailsApplication" of type GrailsApplication


getEnvironment

public static String getEnvironment()
Deprecated. Use Environment.getCurrent() method instead

Retrieves the current execution environment

Returns:
The environment Grails is executing under

isDevelopmentEnv

public static boolean isDevelopmentEnv()
Retrieves whether the current execution environment is the development one

Returns:
True if it is the development environment

getGrailsVersion

public static String getGrailsVersion()

deprecated

public static void deprecated(Class clazz,
                              String methodOrPropName)
Logs warning message about deprecation of specified property or method of some class.

Parameters:
clazz - A class
methodOrPropName - Name of deprecated property or method

deprecated

public static void deprecated(Class clazz,
                              String methodOrPropName,
                              String version)
Logs warning message about deprecation of specified property or method of some class.

Parameters:
clazz - A class
methodOrPropName - Name of deprecated property or method
version - Version of Grails release in which property or method were deprecated

deprecated

public static void deprecated(String message)
Logs warning message about some deprecation and code style related hints.

Parameters:
message - Message to display

warn

public static void warn(String message)
Logs warning message to grails.util.GrailsUtil logger which is turned on in development mode.

Parameters:
message - Message to display

sanitize

public static Throwable sanitize(Throwable t)

Remove all apparently Grails-internal trace entries from the exception instance

This modifies the original instance and returns it, it does not clone

Parameters:
t -
Returns:
The exception passed in, after cleaning the stack trace

printSanitizedStackTrace

public static void printSanitizedStackTrace(Throwable t,
                                            PrintWriter p)

printSanitizedStackTrace

public static void printSanitizedStackTrace(Throwable t)

isApplicationClass

public static boolean isApplicationClass(String className)

extractRootCause

public static Throwable extractRootCause(Throwable t)

Extracts the root cause of the exception, no matter how nested it is

Parameters:
t -
Returns:
The deepest cause of the exception that can be found

sanitizeRootCause

public static Throwable sanitizeRootCause(Throwable t)

Get the root cause of an exception and sanitize it for display to the user

This will MODIFY the stacktrace of the root cause exception object and return it

Parameters:
t -
Returns:
The root cause exception instance, with its stace trace modified to filter out grails runtime classes

deepSanitize

public static Throwable deepSanitize(Throwable t)

Sanitize the exception and ALL nested causes

This will MODIFY the stacktrace of the exception instance and all its causes irreversibly

Parameters:
t -
Returns:
The root cause exception instances, with stack trace modified to filter out grails runtime classes

writeSlurperResult

public static void writeSlurperResult(groovy.util.slurpersupport.GPathResult result,
                                      Writer output)
                               throws IOException
Deprecated. Will be removed in a future release or unwritable file.

Writes out a GPathResult (i.e. the result of parsing XML using XmlSlurper) to the given writer.

Parameters:
result - The root node of the XML to write out.
output - Where to write the XML to.
Throws:
IOException - If the writing fails due to a closed stream


Copyright (c) 2005-2009 The Grails project