Class MarshallerInspector
- java.lang.Object
-
- org.nuxeo.ecm.core.io.registry.reflect.MarshallerInspector
-
- All Implemented Interfaces:
Comparable<MarshallerInspector>
public class MarshallerInspector extends Object implements Comparable<MarshallerInspector>
Utility class used to instanciate marshallers. This class checks if a marshaller has annotationSetup
and inspect every attributes havingInject
annotation.To get a valid marshaller instance :
- Create an inspector for your marshaller class using constructor
MarshallerInspector(Class)
. This will checks your marshaller has annotationSetup
and inspect every attributes havingInject
annotation. - You can check it's a valid marshaller by calling @ #isValid()}
- You can check it's a
Writer
by callingisWriter()
- You can check it's a
Reader
by callingisReader()
- You can finally call
getInstance(RenderingContext)
to get a valid marshaller instance withRenderingContext
and required services injected.
This class implements
Comparable
and then handle marshaller priorities rules: look atMarshallerRegistry
javadoc to read the rules.- Since:
- 7.2
-
-
Constructor Summary
Constructors Constructor Description MarshallerInspector(Class<?> clazz)
Create an inspector for the given class.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
compareTo(MarshallerInspector inspector)
boolean
equals(Object obj)
TwoMarshallerInspector
are equals if their managed clazz are the same.Type
getGenericType()
<T> T
getInstance(RenderingContext ctx)
Create an instance of this marshaller.Instantiations
getInstantiations()
Class<?>
getMarshalledType()
Object
getNewInstance(RenderingContext ctx, boolean singleton)
Create a new instance of the marshaller.Integer
getPriority()
List<javax.ws.rs.core.MediaType>
getSupports()
int
hashCode()
void
injectCtx(Object instance, RenderingContext ctx, boolean singleton)
Inject the context.void
injectServices(Object instance)
Inject the services.boolean
isMarshaller()
boolean
isReader()
boolean
isWriter()
-
-
-
Constructor Detail
-
MarshallerInspector
public MarshallerInspector(Class<?> clazz)
Create an inspector for the given class.- Parameters:
clazz
- The class to analyse and instantiate.
-
-
Method Detail
-
getInstance
public <T> T getInstance(RenderingContext ctx)
Create an instance of this marshaller. Depending on the instantiation mode, get the current singleton instance, get a thread local one or create a new one.- Parameters:
ctx
- TheRenderingContext
to inject, if null create an empty context.- Returns:
- An instance of this class.
- Since:
- 7.2
-
getNewInstance
public Object getNewInstance(RenderingContext ctx, boolean singleton)
Create a new instance of the marshaller. It injects the required services if the marshaller is not a singleton. If it's a singleton, it prepares the context variables to handle thread localized context. Then it injects the given ctx.- Parameters:
ctx
- TheRenderingContext
to inject.- Returns:
- An instance of the marshaller.
- Since:
- 7.2
-
injectCtx
public void injectCtx(Object instance, RenderingContext ctx, boolean singleton)
Inject the context.
-
injectServices
public void injectServices(Object instance)
Inject the services.
-
getInstantiations
public Instantiations getInstantiations()
-
getPriority
public Integer getPriority()
-
getSupports
public List<javax.ws.rs.core.MediaType> getSupports()
-
getMarshalledType
public Class<?> getMarshalledType()
-
getGenericType
public Type getGenericType()
-
isMarshaller
public boolean isMarshaller()
-
isWriter
public boolean isWriter()
-
isReader
public boolean isReader()
-
compareTo
public int compareTo(MarshallerInspector inspector)
- Specified by:
compareTo
in interfaceComparable<MarshallerInspector>
-
equals
public boolean equals(Object obj)
TwoMarshallerInspector
are equals if their managed clazz are the same.
-
-