org.easetech.easytest.io
Class ResourceLoaderStrategy

java.lang.Object
  extended by org.easetech.easytest.io.ResourceLoaderStrategy
All Implemented Interfaces:
ResourceLoader

public class ResourceLoaderStrategy
extends Object
implements ResourceLoader

Implementation of the ResourceLoader that defines a strategy to load different types of resources based on user provided values. It loads three different types of resources :

  • ClasspathResource - Resource representing the Classpath based resources(prefixed with classpath:)
  • FileSystemResource - Resource based on FileSystem (for eg. in your C: drive)
  • UrlResource - Resource based on URL (http for eg)

    Author:
    Anuj Kumar

    Field Summary
    protected static org.slf4j.Logger LOG
              An instance of logger associated with the test framework.
     
    Fields inherited from interface org.easetech.easytest.io.ResourceLoader
    CLASSPATH_PREFIX, FILE_PREFIX, URL_PREFIX
     
    Constructor Summary
    ResourceLoaderStrategy()
              Construct a new ResourceLoaderStrategy
    ResourceLoaderStrategy(Class classObj)
              Construct a new ResourceLoaderStrategy
    ResourceLoaderStrategy(ClassLoader classLoader)
              Construct a new ResourceLoaderStrategy
    ResourceLoaderStrategy(ClassLoader classLoader, Class classObj)
              Construct a new ResourceLoaderStrategy
     
    Method Summary
     ClassLoader getClassLoader()
              Get the associated ClassLoader
     Class<?> getClassObj()
               
     Resource getResource(String location)
              Get the resource based on the location.
     
    Methods inherited from class java.lang.Object
    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
     

    Field Detail

    LOG

    protected static final org.slf4j.Logger LOG
    An instance of logger associated with the test framework.

    Constructor Detail

    ResourceLoaderStrategy

    public ResourceLoaderStrategy()
    Construct a new ResourceLoaderStrategy


    ResourceLoaderStrategy

    public ResourceLoaderStrategy(Class classObj)
    Construct a new ResourceLoaderStrategy

    Parameters:
    classObj - the class object

    ResourceLoaderStrategy

    public ResourceLoaderStrategy(ClassLoader classLoader)
    Construct a new ResourceLoaderStrategy

    Parameters:
    classLoader - the class loader

    ResourceLoaderStrategy

    public ResourceLoaderStrategy(ClassLoader classLoader,
                                  Class classObj)
    Construct a new ResourceLoaderStrategy

    Parameters:
    classLoader -
    classObj -
    Method Detail

    getResource

    public Resource getResource(String location)
    Get the resource based on the location. The strategy works as follows:
  • The method first looks whether the resource path has a classpath: prefix. If it finds one, it creates a ClasspathResource instance based on the provided location.
  • If it doesnt find one, it then tries to create a UrlResource. If the UrlResource cannot be created due to MalformedURLException then we return a FileSystemResource instance and pray to God that it works :)

    Specified by:
    getResource in interface ResourceLoader
    Parameters:
    location - the location of the resource
    Returns:
    Resource instance.

    getClassLoader

    public ClassLoader getClassLoader()
    Get the associated ClassLoader

    Specified by:
    getClassLoader in interface ResourceLoader
    Returns:
    the class loader

    getClassObj

    public Class<?> getClassObj()
    Returns:
    the classObj


    Copyright © 2013. All Rights Reserved.