Class ObjectModel
- java.lang.Object
-
- org.apache.sling.scripting.sightly.compiler.util.ObjectModel
-
@Deprecated public final class ObjectModel extends java.lang.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 java.util.Set<java.lang.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 java.lang.String
collectionToString(java.util.Collection<?> collection)
Deprecated.Converts the passedcollection
to a comma separated valuesString
representation.static java.lang.reflect.Method
findBeanMethod(java.lang.Class<?> cls, java.lang.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 java.util.Collection<java.lang.Object>
fromIterator(java.util.Iterator<java.lang.Object> iterator)
Deprecated.Given aniterator
, this method will return aCollection
.static java.lang.Object
getField(java.lang.Object object, java.lang.String fieldName)
Deprecated.Given anobject
, this method will return the value of the public field identified byfieldName
.static java.lang.Object
getIndex(java.lang.Object object, int index)
Deprecated.Given an indexableobject
(i.e.static java.lang.Object
invokeBeanMethod(java.lang.Object object, java.lang.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(java.lang.reflect.Method method)
Deprecated.Returnstrue
if the method is not one of theObject
's class declared methods, with the exception ofObject.toString()
.static boolean
isPrimitive(java.lang.Object object)
Deprecated.Checks if the providedobject
is an instance of a primitive class.static java.lang.Object
resolveProperty(java.lang.Object target, java.lang.Object property)
Deprecated.Given thetarget
object, this method attempts to resolve and return the value of the passedproperty
.static boolean
toBoolean(java.lang.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 java.util.Collection<java.lang.Object>
toCollection(java.lang.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 java.lang.Number
toNumber(java.lang.Object object)
Deprecated.Coerces the passedobject
to a numeric value.static java.lang.String
toString(java.lang.Object object)
Deprecated.Converts the passedobject
to aString
.
-
-
-
Method Detail
-
isPrimitive
public static boolean isPrimitive(java.lang.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 java.lang.Object resolveProperty(java.lang.Object target, java.lang.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(java.lang.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 java.lang.Number toNumber(java.lang.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 java.lang.String toString(java.lang.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 java.util.Collection<java.lang.Object> toCollection(java.lang.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 java.lang.String collectionToString(java.util.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 java.util.Collection<java.lang.Object> fromIterator(java.util.Iterator<java.lang.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 java.lang.Object getIndex(java.lang.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 java.lang.Object getField(java.lang.Object object, java.lang.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 java.lang.Object invokeBeanMethod(java.lang.Object object, java.lang.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 java.lang.reflect.Method findBeanMethod(java.lang.Class<?> cls, java.lang.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(java.lang.reflect.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
-
-