Class IntrospectingUnmarshaller
java.lang.Object
ch.tocco.nice2.model.base.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
-
Constructor Summary
ConstructorDescriptionIntrospectingUnmarshaller
(String rootElement, Object root) Initialize the unmarshaller expecting the specified root element and operating on the specified root object. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addTypeHandler
(Class<?> type, TypeHandler handler) void
addValidator
(String name, Validator validator) protected String
attributeKey
(String attributeName) void
conclude()
Conclude one resource.void
Set an element's text content.void
End an element.protected UnmarshalException
protected UnmarshalException
getRoot()
Get the current root object.protected void
initLevel
(ch.tocco.nice2.model.base.unmarshal.Level level) Builds and caches the event mappings based on the method annotations.protected InvalidMappingException
invalidMapping
(String msg) protected InvalidMappingException
invalidMapping
(String msg, Throwable cause) protected Object
invokeMethod
(Object target, Method method, Object[] args) protected ch.tocco.nice2.model.base.unmarshal.Level
peek()
protected ch.tocco.nice2.model.base.unmarshal.Level
pop()
protected ch.tocco.nice2.model.base.unmarshal.Level
void
removeTypeHandler
(Class<?> type) void
removeValidator
(String name) void
reset()
Reset the unmarshaller.void
setIgnoreUnhandledAttributes
(boolean ignoreUnhandledAttributes) void
setLocation
(Location location) Set the current location.void
Set the current root object.void
startElement
(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:Unmarshaller
Set 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:
setLocation
in 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:
startElement
in 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:Unmarshaller
End an element.- Specified by:
endElement
in interfaceUnmarshaller
- Throws:
UnmarshalException
- If an error occurs.
-
content
Description copied from interface:Unmarshaller
Set an element's text content. This may be called only once per element. Content and sub hierarchies may not be combined.- Specified by:
content
in interfaceUnmarshaller
- Parameters:
str
- The text content.- Throws:
UnmarshalException
- If an error occurs.
-
reset
public void reset()Description copied from interface:Unmarshaller
Reset the unmarshaller. This should be called on the start of each document.- Specified by:
reset
in interfaceUnmarshaller
-
conclude
Description copied from interface:Unmarshaller
Conclude one resource. This should be called at the end of each document.- Specified by:
conclude
in 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.unmarshal.Level peek() -
pop
protected ch.tocco.nice2.model.base.unmarshal.Level pop() -
initLevel
protected void initLevel(ch.tocco.nice2.model.base.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
-