|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectno.sesat.search.site.config.AbstractResourceLoader
public abstract class AbstractResourceLoader
Utility class to handle loading different types of resources in a background thread.
This avoids the problem of having to order loading of applications in the container because of static initialisers
using resources from the search-front-config application.
Because the loading is backgrounded it is important to wait until it is finished.
This is done by calling abut()
Example usecases:
(1)
// load custom.properties into props in skin's WEB-INF/classes/ Site site = ...; PropertiesContext context = ...; Properties props = new Properties(); PropertiesLoader loader = context.newPropertiesLoader(site.getSiteContext(), "custom.properties", props); loader.abut(); props.getProperty(...); (2)// create document from my.xml located in skin's WEB-INF/classes/ Site site = ...; DocumentContext context = ...; final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setValidating(false); final DocumentBuilder builder = factory.newDocumentBuilder(); loader = context.newDocumentLoader(site.getSiteContext(), "my.xml", builder); loader.abut(); Document doc = loader.getDocument();(3)// read a class file from a jar file located in skin's WEB-INF/lib/ Site site = ...; BytecodeContext context = ...; BytecodeLoader loader= context.newBytecodeLoader(site.getSiteContext(),"Example.class", "Example.jar"); loader.abut() byte[] bytes = loader.getBytecode();
| Field Summary | |
|---|---|
protected DocumentBuilder |
builder
DocumentBuilder builder. |
protected Document |
document
Document. |
protected String |
jarFileName
Name of jar to load classes from |
protected Properties |
props
the properties resource holder. |
| Constructor Summary | |
|---|---|
protected |
AbstractResourceLoader(SiteContext cxt)
Creates a new instance of AbstractResourceLoader. |
| Method Summary | |
|---|---|
void |
abut()
Simple thread.join() wrapper to avoid dealing with InterruptedException. |
byte[] |
getBytecode()
Returns byte code for the class. |
protected SiteContext |
getContext()
Get the SiteContext. |
Document |
getDocument()
get the Document. |
protected abstract InputStream |
getInputStreamFor(URL resource)
|
Properties |
getProperties()
get the properties. |
protected String |
getResource()
Get the resource name/path this class is responsible for retrieving. |
protected abstract URL |
getResource(Site site)
|
void |
init(String resource,
DocumentBuilder builder)
initialise this resource loader with the resource name/path and the builder used to create the dom. |
void |
init(String resource,
Properties props)
initialise this resource loader with the resource name/path and the resource it will go into. |
void |
initBytecodeLoader(String className,
String jarFileName)
Prepares and loads byte code for a class. |
protected String |
readResourceDebug(URL url)
|
void |
run()
|
abstract boolean |
urlExists(URL url)
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected Properties props
protected DocumentBuilder builder
protected Document document
protected String jarFileName
| Constructor Detail |
|---|
protected AbstractResourceLoader(SiteContext cxt)
cxt - the context that we supply us with which site we are dealing with.| Method Detail |
|---|
public abstract boolean urlExists(URL url)
public Properties getProperties()
PropertiesLoader
getProperties in interface PropertiesLoaderpublic Document getDocument()
DocumentLoader
getDocument in interface DocumentLoaderpublic byte[] getBytecode()
BytecodeLoader
getBytecode in interface BytecodeLoader
public void init(String resource,
Properties props)
PropertiesLoader
init in interface PropertiesLoaderresource - the name/path of the resource.props - the properties that will be used to hold the individual properties.
public void init(String resource,
DocumentBuilder builder)
DocumentLoader
init in interface DocumentLoaderresource - the name/path of the resource.builder - the document that will be used to hold the xml dom.
public void initBytecodeLoader(String className,
String jarFileName)
BytecodeLoader
initBytecodeLoader in interface BytecodeLoaderclassName - the class to load byte code for.jarFileName - the jar file to look in.public void abut()
ResourceLoader
abut in interface ResourceLoaderpublic void run()
run in interface Runnableprotected abstract URL getResource(Site site)
protected abstract InputStream getInputStreamFor(URL resource)
protected SiteContext getContext()
protected String getResource()
protected String readResourceDebug(URL url)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||