Class IntrospectingUnmarshaller

java.lang.Object
ch.tocco.nice2.model.base.unmarshal.IntrospectingUnmarshaller
All Implemented Interfaces:
Unmarshaller

public class IntrospectingUnmarshaller extends Object implements 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

  • Constructor Details

    • IntrospectingUnmarshaller

      public IntrospectingUnmarshaller(String rootElement, Object root)
      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

      public void setLocation(Location location)
      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 interface Unmarshaller
      Parameters:
      location - The location.
    • setIgnoreUnhandledAttributes

      public void setIgnoreUnhandledAttributes(boolean ignoreUnhandledAttributes)
    • startElement

      public void startElement(String element, Map<String,String> attributes) throws UnmarshalException
      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 interface Unmarshaller
      Parameters:
      element - The element's name.
      attributes - A map of attributes as read from the tag.
      Throws:
      UnmarshalException - If an error occurs.
    • endElement

      public void endElement() throws UnmarshalException
      Description copied from interface: Unmarshaller
      End an element.
      Specified by:
      endElement in interface Unmarshaller
      Throws:
      UnmarshalException - If an error occurs.
    • content

      public void content(String str) throws UnmarshalException
      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 interface Unmarshaller
      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 interface Unmarshaller
    • conclude

      public void conclude() throws UnmarshalException
      Description copied from interface: Unmarshaller
      Conclude one resource. This should be called at the end of each document.
      Specified by:
      conclude in interface Unmarshaller
      Throws:
      UnmarshalException - If an error occurs.
    • getRoot

      public Object getRoot()
      Get the current root object.
      Returns:
      The current root object.
    • setRoot

      public void setRoot(Object root)
      Set the current root object.
      Parameters:
      root - The new root object.
    • addTypeHandler

      public void addTypeHandler(Class<?> type, TypeHandler handler)
    • removeTypeHandler

      public void removeTypeHandler(Class<?> type)
    • addValidator

      public void addValidator(String name, Validator validator)
    • removeValidator

      public void removeValidator(String name)
    • getLocation

      public Location getLocation()
    • push

      protected ch.tocco.nice2.model.base.unmarshal.Level push(String element, Object o)
    • 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

      protected String attributeKey(String attributeName)
    • error

      protected UnmarshalException error(String msg)
    • error

      protected UnmarshalException error(String msg, Throwable cause)
    • invalidMapping

      protected InvalidMappingException invalidMapping(String msg)
    • invalidMapping

      protected InvalidMappingException invalidMapping(String msg, Throwable cause)