Package org.opensaml.core.xml.io

# Class MarshallerFactory

java.lang.Object
org.opensaml.core.xml.io.MarshallerFactory

public class MarshallerFactory extends Object
This thread-safe factory creates `Marshaller`s that can be used to convert `XMLObject`s into W3C DOM elements. Marshallers are stored and retrieved by a `QName` key. This key is either the XML Schema Type or element QName of the XML element the XMLObject is marshalled into.

## Field Summary

Fields
Modifier and Type
Field
Description
`private final org.slf4j.Logger`
`log`
Class logger.
`private final Map<QName,Marshaller>`
`marshallers`
Map of marshallers to the elements they are for.

## Constructor Summary

Constructors
Constructor
Description
`MarshallerFactory()`
Constructor.

## Method Summary

Modifier and Type
Method
Description
`Marshaller`
`deregisterMarshaller(QName key)`
Deregisters the marshaller for the given element.
`Marshaller`
`ensureMarshaller(QName key)`
Call `getMarshaller(QName)` and raise an exception if no marshaller is registered.
`Marshaller`
`ensureMarshaller(XMLObject xmlObject)`
Call `getMarshaller(XMLObject)` and raise an exception if no marshaller is registered.
`Marshaller`
`getMarshaller(QName key)`
Gets the Marshaller for a particular element or null if no marshaller is registered for an element.
`Marshaller`
`getMarshaller(XMLObject xmlObject)`
Retrieves the marshaller for the given XMLObject.
`Map<QName,Marshaller>`
`getMarshallers()`
Gets an immutable listing of all the Marshallers currently registered.
`void`
`registerMarshaller(QName key, Marshaller marshaller)`
Registers a Marshaller with this factory.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Field Details

### log

@Nonnull private final org.slf4j.Logger log
Class logger.

### marshallers

@Nonnull private final Map<QName,Marshaller> marshallers
Map of marshallers to the elements they are for.

## Constructor Details

### MarshallerFactory

public MarshallerFactory()
Constructor.

## Method Details

### getMarshaller

@Nullable public Marshaller getMarshaller(@Nonnull QName key)
Gets the Marshaller for a particular element or null if no marshaller is registered for an element.

Parameters:
  `key` - the key the marshaller was registered under
Returns:
  the Marshaller or null

### getMarshaller

@Nullable public Marshaller getMarshaller(@Nonnull XMLObject xmlObject)
Retrieves the marshaller for the given XMLObject. The schema type, if present, is tried first as the key with the element QName used if no schema type is present or does not have a marshaller registered under it.

Parameters:
  `xmlObject` - the XMLObject to retrieve the marshaller for
Returns:
  the marshaller that can be used for the given XMLObject

### ensureMarshaller

@Nonnull public Marshaller ensureMarshaller(@Nonnull QName key)
Call `getMarshaller(QName)` and raise an exception if no marshaller is registered.

Parameters:
  `key` - type of marshaller to fetch
Returns:
  the registered marshaller
Throws:
  `XMLRuntimeException` - if no marshaller is registered
Since:
  5.0.0

### ensureMarshaller

@Nonnull public Marshaller ensureMarshaller(@Nonnull XMLObject xmlObject)
Call `getMarshaller(XMLObject)` and raise an exception if no marshaller is registered.

Parameters:
  `xmlObject` - type of marshaller to fetch
Returns:
  the registered marshaller
Throws:
  `XMLRuntimeException` - if no marshaller is registered
Since:
  5.0.0

### getMarshallers

@Nonnull @Unmodifiable @NotLive public Map<QName,Marshaller> getMarshallers()
Gets an immutable listing of all the Marshallers currently registered.

Returns:
  a listing of all the Marshallers currently registered

### registerMarshaller

public void registerMarshaller(@Nonnull QName key, @Nonnull Marshaller marshaller)
Registers a Marshaller with this factory. If a Marshaller exist for the element name given it is replaced with the given marshaller.

Parameters:
  `key` - the key the marshaller was registered under
  `marshaller` - the Marshaller

### deregisterMarshaller

@Nullable public Marshaller deregisterMarshaller(@Nonnull QName key)
Deregisters the marshaller for the given element.

Parameters:
  `key` - the key the marshaller was registered under
Returns:
  the Marshaller previously registered or null