Enum JaxbContextLoader
- java.lang.Object
-
- java.lang.Enum<JaxbContextLoader>
-
- com.prowidesoftware.swift.model.mx.JaxbContextLoader
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Comparable<JaxbContextLoader>
public enum JaxbContextLoader extends java.lang.Enum<JaxbContextLoader>
Singleton to parameterize theJaxbContextCache
used when marshalling or unmarshalling MX messages.This class is just a holder for the currently set cache. It is invoked in the static parse and write calls of the MX message model classes.
By default the loader will use no cache at all, creating new contexts for each parse or write call. Jaxb marshalling and unmarshalling is known to be a resource intensive task, so if you need to parse large burst of messages it is highly recommended that you set a proper cache here.
A basic cache implementation is provided in the
JaxbContextCacheImpl
class. This implementation uses a simple static Map with no eviction. It is aimed to provide something out-ot-the-box without adding additional third party libraries. You can easily inject your own cache implementation based on Guava, Ecache, Caffeine or any other cache implementation of choice. See some code references in theJaxbContextCache
interface.- Since:
- 9.0
-
-
Enum Constant Summary
Enum Constants Enum Constant Description INSTANCE
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description jakarta.xml.bind.JAXBContext
get(AbstractMX mx)
Gets a context from the static cache.jakarta.xml.bind.JAXBContext
get(java.lang.Class messageClass, java.lang.Class<?>[] classes)
Gets a context from the static cache.JaxbContextCache
getCacheImpl()
Currently set cache implementationvoid
setCacheImpl(JaxbContextCache cacheImpl)
Sets a new cache implementationvoid
setNoCache()
Sets the current cache implementation to null, meaning for all subsequent calls new context will always be created without any caching.static JaxbContextLoader
valueOf(java.lang.String name)
Returns the enum constant of this type with the specified name.static JaxbContextLoader[]
values()
Returns an array containing the constants of this enum type, in the order they are declared.
-
-
-
Enum Constant Detail
-
INSTANCE
public static final JaxbContextLoader INSTANCE
-
-
Method Detail
-
values
public static JaxbContextLoader[] values()
Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:for (JaxbContextLoader c : JaxbContextLoader.values()) System.out.println(c);
- Returns:
- an array containing the constants of this enum type, in the order they are declared
-
valueOf
public static JaxbContextLoader valueOf(java.lang.String name)
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)- Parameters:
name
- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
java.lang.IllegalArgumentException
- if this enum type has no constant with the specified namejava.lang.NullPointerException
- if the argument is null
-
get
public jakarta.xml.bind.JAXBContext get(AbstractMX mx) throws jakarta.xml.bind.JAXBException, java.util.concurrent.ExecutionException
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 and stored in the cache.- Parameters:
mx
- an MX message instance- Returns:
- the cached or created context for the specific message type
- Throws:
jakarta.xml.bind.JAXBException
java.util.concurrent.ExecutionException
-
get
public jakarta.xml.bind.JAXBContext get(java.lang.Class messageClass, java.lang.Class<?>[] classes) throws jakarta.xml.bind.JAXBException, java.util.concurrent.ExecutionException
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.- Parameters:
messageClass
- class of the message to be read or writtenclasses
- 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
java.util.concurrent.ExecutionException
-
getCacheImpl
public JaxbContextCache getCacheImpl()
Currently set cache implementation- Returns:
- current cache if none was set
-
setCacheImpl
public void setCacheImpl(JaxbContextCache cacheImpl)
Sets a new cache implementation- Parameters:
cacheImpl
- cache implementation to set
-
setNoCache
public void setNoCache()
Sets the current cache implementation to null, meaning for all subsequent calls new context will always be created without any caching. This is the default loader state.
-
-