org.jasig.services.persondir.support.xml
Class CachingJaxbLoaderImpl<T>

java.lang.Object
  extended by org.jasig.services.persondir.support.xml.CachingJaxbLoaderImpl<T>
All Implemented Interfaces:
CachingJaxbLoader<T>

public class CachingJaxbLoaderImpl<T>
extends Object
implements CachingJaxbLoader<T>

Base logic for loading unmarshalling an XML document via JAXB and only reloading the cached object model when needed. The class attempts to monitor the lastModified date of the Resource to determine when to reload. If that fails the resource is reloaded periodically as specified by the setNoLastModifiedReloadPeriod(long) property. The class determines the return type and the base package to use for the JAXBContext.newInstance(String) call via the loadedType parameter provided to the constructor.

Version:
$Revision$
Author:
Eric Dalquist

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.jasig.services.persondir.support.xml.CachingJaxbLoader
CachingJaxbLoader.UnmarshallingCallback<T>
 
Field Summary
protected  long lastModifiedTime
           
protected  Class<T> loadedType
           
protected  org.springframework.core.io.Resource mappedXmlResource
           
protected  long noLastModifiedReloadPeriod
           
protected  T unmarshalledObject
           
 
Constructor Summary
CachingJaxbLoaderImpl(Class<T> loadedType)
           
 
Method Summary
protected  JAXBContext getJAXBContext()
           
protected  Long getLastModified()
           
 org.springframework.core.io.Resource getMappedXmlResource()
           
 long getNoLastModifiedReloadPeriod()
           
 T getUnmarshalledObject()
          Loads and unmarshalls the XML as needed, returning the unmarshalled object
 T getUnmarshalledObject(CachingJaxbLoader.UnmarshallingCallback<T> callback)
           
protected  Unmarshaller getUnmarshaller(JAXBContext jaxbContext)
           
protected  InputStream getXmlInputStream()
           
protected  boolean isCacheValid(Long lastModified)
          Determines if the cached unmarshalled object is still valid
 void setMappedXmlResource(org.springframework.core.io.Resource mappedXmlResource)
          The XML resource to load.
 void setNoLastModifiedReloadPeriod(long noLastModifiedReloadPeriod)
          Period between reloads if last-modified of the Resource cannot be determined
protected  T unmarshal(InputStream xmlInputStream, Unmarshaller unmarshaller)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

loadedType

protected final Class<T> loadedType

noLastModifiedReloadPeriod

protected long noLastModifiedReloadPeriod

mappedXmlResource

protected org.springframework.core.io.Resource mappedXmlResource

unmarshalledObject

protected T unmarshalledObject

lastModifiedTime

protected long lastModifiedTime
Constructor Detail

CachingJaxbLoaderImpl

public CachingJaxbLoaderImpl(Class<T> loadedType)
Method Detail

getNoLastModifiedReloadPeriod

public long getNoLastModifiedReloadPeriod()

setNoLastModifiedReloadPeriod

public void setNoLastModifiedReloadPeriod(long noLastModifiedReloadPeriod)
Period between reloads if last-modified of the Resource cannot be determined


getMappedXmlResource

public org.springframework.core.io.Resource getMappedXmlResource()

setMappedXmlResource

public void setMappedXmlResource(org.springframework.core.io.Resource mappedXmlResource)
The XML resource to load.


getUnmarshalledObject

public T getUnmarshalledObject()
Description copied from interface: CachingJaxbLoader
Loads and unmarshalls the XML as needed, returning the unmarshalled object

Specified by:
getUnmarshalledObject in interface CachingJaxbLoader<T>

getUnmarshalledObject

public T getUnmarshalledObject(CachingJaxbLoader.UnmarshallingCallback<T> callback)
Specified by:
getUnmarshalledObject in interface CachingJaxbLoader<T>
Parameters:
callback - Callback that will be executed after the object is unmarshalled (if it needs to be) but before it is returned
See Also:
CachingJaxbLoader.getUnmarshalledObject()

getLastModified

protected Long getLastModified()
Returns:
The last modified date for the XML file, null if it cannot be determined

isCacheValid

protected boolean isCacheValid(Long lastModified)
Determines if the cached unmarshalled object is still valid

Parameters:
lastModified - last modified timestamp of the resource, null if not known.
Returns:
true if the cached object should be used

getXmlInputStream

protected InputStream getXmlInputStream()
Returns:
The InputStream to read the XML file from

getJAXBContext

protected JAXBContext getJAXBContext()
Returns:
The JAXB context to parse the XML resource with

getUnmarshaller

protected Unmarshaller getUnmarshaller(JAXBContext jaxbContext)
Parameters:
jaxbContext - The context to get an unmarshaller for
Returns:
An unmarshaller to use to generate object from the XML

unmarshal

protected T unmarshal(InputStream xmlInputStream,
                      Unmarshaller unmarshaller)
Parameters:
xmlInputStream - InputStream to read the XML from
unmarshaller - Unmarshaller to generate the object from the XML with
Returns:
An unmarshalled object model of the XML


Copyright © 2012 Jasig. All Rights Reserved.