
uk.org.retep.xmpp.jaxb.XMPPUnmarshaller Maven / Gradle / Ivy
The newest version!
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package uk.org.retep.xmpp.jaxb;
import java.util.Collection;
import net.jcip.annotations.ThreadSafe;
import uk.org.retep.util.services.Service;
import uk.org.retep.util.xml.JAXBUtil;
import uk.org.retep.xmpp.annotation.XMPPProtocol;
/**
* A singleton instance of {@link JAXBUtil} which contains the standard XMPP
* packages.
*
*
* When unmarshalling xmpp messages, this instance should be used as it would be
* unknown when a packet is received to what packages should be used.
*
*
*
* When additional non-standard xmpp protocols are in use then they should be
* included in this instance prior to use.
*
*
*
* When marshalling xmpp messages then XMPPMarshaller should be used as it
* will manage the creation of the correct contexts ensuring that no additional
* cruft is included in the resultant xml.
*
*
* @author peter
*/
@ThreadSafe
public class XMPPUnmarshaller
extends JAXBUtil
{
/**
* The singleton instance
* @return singleton
*/
public static XMPPUnmarshaller getInstance()
{
return Holder.getInstance();
}
private XMPPUnmarshaller()
{
// Read the deployed packages and add them all to this instance.
final Collection packages = Service.providerClassNames(
XMPPProtocol.class.getName(),
Thread.currentThread().getContextClassLoader() );
for( String pkg : packages )
{
addPackage( pkg );
}
}
/**
* Holder pattern to lazy initialise the singleton as instantiation is
* pretty expensive due to the number of packages involved.
*/
private static class Holder
{
private static final XMPPUnmarshaller instance = new XMPPUnmarshaller();
private Holder()
{
}
static XMPPUnmarshaller getInstance()
{
return instance;
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy