Class ObjectModel
- java.lang.Object
-
- org.apache.sling.scripting.sightly.compiler.util.ObjectModel
-
@Deprecated public final class ObjectModel extends Object
Deprecated.This class has been moved toObjectModel
.TheObjectModel
class provides various static models for object conversion and object property resolution.
-
-
Field Summary
Fields Modifier and Type Field Description static Set<Class<?>>
PRIMITIVE_CLASSES
Deprecated.ASet
that stores all the supported primitive classes.
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static String
collectionToString(Collection<?> collection)
Deprecated.Converts the passedcollection
to a comma separated valuesString
representation.static Method
findBeanMethod(Class<?> cls, String baseName)
Deprecated.Given a bean class and a base method name, this method will try to find a public method without parameters that is named:baseName
get +BaseName
is +BaseName
static Collection<Object>
fromIterator(Iterator<Object> iterator)
Deprecated.Given aniterator
, this method will return aCollection
.static Object
getField(Object object, String fieldName)
Deprecated.Given anobject
, this method will return the value of the public field identified byfieldName
.static Object
getIndex(Object object, int index)
Deprecated.Given an indexableobject
(i.e.static Object
invokeBeanMethod(Object object, String methodName)
Deprecated.Given a beanobject
, this method will invoke the public method without parameters identified bymethodName
and return the invocation's result.static boolean
isMethodAllowed(Method method)
Deprecated.Returnstrue
if the method is not one of theObject
's class declared methods, with the exception ofObject.toString()
.static boolean
isPrimitive(Object object)
Deprecated.Checks if the providedobject
is an instance of a primitive class.static Object
resolveProperty(Object target, Object property)
Deprecated.Given thetarget
object, this method attempts to resolve and return the value of the passedproperty
.static boolean
toBoolean(Object object)
Deprecated.Converts the givenobject
to a boolean value, applying the following rules: if theobject
isnull
the returned value isfalse
if theobject
is aNumber
the method will returnfalse
only if the number's value is 0 if theString
representation of theobject
is equal irrespective of its casing to "true", the method will returntrue
if theobject
is aCollection
or aMap
, the method will returntrue
only if the collection / map is not empty if the object is an array, the method will returntrue
only if the array is not emptystatic Collection<Object>
toCollection(Object object)
Deprecated.Forces the conversion of the passedobject
to a collection, according to the following rules: if theobject
isnull
an empty collection will be returned if theobject
is an array a list transformation of the array will be returned if theobject
is aCollection
the object itself will be returned if theobject
is an instance of aMap
the map's key set will be returned (seeMap.keySet()
) if theobject
is an instance of anEnumeration
a list transformation will be returned if theobject
is an instance of anIterator
orIterable
the result offromIterator(Iterator)
will be returned if theobject
is an instance of aString
orNumber
aCollection
containing only this object will be returned any other case not covered by the previous rules will result in an emptyCollection
static Number
toNumber(Object object)
Deprecated.Coerces the passedobject
to a numeric value.static String
toString(Object object)
Deprecated.Converts the passedobject
to aString
.
-
-
-
Method Detail
-
isPrimitive
public static boolean isPrimitive(Object object)
Deprecated.Checks if the providedobject
is an instance of a primitive class.- Parameters:
object
- theObject
to check- Returns:
true
if theobject
is a primitive,false
otherwise
-
resolveProperty
public static Object resolveProperty(Object target, Object property)
Deprecated.Given the
target
object, this method attempts to resolve and return the value of the passedproperty
.The property can be either an index or a name:
- index: the property is considered an index if its value is an integer number and in this case the
target
will be assumed to be either an array or it will be converted to aCollection
; a fallback toMap
will be made in case the previous two attempts failed - name: the
property
will be converted to aString
(seetoString(Object)
); thetarget
will be assumed to be either aMap
or an object; if theMap
attempt fails, theproperty
will be used to check if thetarget
has a publicly accessible field with this name or a publicly accessible method with no parameters with this name or a combination of the "get" or "is" prefixes plus the capitalised name (seeinvokeBeanMethod(Object, String)
)
- Parameters:
target
- the target objectproperty
- the property to be resolved- Returns:
- the value of the property or
null
- index: the property is considered an index if its value is an integer number and in this case the
-
toBoolean
public static boolean toBoolean(Object object)
Deprecated.Converts the givenobject
to a boolean value, applying the following rules:- if the
object
isnull
the returned value isfalse
- if the
object
is aNumber
the method will returnfalse
only if the number's value is 0 - if the
String
representation of theobject
is equal irrespective of its casing to "true", the method will returntrue
- if the
object
is aCollection
or aMap
, the method will returntrue
only if the collection / map is not empty - if the object is an array, the method will return
true
only if the array is not empty
- Parameters:
object
- the target object- Returns:
- the boolean representation of the
object
according to the conversion rules
- if the
-
toNumber
public static Number toNumber(Object object)
Deprecated.Coerces the passedobject
to a numeric value. If the passed value is aString
the conversion rules are those ofNumberUtils.createNumber(String)
.- Parameters:
object
- the target object- Returns:
- the numeric representation if one can be determined or
null
- See Also:
NumberUtils.createNumber(String)
-
toString
public static String toString(Object object)
Deprecated.Converts the passedobject
to aString
. The following rules apply:- if the
object
isnull
an empty string will be returned - if the
object
is an instance of aString
the object itself will be returned - if the object is a primitive (see
isPrimitive(Object)
), itsString
representation will be returned - if the object is an
Enum
its name will be returned (seeEnum.name()
) - otherwise an attempt to convert the object to a
Collection
will be made and then the output ofcollectionToString(Collection)
will be returned
- Parameters:
object
- the target object- Returns:
- the string representation of the object or an empty string
- if the
-
toCollection
public static Collection<Object> toCollection(Object object)
Deprecated.Forces the conversion of the passedobject
to a collection, according to the following rules:- if the
object
isnull
an empty collection will be returned - if the
object
is an array a list transformation of the array will be returned - if the
object
is aCollection
the object itself will be returned - if the
object
is an instance of aMap
the map's key set will be returned (seeMap.keySet()
) - if the
object
is an instance of anEnumeration
a list transformation will be returned - if the
object
is an instance of anIterator
orIterable
the result offromIterator(Iterator)
will be returned - if the
object
is an instance of aString
orNumber
aCollection
containing only this object will be returned - any other case not covered by the previous rules will result in an empty
Collection
- Parameters:
object
- the target object- Returns:
- the collection representation of the object
- if the
-
collectionToString
public static String collectionToString(Collection<?> collection)
Deprecated.Converts the passedcollection
to a comma separated valuesString
representation.- Parameters:
collection
- the collection to be converted to CSV- Returns:
- the CSV; if the
collection
is empty then an empty string will be returned
-
fromIterator
public static Collection<Object> fromIterator(Iterator<Object> iterator)
Deprecated.Given aniterator
, this method will return aCollection
.- Parameters:
iterator
- the iterator to be transformed into acollection
- Returns:
- a collection with the iterator's elements
-
getIndex
public static Object getIndex(Object object, int index)
Deprecated.Given an indexableobject
(i.e. an array or a collection), this method will return the value available at theindex
position.- Parameters:
object
- the indexable objectindex
- the index- Returns:
- the value stored at the
index
ornull
-
getField
public static Object getField(Object object, String fieldName)
Deprecated.Given anobject
, this method will return the value of the public field identified byfieldName
.- Parameters:
object
- the target objectfieldName
- the name of the field- Returns:
- the value of the field or
null
if the field was not found
-
invokeBeanMethod
public static Object invokeBeanMethod(Object object, String methodName)
Deprecated.Given a beanobject
, this method will invoke the public method without parameters identified bymethodName
and return the invocation's result.- Parameters:
object
- the target objectmethodName
- the name of the public method without parameters to invoke- Returns:
- the invocation's result or
null
if such a method cannot be found
-
findBeanMethod
public static Method findBeanMethod(Class<?> cls, String baseName)
Deprecated.Given a bean class and a base method name, this method will try to find a public method without parameters that is named:baseName
- get +
BaseName
- is +
BaseName
- Parameters:
cls
- the class into which to search for the methodbaseName
- the base method name- Returns:
- a method that matches the criteria or
null
-
isMethodAllowed
public static boolean isMethodAllowed(Method method)
Deprecated.Returnstrue
if the method is not one of theObject
's class declared methods, with the exception ofObject.toString()
.- Parameters:
method
- the method to check- Returns:
true
if the method is not one of theObject
's class declared methods, with the exception ofObject.toString()
,false
otherwise
-
-