Class ObjectModel
- java.lang.Object
-
- org.apache.sling.scripting.sightly.compiler.util.ObjectModel
-
@Deprecated public final class ObjectModel extends java.lang.ObjectDeprecated.This class has been moved toObjectModel.TheObjectModelclass 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_CLASSESDeprecated.ASetthat stores all the supported primitive classes.
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static java.lang.StringcollectionToString(java.util.Collection<?> collection)Deprecated.Converts the passedcollectionto a comma separated valuesStringrepresentation.static java.lang.reflect.MethodfindBeanMethod(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:baseNameget +BaseNameis +BaseNamestatic 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.ObjectgetField(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.ObjectgetIndex(java.lang.Object object, int index)Deprecated.Given an indexableobject(i.e.static java.lang.ObjectinvokeBeanMethod(java.lang.Object object, java.lang.String methodName)Deprecated.Given a beanobject, this method will invoke the public method without parameters identified bymethodNameand return the invocation's result.static booleanisMethodAllowed(java.lang.reflect.Method method)Deprecated.Returnstrueif the method is not one of theObject's class declared methods, with the exception ofObject.toString().static booleanisPrimitive(java.lang.Object object)Deprecated.Checks if the providedobjectis an instance of a primitive class.static java.lang.ObjectresolveProperty(java.lang.Object target, java.lang.Object property)Deprecated.Given thetargetobject, this method attempts to resolve and return the value of the passedproperty.static booleantoBoolean(java.lang.Object object)Deprecated.Converts the givenobjectto a boolean value, applying the following rules: if theobjectisnullthe returned value isfalseif theobjectis aNumberthe method will returnfalseonly if the number's value is 0 if theStringrepresentation of theobjectis equal irrespective of its casing to "true", the method will returntrueif theobjectis aCollectionor aMap, the method will returntrueonly if the collection / map is not empty if the object is an array, the method will returntrueonly if the array is not emptystatic java.util.Collection<java.lang.Object>toCollection(java.lang.Object object)Deprecated.Forces the conversion of the passedobjectto a collection, according to the following rules: if theobjectisnullan empty collection will be returned if theobjectis an array a list transformation of the array will be returned if theobjectis aCollectionthe object itself will be returned if theobjectis an instance of aMapthe map's key set will be returned (seeMap.keySet()) if theobjectis an instance of anEnumerationa list transformation will be returned if theobjectis an instance of anIteratororIterablethe result offromIterator(Iterator)will be returned if theobjectis an instance of aStringorNumberaCollectioncontaining only this object will be returned any other case not covered by the previous rules will result in an emptyCollectionstatic java.lang.NumbertoNumber(java.lang.Object object)Deprecated.Coerces the passedobjectto a numeric value.static java.lang.StringtoString(java.lang.Object object)Deprecated.Converts the passedobjectto aString.
-
-
-
Method Detail
-
isPrimitive
public static boolean isPrimitive(java.lang.Object object)
Deprecated.Checks if the providedobjectis an instance of a primitive class.- Parameters:
object- theObjectto check- Returns:
trueif theobjectis a primitive,falseotherwise
-
resolveProperty
public static java.lang.Object resolveProperty(java.lang.Object target, java.lang.Object property)Deprecated.Given the
targetobject, 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
targetwill be assumed to be either an array or it will be converted to aCollection; a fallback toMapwill be made in case the previous two attempts failed - name: the
propertywill be converted to aString(seetoString(Object)); thetargetwill be assumed to be either aMapor an object; if theMapattempt fails, thepropertywill be used to check if thetargethas 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 givenobjectto a boolean value, applying the following rules:- if the
objectisnullthe returned value isfalse - if the
objectis aNumberthe method will returnfalseonly if the number's value is 0 - if the
Stringrepresentation of theobjectis equal irrespective of its casing to "true", the method will returntrue - if the
objectis aCollectionor aMap, the method will returntrueonly if the collection / map is not empty - if the object is an array, the method will return
trueonly if the array is not empty
- Parameters:
object- the target object- Returns:
- the boolean representation of the
objectaccording to the conversion rules
- if the
-
toNumber
public static java.lang.Number toNumber(java.lang.Object object)
Deprecated.Coerces the passedobjectto a numeric value. If the passed value is aStringthe 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 passedobjectto aString. The following rules apply:- if the
objectisnullan empty string will be returned - if the
objectis an instance of aStringthe object itself will be returned - if the object is a primitive (see
isPrimitive(Object)), itsStringrepresentation will be returned - if the object is an
Enumits name will be returned (seeEnum.name()) - otherwise an attempt to convert the object to a
Collectionwill 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 passedobjectto a collection, according to the following rules:- if the
objectisnullan empty collection will be returned - if the
objectis an array a list transformation of the array will be returned - if the
objectis aCollectionthe object itself will be returned - if the
objectis an instance of aMapthe map's key set will be returned (seeMap.keySet()) - if the
objectis an instance of anEnumerationa list transformation will be returned - if the
objectis an instance of anIteratororIterablethe result offromIterator(Iterator)will be returned - if the
objectis an instance of aStringorNumberaCollectioncontaining 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 passedcollectionto a comma separated valuesStringrepresentation.- Parameters:
collection- the collection to be converted to CSV- Returns:
- the CSV; if the
collectionis 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 theindexposition.- Parameters:
object- the indexable objectindex- the index- Returns:
- the value stored at the
indexornull
-
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
nullif 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 bymethodNameand 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
nullif 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.Returnstrueif the method is not one of theObject's class declared methods, with the exception ofObject.toString().- Parameters:
method- the method to check- Returns:
trueif the method is not one of theObject's class declared methods, with the exception ofObject.toString(),falseotherwise
-
-