Class SimplifierAccessor<T>
- All Implemented Interfaces:
ObjectAccessor
- Direct Known Subclasses:
ClassSimplifier,DomElementSimplifier,FileSimplifier,InetAddressSimplifier,ModuleSimplifier,ObjectNameSimplifier,PackageSimplifier,UrlSimplifier
Base class for all simplifiers. A simplifier is a special ObjectAccessor which
condenses full blown Java beans (like File) to a more compact representation.
Simplifiers cannot be used to set values and are only used for downstream serialization.
Simplifiers work similarly to BeanAccessor, but instead
if extracting all properties for all public getters, they delegate to type-specific
attribute extractors, which are used to create a JSONObject with
explicitly configured attributes (not necessarily related to getters).
Simplifier are registered by listing the classes in a META-INF/simplifiers plain text file and
then picked up during initialization. The default prepackaged simplifiers are taken from
META-INF/simplifiers-default.
- Since:
- Jul 27, 2009
- Author:
- roland
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedSimplifierAccessor(Class<T> pType) Super constructor taking the value type as argument -
Method Summary
Modifier and TypeMethodDescriptionprotected final voidaddExtractor(String pName, AttributeExtractor<T> pExtractor) Add a single extractor - to be called by implementing class in the constructorfinal booleanNo setting for simplifying accessorsextractObject(ObjectToJsonConverter pConverter, Object pValue, Deque<String> pPathParts, boolean pJsonify) Extract an object from givenpValueofthe supported type.Class<?>getType()Gets a class of supported objects.final ObjectAlways throwsIllegalArgumentExceptionsince a simplifier cannot be used to write values to objects.final booleanSome accessors may support dedicated conversion to String.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
-
Constructor Details
-
SimplifierAccessor
Super constructor taking the value type as argument- Parameters:
pType- the type handled by thisSimplifierAccessor
-
-
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.
-
supportsStringConversion
public final boolean supportsStringConversion()Description copied from interface:ObjectAccessorSome accessors may support dedicated conversion to String. By default, generic extraction of the value from given object should be used, but in some cases (like explicit conversion to String forMapkeys), some accessors can be used to get a String value.- Specified by:
supportsStringConversionin interfaceObjectAccessor- Returns:
-
canSetValue
public final boolean canSetValue()No setting for simplifying accessors- Specified by:
canSetValuein interfaceObjectAccessor- Returns:
- always
false
-
setObjectValue
public final Object setObjectValue(Converter<String> pConverter, Object pObject, String pAttribute, Object pValue) throws IllegalAccessException, InvocationTargetException Always throwsIllegalArgumentExceptionsince a simplifier cannot be used to write values to objects.- 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:
- the old value of the changed attribute
- Throws:
IllegalAccessException- if the attribute to set to is not accessibleInvocationTargetException- reflection error
-
addExtractor
Add a single extractor - to be called by implementing class in the constructor- Parameters:
pName- name of the extractor - it'll match the attribute name of the constructedJSONObjectfor the class being simplified.pExtractor- the extractor itself
-