Class BeanAccessor
- All Implemented Interfaces:
ObjectAccessor
ObjectAccessor for plain Java objects - "beans". We should be very careful here, because we don't
want to access "classLoader/ucp/path/0/host" attribute of Class for example...- Since:
- Apr 19, 2009
- Author:
- roland
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanWhether this accessor can be used to set a value inside (directly or nested) a value ofgiven class.extractObject(ObjectToJsonConverter pConverter, Object pValue, Deque<String> pPathParts, boolean pJsonify) Extract an object from givenpValueofthe supported type.Class<?>getType()Gets a class of supported objects.Set a bean property with the passed value - subject to conversion into the class of the setter for given attribute.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.jolokia.service.serializer.json.ObjectAccessor
extractString, supportsStringConversion
-
Constructor Details
-
BeanAccessor
public BeanAccessor()
-
-
Method Details
-
getType
Description copied from interface:ObjectAccessorGets a class of supported objects.- Specified by:
getTypein interfaceObjectAccessor- Returns:
- supported type of the objects handled by this accessor
-
extractObject
public Object extractObject(ObjectToJsonConverter pConverter, Object pValue, Deque<String> pPathParts, boolean pJsonify) throws AttributeNotFoundException Description copied from interface:ObjectAccessorExtract an object from given
pValueofthe supported type.In the simplest case without jsonification and without a property path, we extract the value itself.
pPathPartsmay be used as aDeque(a stack) of keys into the object being accessed, where the first item (Deque.pop()) is the 1st level inner object and the remainder of the stack is passed recursively when accessing composite objects. First key may be null, which means that the remaining path parts are applied to each item of the object (like elements of the array).pJsonifyflag indicates that the returned value should be converted into a JSON representation.- Specified by:
extractObjectin interfaceObjectAccessor- Parameters:
pConverter- the top-level converter that knows about otheraccessorsused for drilling into inner objects.pValue- the objects being accessedpPathParts- a path into inner object(s) to access internal structure of the object. Each accessor shouldDeque.pop()its attribute and pass the remaining stack recursively.pJsonify- whether to convert the extracted object into a JSON representation- Returns:
- the extracted object in JSON or original format
- Throws:
AttributeNotFoundException- if the inner path does not exist.
-
canSetValue
public boolean canSetValue()Description copied from interface:ObjectAccessorWhether this accessor can be used to set a value inside (directly or nested) a value ofgiven class.- Specified by:
canSetValuein interfaceObjectAccessor- Returns:
trueif this extractor can be used to set inner values.
-
setObjectValue
public Object setObjectValue(Converter<String> pConverter, Object pObject, String pAttribute, Object pValue) throws IllegalAccessException, InvocationTargetException Set a bean property with the passed value - subject to conversion into the class of the setter for given attribute.
This method, differently than
extractObject(org.jolokia.service.serializer.json.ObjectToJsonConverter, java.lang.Object, java.util.Deque<java.lang.String>, boolean), doesn't use cache and is also used (without success) for primitive types that should not be altered.- Specified by:
setObjectValuein interfaceObjectAccessor- Parameters:
pConverter-Converterused to convert the value being set to a class of the accessed attributepObject- object on which to set the valuepAttribute- attribute of the object to set. (For arrays or lists it should be an index.)pValue- the new value to set afterconversion- Returns:
- Throws:
IllegalAccessExceptionInvocationTargetException
-