Package jadex.commons

Class AbstractModelLoader

    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected java.lang.String[] extensions
      The supported file extensions (if any).
      protected LRU<Tuple,​ICacheableModel> modelcache
      The model cache (filename/imports -> loaded model).
      protected java.util.Map<java.lang.String,​ICacheableModel> registered
      The registered models (filename -> loaded model).
    • Constructor Summary

      Constructors 
      Constructor Description
      AbstractModelLoader​(java.lang.String[] extensions)
      Create a model loader.
      AbstractModelLoader​(java.lang.String[] extensions, int cachesize)
      Create a model loader.
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      void clearModelCache()
      Clears the model cache.
      void deregisterModel​(java.lang.String key)
      Deregister a model.
      protected abstract ICacheableModel doLoadModel​(java.lang.String name, java.lang.Object pojo, java.lang.String[] imports, ResourceInfo info, java.lang.ClassLoader classloader, java.lang.Object context)
      Load a model.
      ICacheableModel getCachedModel​(java.lang.String name, java.lang.String extension, java.lang.String[] imports, java.lang.Object clkey)
      Get a cached model.
      protected ResourceInfo getResourceInfo​(java.lang.String name, java.lang.String[] imports, java.lang.ClassLoader classloader)
      Find the file for a given name using any supported extension.
      protected ResourceInfo getResourceInfo​(java.lang.String name, java.lang.String extension, java.lang.String[] imports, java.lang.ClassLoader classloader)
      Find the file for a given name.
      ResourceInfo getResourceInfo0​(java.lang.String name, java.lang.String[] imports, java.lang.ClassLoader classloader)
      Find the file for a given name using any supported extension.
      ICacheableModel loadModel​(java.lang.String name, java.lang.Object pojo, java.lang.String[] imports, java.lang.Object clkey, java.lang.ClassLoader classloader, java.lang.Object context)
      Load a model.
      ICacheableModel loadModel​(java.lang.String name, java.lang.Object pojo, java.lang.String extension, java.lang.String[] imports, java.lang.Object clkey, java.lang.ClassLoader classloader, java.lang.Object context)
      Load a model with a required extension.
      void registerModel​(java.lang.String key, ICacheableModel model)
      Register a model.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • extensions

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

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

        protected java.util.Map<java.lang.String,​ICacheableModel> registered
        The registered models (filename -> loaded model).
    • Constructor Detail

      • AbstractModelLoader

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

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

      • doLoadModel

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

        protected ResourceInfo getResourceInfo​(java.lang.String name,
                                               java.lang.String[] imports,
                                               java.lang.ClassLoader classloader)
                                        throws java.lang.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:
        java.lang.Exception - when the file could not be found.
      • getResourceInfo0

        public ResourceInfo getResourceInfo0​(java.lang.String name,
                                             java.lang.String[] imports,
                                             java.lang.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 ResourceInfo getResourceInfo​(java.lang.String name,
                                               java.lang.String extension,
                                               java.lang.String[] imports,
                                               java.lang.ClassLoader classloader)
                                        throws java.lang.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:
        java.lang.Exception
      • getCachedModel

        public ICacheableModel getCachedModel​(java.lang.String name,
                                              java.lang.String extension,
                                              java.lang.String[] imports,
                                              java.lang.Object clkey)
                                       throws java.lang.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:
        java.lang.Exception
      • loadModel

        public ICacheableModel loadModel​(java.lang.String name,
                                         java.lang.Object pojo,
                                         java.lang.String[] imports,
                                         java.lang.Object clkey,
                                         java.lang.ClassLoader classloader,
                                         java.lang.Object context)
                                  throws java.lang.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:
        java.lang.Exception
      • loadModel

        public ICacheableModel loadModel​(java.lang.String name,
                                         java.lang.Object pojo,
                                         java.lang.String extension,
                                         java.lang.String[] imports,
                                         java.lang.Object clkey,
                                         java.lang.ClassLoader classloader,
                                         java.lang.Object context)
                                  throws java.lang.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:
        java.lang.Exception
      • registerModel

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

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

        public void clearModelCache()
        Clears the model cache.