Class AbstractModelLoader

java.lang.Object
jadex.model.impl.AbstractModelLoader

public abstract class AbstractModelLoader extends Object
Loader for managing models, loaded from disc and kept in cache.
  • Field Details

    • extensions

      protected String[] extensions
      The supported file extensions (if any).
    • modelcache

      protected jadex.collection.LRU<jadex.common.Tuple,ICacheableModel> modelcache
      The model cache (filename/imports -> loaded model).
    • registered

      protected Map<String,ICacheableModel> registered
      The registered models (filename -> loaded model).
    • loaders

      public static final Map<Class<? extends jadex.core.impl.Component>,AbstractModelLoader> loaders
  • Constructor Details

    • AbstractModelLoader

      public AbstractModelLoader(String[] extensions)
      Create a model loader.
      Parameters:
      extensions - The supported file extensions by order of importance.
    • AbstractModelLoader

      public AbstractModelLoader(String[] extensions, int cachesize)
      Create a model loader.
      Parameters:
      extensions - The supported file extensions by order of importance.
  • Method Details

    • doLoadModel

      protected abstract ICacheableModel doLoadModel(String name, Object pojo, String[] imports, ClassLoader classloader, jadex.common.ResourceInfo info) throws Exception
      Load a model.
      Parameters:
      name - The original name (i.e. not filename).
      info - The resource info.
      Throws:
      Exception
    • getResourceInfo

      protected jadex.common.ResourceInfo getResourceInfo(String name, String[] imports, ClassLoader classloader) throws Exception
      Find the file for a given name using any supported extension.
      Parameters:
      name - The filename or logical name (resolved via imports and extensions).
      imports - The imports, if any.
      Returns:
      The resource info identifying the file.
      Throws:
      Exception - when the file could not be found.
    • getResourceInfo0

      public jadex.common.ResourceInfo getResourceInfo0(String name, String[] imports, ClassLoader classloader)
      Find the file for a given name using any supported extension.
      Parameters:
      name - The filename or logical name (resolved via imports and extensions).
      imports - The imports, if any.
      Returns:
      The resource info identifying the file or null.
    • getResourceInfo

      protected jadex.common.ResourceInfo getResourceInfo(String name, String extension, String[] imports, ClassLoader classloader) throws Exception
      Find the file for a given name.
      Parameters:
      name - The filename or logical name (resolved via imports and extension).
      extension - The required extension.
      imports - The imports, if any.
      Returns:
      The resource info identifying the file.
      Throws:
      Exception
    • getCachedModel

      public ICacheableModel getCachedModel(String name, String extension, String[] imports, Object clkey) throws Exception
      Get a cached model.
      Parameters:
      name - The name of the model (file name or logical name).
      extension - The specific extension to look for.
      imports - The imports to use when resolving logical names.
      clkey - The class loader key to allow caching by e.g. RID.
      Returns:
      null, when model not found or not yet loaded.
      Throws:
      Exception
    • loadModel

      public ICacheableModel loadModel(String name, Object pojo, String[] imports, Object clkey, ClassLoader classloader, Object context) throws Exception
      Load a model.
      Parameters:
      name - The name of the model (file name or logical name).
      imports - The imports to use when resolving logical names.
      clkey - The class loader key to allow caching by e.g. RID.
      Throws:
      Exception
    • loadModel

      public ICacheableModel loadModel(String name, Object pojo, String extension, String[] imports, Object clkey, ClassLoader classloader) throws Exception
      Load a model with a required extension.
      Parameters:
      name - The name of the model (file name or logical name).
      extension - The specific extension to look for.
      imports - The imports to use when resolving logical names.
      clkey - The class loader key to allow caching by e.g. RID.
      Throws:
      Exception
    • updateCachedModel

      public void updateCachedModel(Runnable update)
    • registerModel

      public void registerModel(String key, ICacheableModel model)
      Register a model.
    • deregisterModel

      public void deregisterModel(String key)
      Deregister a model.
    • clearModelCache

      public void clearModelCache()
      Clears the model cache.
    • getLoader

      public static AbstractModelLoader getLoader(Class<? extends jadex.core.impl.Component> type)
    • addLoader

      public static void addLoader(Class<? extends jadex.core.impl.Component> type, AbstractModelLoader loader)