Class IntrospectingUnmarshaller
java.lang.Object
ch.tocco.nice2.model.base.api.unmarshal.IntrospectingUnmarshaller
- All Implemented Interfaces:
Unmarshaller
The default unmarshaller. It maps the unmarshalling events to method calls based on
the annotations in the
annotations package.
How to use: https://wiki.tocco.ch/wiki/index.php/Nice2-xml-reader
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionIntrospectingUnmarshaller(String rootElement, Object root) Initialize the unmarshaller expecting the specified root element and operating on the specified root object. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddTypeHandler(Class<?> type, TypeHandler handler) voidaddValidator(String name, Validator validator) protected StringattributeKey(String attributeName) voidconclude()Conclude one resource.voidSet an element's text content.voidEnd an element.protected UnmarshalExceptionprotected UnmarshalExceptiongetRoot()Get the current root object.protected voidinitLevel(ch.tocco.nice2.model.base.api.unmarshal.Level level) Builds and caches the event mappings based on the method annotations.protected InvalidMappingExceptioninvalidMapping(String msg) protected InvalidMappingExceptioninvalidMapping(String msg, Throwable cause) protected ObjectinvokeMethod(Object target, Method method, Object[] args) protected ch.tocco.nice2.model.base.api.unmarshal.Levelpeek()protected ch.tocco.nice2.model.base.api.unmarshal.Levelpop()protected ch.tocco.nice2.model.base.api.unmarshal.LevelvoidremoveTypeHandler(Class<?> type) voidremoveValidator(String name) voidreset()Reset the unmarshaller.voidsetIgnoreUnhandledAttributes(boolean ignoreUnhandledAttributes) voidsetLocation(Location location) Set the current location.voidSet the current root object.voidstartElement(String element, Map<String, String> attributes) This method fires the event receiving method which is either annotated with the @Element("tag-name") or with @AnyElement as fallback.
-
Constructor Details
-
IntrospectingUnmarshaller
Initialize the unmarshaller expecting the specified root element and operating on the specified root object.- Parameters:
rootElement- The root element's name.root- The root object.
-
-
Method Details
-
setLocation
Description copied from interface:UnmarshallerSet the current location. This is used for error messages. Implementations should always make a copy of this location to allow event emitters, to put a "live" version here, i.e. one that changes during parsing always reflecting the current location.- Specified by:
setLocationin interfaceUnmarshaller- Parameters:
location- The location.
-
setIgnoreUnhandledAttributes
public void setIgnoreUnhandledAttributes(boolean ignoreUnhandledAttributes) -
startElement
This method fires the event receiving method which is either annotated with the @Element("tag-name") or with @AnyElement as fallback. It passes on all the annotated attributes to method params, plus the content, if defined.If there is a param for the content then the calling of the method is DELAYED and done in
endElement()(cause the content is not available yet).- Specified by:
startElementin interfaceUnmarshaller- Parameters:
element- The element's name.attributes- A map of attributes as read from the tag.- Throws:
UnmarshalException- If an error occurs.
-
endElement
Description copied from interface:UnmarshallerEnd an element.- Specified by:
endElementin interfaceUnmarshaller- Throws:
UnmarshalException- If an error occurs.
-
content
Description copied from interface:UnmarshallerSet an element's text content. This may be called only once per element. Content and sub hierarchies may not be combined.- Specified by:
contentin interfaceUnmarshaller- Parameters:
str- The text content.- Throws:
UnmarshalException- If an error occurs.
-
reset
public void reset()Description copied from interface:UnmarshallerReset the unmarshaller. This should be called on the start of each document.- Specified by:
resetin interfaceUnmarshaller
-
conclude
Description copied from interface:UnmarshallerConclude one resource. This should be called at the end of each document.- Specified by:
concludein interfaceUnmarshaller- Throws:
UnmarshalException- If an error occurs.
-
getRoot
Get the current root object.- Returns:
- The current root object.
-
setRoot
Set the current root object.- Parameters:
root- The new root object.
-
addTypeHandler
-
removeTypeHandler
-
addValidator
-
removeValidator
-
getLocation
-
push
-
peek
protected ch.tocco.nice2.model.base.api.unmarshal.Level peek() -
pop
protected ch.tocco.nice2.model.base.api.unmarshal.Level pop() -
initLevel
protected void initLevel(ch.tocco.nice2.model.base.api.unmarshal.Level level) Builds and caches the event mappings based on the method annotations. -
invokeMethod
protected Object invokeMethod(Object target, Method method, Object[] args) throws UnmarshalException - Throws:
UnmarshalException
-
attributeKey
-
error
-
error
-
invalidMapping
-
invalidMapping
-