|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.directwebremoting.util.LocalUtil
public final class LocalUtil
Various utilities, stuff that we're still surprised isn't in the JDK, and stuff that perhaps is borderline JDK material, but isn't really pure DWR either. TODO: This probably needs cutting up into
| Method Summary | ||
|---|---|---|
static void |
addNoCacheHeaders(javax.servlet.http.HttpServletResponse resp)
Add headers to prevent browsers and proxies from caching this reply. |
|
static java.lang.String |
capitalize(java.lang.String input)
Changes the first letter to upper case. |
|
static java.lang.Class<?> |
classForName(java.lang.String className)
Utility to essentially do Class forName and allow configurable Classloaders. |
|
static
|
classForName(java.lang.String debugContext,
java.lang.String className,
java.lang.Class<T> impl)
Utility to essentially do Class forName with the assumption that the environment expects failures for missing jar files and can carry on if this process fails. |
|
static
|
classNewInstance(java.lang.String name,
java.lang.String className,
java.lang.Class<T> impl)
Utility to essentially do Class forName and newInstance with the assumption that the environment expects failures for missing jar files and can carry on if this process fails. |
|
static void |
close(java.io.Closeable in)
InputStream closer that can cope if the input stream is null. |
|
static void |
close(OutputStreamLoader loader)
OutputStreamLoader closer that can cope if the input is null. |
|
static void |
debugRequest(javax.servlet.http.HttpServletRequest request)
If something has gone wrong we want to know all about the request that caused the failure |
|
static boolean |
equals(java.lang.Object object1,
java.lang.Object object2)
A helper for implementing Object.equals(Object) when some of your
members could be null. |
|
static java.lang.reflect.Field[] |
getAllFields(java.lang.Class<?> clazz)
Return a list of all fields (whatever access status, and on whatever superclass they were defined) that can be found on this class. |
|
static java.util.List<java.lang.Class<?>> |
getAllSuperclasses(java.lang.Class<?> clazz)
Return a List of super-classes for the given class. |
|
static java.lang.String |
getFullUrlToDwrServlet(javax.servlet.http.HttpServletRequest request)
|
|
static java.io.InputStream |
getInternalResourceAsStream(java.lang.String path)
Open a stream to an internal file resource located in the DWR package tree. |
|
static java.lang.reflect.Method |
getMethod(java.lang.Class<?> clazz,
java.lang.String name,
java.lang.Class<?>... args)
Utility to retrieve a method. |
|
static java.lang.Class<?> |
getNonPrimitiveType(java.lang.Class<?> type)
|
|
static
|
getProperty(java.lang.Object pojo,
java.lang.String propertyName,
java.lang.Class<T> type)
Utility to find a getter and return it's value from an object If Java had the option to temporarily do dynamic typing there would be no need for this. |
|
static java.lang.Class<?> |
getPropertyType(java.lang.Class<?> real,
java.lang.String key)
Set a property on an object using reflection |
|
static java.net.URL |
getResource(java.lang.String path)
Open a stream to a file resource located on the classpath. |
|
static java.lang.Throwable |
getRootCause(java.lang.Throwable ex)
Find the leaf cause of an exception chain. |
|
static long |
getSystemClassloadTime()
Get a timestamp for the earliest time that we know the JVM started |
|
static java.lang.reflect.Method |
getWriteMethod(java.lang.Class<?> clazz,
java.beans.PropertyDescriptor property)
Obtains the write method for a property. |
|
static boolean |
hasLength(java.lang.CharSequence str)
Check that the given CharSequence is neither null nor of length 0. |
|
static boolean |
hasText(java.lang.CharSequence str)
Check whether the given CharSequence has actual text. |
|
static java.lang.String |
inferWildcardReplacements(java.lang.String base,
java.lang.String wildcarded)
Expands wildcards in an identifier string by using information in a base identifier name. |
|
static java.lang.Object |
invoke(java.lang.Object object,
java.lang.reflect.Method method,
java.lang.Object[] params)
Calling methods using reflection is useful for graceful fallback - this is a helper method to make this easy |
|
static boolean |
isClassNameInDwrOriginalPackage(java.lang.String className)
Determines if a classname resides in the DWR original package (org.directwebremoting). |
|
static boolean |
isClassNameInDwrRemappedPackage(java.lang.String className)
Determines if a classname resides in the remapped package, if applicable. |
|
static boolean |
isEquivalent(java.lang.Class<?> c1,
java.lang.Class<?> c2)
True if c1 is java.lang.Boolean and c2 is boolean, etc. |
|
static boolean |
isJavaIdentifier(java.lang.String test)
Determines if the specified string is permissible as a Java identifier. |
|
static boolean |
isJavaIdentifierWithPackage(java.lang.String test)
Determines if the specified string is permissible as a Java identifier potentially prefixed with package names. |
|
static boolean |
isJavaScriptTypeAssignableTo(java.lang.String javaScriptType,
java.lang.Class<?> clazz)
Determines if a JavaScript type is assignable to the passed in Java class. |
|
static boolean |
isLetterOrDigitOrUnderline(java.lang.String test)
Determines if the specified string contains only Unicode letters or digits as defined by Character.isLetterOrDigit(char) |
|
static boolean |
isMeteorAvailable()
Is Atmosphere/Meteor present on the classpath? |
|
static boolean |
isSafeHierarchicalIdentifierInBrowser(java.lang.String test)
Tests if a string contains only characters that will allow safe use inside html element attributes and url:s, and is a valid hierarchical identifier wrt to dot ("package") segments. |
|
static boolean |
isSafeIdentifierInBrowser(java.lang.String test)
Tests if a string contains only characters that will allow safe use inside html element attributes and url:s. |
|
static boolean |
isServletClass(java.lang.Class<?> paramType)
Is this class one that we auto fill, so the user can ignore? |
|
static boolean |
isSimpleName(java.lang.String name)
Is this object property one that we can use in a JSON style or do we need to get fancy. |
|
static boolean |
isTypeSimplyConvertable(java.lang.Class<?> paramType)
Can the type be used in a call to simpleConvert(String, Class)? |
|
static boolean |
isValidMappedClassName(java.lang.String test)
Determines whether the supplied string is a valid class name to use for class-mapped data classes. |
|
static boolean |
isValidScriptName(java.lang.String test)
Determines whether the supplied string is a valid script name to use for remoted classes. |
|
static boolean |
isWrapper(java.lang.Object object)
Checks if this object is an instance of a primitive wrapper. |
|
static
|
iterableizer(java.util.Enumeration<?> en,
java.lang.Class<T> type)
Go Java! Why do I even need to do this? |
|
static
|
iterableizer(java.util.Enumeration<T> en)
Go Java! How many people have written this code? |
|
static java.lang.String |
join(java.lang.Object[] array,
java.lang.String separator)
Create a string by joining the array elements together with the separator in-between each element. |
|
static void |
makeAccessible(java.lang.reflect.Constructor<?> ctor)
Make the given constructor accessible, explicitly setting it accessible if necessary. |
|
static java.lang.String |
originalDwrClassName(java.lang.String className)
Converts a remapped DWR classname to the corresponding original name in the org.directwebremoting package. |
|
static java.util.Locale |
parseLocaleString(java.lang.String localeString)
Parse the given localeString into a Locale. |
|
static java.lang.Class<?> |
primitiveToWrapper(java.lang.Class<?> clazz)
Converts the specified primitive Class object to its corresponding wrapper Class object. |
|
static java.lang.String |
remappedDwrClassName(java.lang.String className)
Converts a DWR classname in the original org.directwebremoting package to the corresponding name in the remapped package, if applicable. |
|
static java.lang.String |
remappedResourcePath(java.lang.String path)
Adjust a resource path to match any remapping done to the DWR package path. |
|
static void |
setParams(java.lang.Object object,
java.util.Map<java.lang.String,?> params,
java.util.List<java.lang.String> ignore)
Set use reflection to set the setters on the object called by the keys in the params map with the corresponding values |
|
static void |
setProperty(java.lang.Object object,
java.lang.String key,
java.lang.Object value)
Set a property on an object using reflection |
|
static int |
shrink(long diff)
Comparator.compare(Object, Object) demands that the
return is 1, 0, -1. |
|
static
|
simpleConvert(java.lang.String value,
java.lang.Class<T> paramType)
A very simple conversion function for all the IoC style setup and reflection that we are doing. |
|
static java.lang.Class<?> |
toClass(java.lang.reflect.Type parameterType,
java.lang.String debugContext)
Utility to find a Class> from a Type if possible, assuming String.class if the conversion can't be made |
|
static java.lang.String |
urlDecode(java.lang.String value)
URL decode a value. |
|
static java.lang.String |
urlEncode(java.lang.String value)
URL encode a value. |
|
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method Detail |
|---|
public static java.lang.String join(java.lang.Object[] array,
java.lang.String separator)
array - The array of elements to joinseparator - The string sequence to place between array elements
public static boolean hasText(java.lang.CharSequence str)
true if the string not null,
its length is greater than 0, and it contains at least one non-whitespace character.
LocalUtil.hasText(null) = false
LocalUtil.hasText("") = false
LocalUtil.hasText(" ") = false
LocalUtil.hasText("12345") = true
LocalUtil.hasText(" 12345 ") = true
str - the CharSequence to check (may be null)
true if the CharSequence is not null,
its length is greater than 0, and it does not contain whitespace onlyCharacter.isWhitespace(char)public static boolean hasLength(java.lang.CharSequence str)
null nor of length 0.
Note: Will return true for a CharSequence that purely consists of whitespace.
LocalUtil.hasLength(null) = false
LocalUtil.hasLength("") = false
LocalUtil.hasLength(" ") = true
LocalUtil.hasLength("Hello") = true
str - the CharSequence to check (may be null)
true if the CharSequence is not null and has lengthhasText(java.lang.CharSequence)public static boolean isJavaIdentifier(java.lang.String test)
test - the string to be tested.
Character.isJavaIdentifierPart(char),
Character.isJavaIdentifierStart(char)public static boolean isJavaIdentifierWithPackage(java.lang.String test)
test - the string to be tested.
public static boolean isLetterOrDigitOrUnderline(java.lang.String test)
Character.isLetterOrDigit(char)
test - The string to test
Character.isLetterOrDigit(char)public static boolean isValidScriptName(java.lang.String test)
test -
public static boolean isValidMappedClassName(java.lang.String test)
test -
public static boolean isSafeHierarchicalIdentifierInBrowser(java.lang.String test)
test -
public static boolean isSafeIdentifierInBrowser(java.lang.String test)
test -
public static java.lang.String inferWildcardReplacements(java.lang.String base,
java.lang.String wildcarded)
base - the base identifierwildcarded - the wildcarded string to be replaced
public static boolean isEquivalent(java.lang.Class<?> c1,
java.lang.Class<?> c2)
c1 - the first class to testc2 - the second class to test
public static boolean equals(java.lang.Object object1,
java.lang.Object object2)
Object.equals(Object) when some of your
members could be null. Returns true if both objects are null, or if
neither object is null, but object1.equals(object2) returns true.
Otherwise returns false.
object1 - The first object to compare.object2 - The second object to compare.
Object.equals(Object)public static int shrink(long diff)
Comparator.compare(Object, Object) demands that the
return is 1, 0, -1. This helps implement that.
diff - The result of some subtraction.
public static java.lang.Class<?> getNonPrimitiveType(java.lang.Class<?> type)
type - The class to de-primitivize
public static void addNoCacheHeaders(javax.servlet.http.HttpServletResponse resp)
resp - The response to add headers topublic static boolean isServletClass(java.lang.Class<?> paramType)
paramType - The type to test
public static java.lang.String getFullUrlToDwrServlet(javax.servlet.http.HttpServletRequest request)
request -
public static void debugRequest(javax.servlet.http.HttpServletRequest request)
request - The HttpServletRequest the borkedpublic static <T> java.lang.Iterable<T> iterableizer(java.util.Enumeration<T> en)
en - The Enumeration that we want to iterate over
Iterable for use in a for each loop
public static <T> java.lang.Iterable<T> iterableizer(java.util.Enumeration<?> en,
java.lang.Class<T> type)
en - The Enumeration that we want to iterate overtype - For when we were given an Enumeration> and need an IteratorIterable for use in a for each looppublic static java.lang.String urlDecode(java.lang.String value)
URLDecoder.decode(String, String) throws an
UnsupportedEncodingException, which is silly given that the most
common use case will be to pass in "UTF-8"
value - The string to decode
public static java.lang.String urlEncode(java.lang.String value)
URLEncoder.encode(String, String) throws an
UnsupportedEncodingException, which is silly given that the most
common use case will be to pass in "UTF-8"
value - The string to decode
public static void setParams(java.lang.Object object,
java.util.Map<java.lang.String,?> params,
java.util.List<java.lang.String> ignore)
object - The object to setupparams - The settings to useignore - List of keys to not warn about if they are not properties
Note only the warning is skipped, we still try the setter
public static void setProperty(java.lang.Object object,
java.lang.String key,
java.lang.Object value)
throws java.lang.NoSuchMethodException,
java.lang.SecurityException,
java.lang.IllegalAccessException,
java.lang.IllegalArgumentException,
java.lang.reflect.InvocationTargetException
object - The object to call the setter onkey - The name of the property to set.value - The new value to use for the property
java.lang.NoSuchMethodException - Passed on from reflection code
java.lang.SecurityException - Passed on from reflection code
java.lang.IllegalAccessException - Passed on from reflection code
java.lang.IllegalArgumentException - Passed on from reflection code
java.lang.reflect.InvocationTargetException - Passed on from reflection codepublic static final boolean isWrapper(java.lang.Object object)
object - anything
public static java.lang.Class<?> getPropertyType(java.lang.Class<?> real,
java.lang.String key)
real - The object type to find the setter onkey - The name of the property to set.public static boolean isTypeSimplyConvertable(java.lang.Class<?> paramType)
simpleConvert(String, Class)?
paramType - The type to test
public static <T> T simpleConvert(java.lang.String value,
java.lang.Class<T> paramType)
value - The value to convertparamType - The type to convert to. Currently any primitive types and
String are supported.
public static boolean isSimpleName(java.lang.String name)
name - The name to test for JSON compatibility
public static java.lang.Class<?> classForName(java.lang.String className)
throws java.lang.ClassNotFoundException
This implementation makes use of the context classloader for the current thread, with fallback to the local classloader if needed.
className - The class to create
java.lang.ClassNotFoundException - If className is not validpublic static boolean isMeteorAvailable()
public static java.lang.String originalDwrClassName(java.lang.String className)
className -
public static java.lang.String remappedDwrClassName(java.lang.String className)
className -
public static boolean isClassNameInDwrOriginalPackage(java.lang.String className)
className -
public static boolean isClassNameInDwrRemappedPackage(java.lang.String className)
className -
public static <T> java.lang.Class<? extends T> classForName(java.lang.String debugContext,
java.lang.String className,
java.lang.Class<T> impl)
T - The base type that we want a class to implementdebugContext - The name for debugging purposesclassName - The class to createimpl - The implementation class - what should className do?
public static java.lang.reflect.Method getMethod(java.lang.Class<?> clazz,
java.lang.String name,
java.lang.Class<?>... args)
clazz - - The class where the method exists.name - - The name of the method to retrieve.args - - The arguments the method takes.
public static <T> T classNewInstance(java.lang.String name,
java.lang.String className,
java.lang.Class<T> impl)
T - The base type that we want a class to implementname - The name for debugging purposesclassName - The class to createimpl - The implementation class - what should className do?
public static java.lang.Object invoke(java.lang.Object object,
java.lang.reflect.Method method,
java.lang.Object[] params)
throws java.lang.IllegalStateException
object - The object to use as 'this'method - The method to call, can be null in which case null is returnedparams - The parameters to pass to the reflection call
java.lang.IllegalStateException - If anything goes wrongpublic static java.lang.String remappedResourcePath(java.lang.String path)
path - original resource path
public static java.io.InputStream getInternalResourceAsStream(java.lang.String path)
path -
public static java.net.URL getResource(java.lang.String path)
path -
public static void close(java.io.Closeable in)
in - The resource to closepublic static void close(OutputStreamLoader loader)
loader - The resource to closepublic static void makeAccessible(java.lang.reflect.Constructor<?> ctor)
setAccessible(true) method is only called
when actually necessary, to avoid unnecessary conflicts with a JVM
SecurityManager (if active).
ctor - the constructor to make accessibleAccessibleObject.setAccessible(java.lang.reflect.AccessibleObject[], boolean)public static java.util.List<java.lang.Class<?>> getAllSuperclasses(java.lang.Class<?> clazz)
clazz - the class to look up
public static java.lang.reflect.Field[] getAllFields(java.lang.Class<?> clazz)
This is like a union of Class.getDeclaredFields() which
ignores and super-classes, and Class.getFields() which ignored
non-public fields
clazz - The class to introspect
public static <T> T getProperty(java.lang.Object pojo,
java.lang.String propertyName,
java.lang.Class<T> type)
pojo - The POJO to extract some data from.propertyName - The name of the property form which we form a getter
name by upper-casing the first letter (in the EN locale) and prefixing
with 'get'
public static java.lang.Class<?> toClass(java.lang.reflect.Type parameterType,
java.lang.String debugContext)
public static java.util.Locale parseLocaleString(java.lang.String localeString)
localeString into a Locale.
This is the inverse operation of Locale's toString.
localeString - the locale string, following Locale's
toString() format ("en", "en_UK", etc);
also accepts spaces as separators, as an alternative to underscores
Locale instancepublic static java.lang.Class<?> primitiveToWrapper(java.lang.Class<?> clazz)
clazz - the class to convert, may be null
public static java.lang.String capitalize(java.lang.String input)
input - any
public static java.lang.reflect.Method getWriteMethod(java.lang.Class<?> clazz,
java.beans.PropertyDescriptor property)
property - any
public static boolean isJavaScriptTypeAssignableTo(java.lang.String javaScriptType,
java.lang.Class<?> clazz)
javaScriptType - clazz -
public static long getSystemClassloadTime()
public static java.lang.Throwable getRootCause(java.lang.Throwable ex)
|
Copyright ยจ 2008 | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||