org.apache.axis.utils

Class JavaUtils

public class JavaUtils extends Object

Utility class to deal with Java language related issues, such as type conversions.

Author: Glen Daniels (gdaniels@apache.org)

Nested Class Summary
interfaceJavaUtils.ConvertCache
It the argument to the convert(...) method implements the ConvertCache interface, the convert(...) method will use the set/get methods to store and retrieve converted values.
static classJavaUtils.HolderException
Field Summary
static charCR
protected static Loglog
static StringLS
The prefered line separator
static charNL
Method Summary
static Objectconvert(Object arg, Class destClass)
Utility function to convert an Object to some desired Class.
static ObjectgetHolderValue(Object holder)
Gets the Holder value.
static ClassgetHolderValueType(Class type)
Determines if the Class is a Holder class.
static ImagegetImageFromStream(InputStream is)
static StringgetLoadableClassName(String text)
Converts text of the form Foo[] to the proper class name for loading [LFoo
static ClassgetPrimitiveClass(Class wrapper)
static StringgetTextClassName(String text)
Converts text of the form [LFoo to the Foo[]
static StringgetUniqueValue(Collection values, String initValue)
Makes the value passed in initValue unique among the String values contained in values by suffixing it with a decimal digit suffix.
static StringgetWrapper(String primitive)
static ClassgetWrapperClass(Class primitive)
static booleanisAttachmentSupported()
Determine whether attachments are supported by checking if the following classes are available: javax.activation.DataHandler, javax.mail.internet.MimeMultipart.
static booleanisBasic(Class javaType)
static booleanisConvertable(Object obj, Class dest)
static booleanisConvertable(Object obj, Class dest, boolean isEncoded)
static booleanisEnumClass(Class cls)
Determine if the class is a JAX-RPC enum class.
static booleanisFalse(String value)
Tests the String 'value': return 'true' if its 'false', '0', or 'no' - else 'false' Follow in 'C' tradition of boolean values: false is specific (0), everything else is true;
static booleanisFalse(Object value, boolean defaultVal)
Tests the Object 'value': if its null, return default. if its a Boolean, return booleanValue() if its an Integer, return 'false' if its '0' else 'true' if its a String, return 'false' if its 'false', 'no', or '0' - else 'true' All other types return 'true'
static booleanisFalse(Object value)
static booleanisFalseExplicitly(String value)
Tests the String 'value': return 'true' if its null, 'false', '0', or 'no' - else 'false'
static booleanisFalseExplicitly(Object value, boolean defaultVal)
Tests the Object 'value': if its null, return default. if its a Boolean, return !
static booleanisFalseExplicitly(Object value)
static booleanisJavaId(String id)
isJavaId Returns true if the name is a valid java identifier.
static booleanisJavaKeyword(String keyword)
checks if the input string is a valid java keyword.
static booleanisTrue(String value)
Tests the String 'value': return 'false' if its 'false', '0', or 'no' - else 'true' Follow in 'C' tradition of boolean values: false is specific (0), everything else is true;
static booleanisTrue(Object value, boolean defaultVal)
Tests the Object 'value': if its null, return default. if its a Boolean, return booleanValue() if its an Integer, return 'false' if its '0' else 'true' if its a String, return 'false' if its 'false', 'no', or '0' - else 'true' All other types return 'true'
static booleanisTrue(Object value)
static booleanisTrueExplicitly(String value)
Tests the String 'value': return 'true' if its 'true', '1', or 'yes' - else 'false'
static booleanisTrueExplicitly(Object value, boolean defaultVal)
Tests the Object 'value': if its null, return default. if its a Boolean, return booleanValue() if its an Integer, return 'false' if its '0' else 'true' if its a String, return isTrueExplicitly((String)value).
static booleanisTrueExplicitly(Object value)
static StringmakeNonJavaKeyword(String keyword)
Turn a java keyword string into a non-Java keyword string.
static StringmimeToJava(String mime)
Given the MIME type string, return the Java mapping.
static Stringreplace(String name, String oldT, String newT)
replace: Like String.replace except that the old new items are strings.
static voidsetHolderValue(Object holder, Object value)
Sets the Holder value.
static StringstackToString(Throwable e)
static StringxmlNameToJava(String name)
Map an XML name to a Java identifier per the mapping rules of JSR 101 (in version 1.0 this is "Chapter 20: Appendix: Mapping of XML Names"

Field Detail

CR

public static final char CR

log

protected static Log log

LS

public static final String LS
The prefered line separator

NL

public static final char NL

Method Detail

convert

public static Object convert(Object arg, Class destClass)
Utility function to convert an Object to some desired Class. Right now this works for: arrays <-> Lists, Holders <-> held values

Parameters: arg the array to convert destClass the actual class we want

getHolderValue

public static Object getHolderValue(Object holder)
Gets the Holder value.

Parameters: holder Holder object

Returns: value object

getHolderValueType

public static Class getHolderValueType(Class type)
Determines if the Class is a Holder class. If so returns Class of held type else returns null

Parameters: type the suspected Holder Class

Returns: class of held type or null

getImageFromStream

public static Image getImageFromStream(InputStream is)

getLoadableClassName

public static String getLoadableClassName(String text)
Converts text of the form Foo[] to the proper class name for loading [LFoo

getPrimitiveClass

public static Class getPrimitiveClass(Class wrapper)

getTextClassName

public static String getTextClassName(String text)
Converts text of the form [LFoo to the Foo[]

getUniqueValue

public static String getUniqueValue(Collection values, String initValue)
Makes the value passed in initValue unique among the String values contained in values by suffixing it with a decimal digit suffix.

getWrapper

public static String getWrapper(String primitive)

getWrapperClass

public static Class getWrapperClass(Class primitive)

isAttachmentSupported

public static boolean isAttachmentSupported()
Determine whether attachments are supported by checking if the following classes are available: javax.activation.DataHandler, javax.mail.internet.MimeMultipart.

isBasic

public static boolean isBasic(Class javaType)

isConvertable

public static boolean isConvertable(Object obj, Class dest)

isConvertable

public static boolean isConvertable(Object obj, Class dest, boolean isEncoded)

isEnumClass

public static boolean isEnumClass(Class cls)
Determine if the class is a JAX-RPC enum class. An enumeration class is recognized by a getValue() method, a toString() method, a fromString(String) method a fromValue(type) method and the lack of a setValue(type) method

isFalse

public static final boolean isFalse(String value)
Tests the String 'value': return 'true' if its 'false', '0', or 'no' - else 'false' Follow in 'C' tradition of boolean values: false is specific (0), everything else is true;

isFalse

public static final boolean isFalse(Object value, boolean defaultVal)
Tests the Object 'value': if its null, return default. if its a Boolean, return booleanValue() if its an Integer, return 'false' if its '0' else 'true' if its a String, return 'false' if its 'false', 'no', or '0' - else 'true' All other types return 'true'

isFalse

public static final boolean isFalse(Object value)

isFalseExplicitly

public static final boolean isFalseExplicitly(String value)
Tests the String 'value': return 'true' if its null, 'false', '0', or 'no' - else 'false'

isFalseExplicitly

public static final boolean isFalseExplicitly(Object value, boolean defaultVal)
Tests the Object 'value': if its null, return default. if its a Boolean, return !booleanValue() if its an Integer, return 'true' if its '0' else 'false' if its a String, return isFalseExplicitly((String)value). All other types return 'false'

isFalseExplicitly

public static final boolean isFalseExplicitly(Object value)

isJavaId

public static boolean isJavaId(String id)
isJavaId Returns true if the name is a valid java identifier.

Parameters: id to check

Returns: boolean true/false

isJavaKeyword

public static boolean isJavaKeyword(String keyword)
checks if the input string is a valid java keyword.

Returns: boolean true/false

isTrue

public static final boolean isTrue(String value)
Tests the String 'value': return 'false' if its 'false', '0', or 'no' - else 'true' Follow in 'C' tradition of boolean values: false is specific (0), everything else is true;

isTrue

public static final boolean isTrue(Object value, boolean defaultVal)
Tests the Object 'value': if its null, return default. if its a Boolean, return booleanValue() if its an Integer, return 'false' if its '0' else 'true' if its a String, return 'false' if its 'false', 'no', or '0' - else 'true' All other types return 'true'

isTrue

public static final boolean isTrue(Object value)

isTrueExplicitly

public static final boolean isTrueExplicitly(String value)
Tests the String 'value': return 'true' if its 'true', '1', or 'yes' - else 'false'

isTrueExplicitly

public static final boolean isTrueExplicitly(Object value, boolean defaultVal)
Tests the Object 'value': if its null, return default. if its a Boolean, return booleanValue() if its an Integer, return 'false' if its '0' else 'true' if its a String, return isTrueExplicitly((String)value). All other types return 'true'

isTrueExplicitly

public static final boolean isTrueExplicitly(Object value)

makeNonJavaKeyword

public static String makeNonJavaKeyword(String keyword)
Turn a java keyword string into a non-Java keyword string. (Right now this simply means appending an underscore.)

mimeToJava

public static String mimeToJava(String mime)
Given the MIME type string, return the Java mapping.

replace

public static final String replace(String name, String oldT, String newT)
replace: Like String.replace except that the old new items are strings.

Parameters: name string oldT old text to replace newT new text to use

Returns: replacement string

setHolderValue

public static void setHolderValue(Object holder, Object value)
Sets the Holder value.

Parameters: holder Holder object value is the object value

stackToString

public static String stackToString(Throwable e)

xmlNameToJava

public static String xmlNameToJava(String name)
Map an XML name to a Java identifier per the mapping rules of JSR 101 (in version 1.0 this is "Chapter 20: Appendix: Mapping of XML Names"

Parameters: name is the xml name

Returns: the java name per JSR 101 specification

Copyright B) 2005 Apache Web Services Project. All Rights Reserved.