Class JaxbContextCacheImpl

  • All Implemented Interfaces:
    JaxbContextCache

    public class JaxbContextCacheImpl
    extends java.lang.Object
    implements JaxbContextCache
    Simple cache based on ConcurrentHashMap without eviction. This implementation is aimed to avoid additional third party dependencies. For a more robust solution You can easily implement your own cache with Guava, Ecache, Caffeine or any other cache library. See some code references in the JaxbContextCache interface.
    Since:
    9.0
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void clear()
      Drops all cached contexts
      jakarta.xml.bind.JAXBContext clear​(java.lang.Class clazz)
      Drops the cached context for the specific MX implementation class
      jakarta.xml.bind.JAXBContext get​(java.lang.Class messageClass, java.lang.Class<?>[] classes)
      Gets a context from the static cache.
      int size()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • JaxbContextCacheImpl

        public JaxbContextCacheImpl()
    • Method Detail

      • get

        public jakarta.xml.bind.JAXBContext get​(java.lang.Class messageClass,
                                                java.lang.Class<?>[] classes)
                                         throws jakarta.xml.bind.JAXBException
        Gets a context from the static cache. If the context for the specific message type is not present, a new context is initialized with the given classes or messageClass and stored in the cache.
        Specified by:
        get in interface JaxbContextCache
        Parameters:
        messageClass - class of the message to be read or written
        classes - comprehensive list of classes for the context, null or empty to create a context with the messageClass
        Returns:
        the cached or created context for the specific message type
        Throws:
        jakarta.xml.bind.JAXBException
      • clear

        public void clear()
        Drops all cached contexts
      • clear

        public jakarta.xml.bind.JAXBContext clear​(java.lang.Class clazz)
        Drops the cached context for the specific MX implementation class
        Returns:
        the remove context, if it was present, or null otherwise
      • size

        public int size()
        Returns:
        the number of cached contexts