com.dynamide.resource
Class Assembly

java.lang.Object
  extended by com.dynamide.DynamideObject
      extended by com.dynamide.resource.ContextNode
          extended by com.dynamide.resource.Pool
              extended by com.dynamide.resource.Assembly
All Implemented Interfaces:
IContext, IFileDiverListener, IGet

public class Assembly
extends Pool
implements IFileDiverListener, IContext

Each assembly turns into a cache of resources at runtime. This Assembly class extends Pool, and keeps each resource in an IContext node.

The context key is the path of the resource name of the resource, which is the name relative to the assembly root or to the resources directories inside the assembly or application. When the resource is not in cache, the context object is null, but the key is present. So hasContext() will return true, but getContext will still return null. When the resource is in cache, the IContext returned by getContext(key) will have information about the resource's contents. It will have the following attributes:

The most important is the CONTENT attribute, which is the resource's contents. The string names of these attributes are defined in this class, such as Assembly.CONTENT.

Attributes associated with this object are:

Note that you should use the symbolic name, since they may map to some other string, e.g. Assembly.BASENAME == "basename".


Field Summary
static java.lang.String ACCESSED
           
static java.lang.String ASSEMBLY
           
static java.lang.String ASSEMBLY_STANDARD_NAME
           
static java.lang.String ASSEMBLYDIR
           
static java.lang.String BASENAME
           
static java.lang.String BASENAMES
          key for the collection of basenames IContexts, which hold the list of assembly-build names that provide this basename.
static java.lang.String BINARY
           
static java.lang.String BUILD
           
static java.lang.String CACHE_REL
           
static java.lang.String CACHED
           
static java.lang.String CAT_CACHE
           
static java.lang.String CONTENT
           
static java.lang.String DEFAULT_INTERFACE_NUMBER
           
static java.lang.String FALSE
           
static java.lang.String FULLPATH
           
static java.lang.String HITS
           
static java.lang.String IMPORTS
           
static java.lang.String IN_MEMORY_RESOURCE
           
static java.lang.String INTERFACE
           
protected static boolean LOG_CACHING
           
static java.lang.String MODIFIED
           
static java.lang.String NAME
           
static java.lang.String TRUE
           
static java.lang.String WIDGETS_DIR_REL_RESOURCES
           
 
Fields inherited from class com.dynamide.resource.Pool
DEFAULT_POOL_TIMEOUT
 
Fields inherited from class com.dynamide.DynamideObject
m_id
 
Constructor Summary
Assembly(DynamideObject owner)
          Illegal to call directly - use ResourceManger.createAssembly() instead, from the Root ResourceManger.
Assembly(DynamideObject owner, java.lang.String key, java.lang.String account, java.lang.String RESOURCE_ROOT)
          Illegal to call directly - use ResourceManger.createAssembly() instead, from the Root ResourceManger.
 
Method Summary
static void accessed(IContext context)
           
static Assembly createAssembly(ResourceManager resourceManager, IContext assemblies, java.io.File assemblyDir, java.lang.String assemblyName, java.lang.String account, java.lang.String RESOURCE_ROOT, boolean isCacheOn)
           
static byte[] extractBinaryResourceContent(IContext node)
          Get the content of the resource as a byte array.
static java.lang.String extractResourceContent(IContext node)
          Get the content of the resource as a String from an IContext node.
 java.lang.String extractResourceContent(java.lang.String resourceID)
          Get the content of the resource as a String, by resourceID.
static Assembly findAssembly(IContext assemblies, java.lang.String basename, java.lang.String interfaceNumber, java.lang.String build)
          Find Assembly in "assemblies" IContext param, matching basename param, with these rules: First rule: find assembly for build number Second rule: find assembly for interface number
 Assembly findImport(java.lang.String assemblyName, java.lang.String assemblyInterfaceNumber, java.lang.String assemblyBuild)
           
 java.lang.String getAccount()
           
 IContext getApplicationResource(java.lang.String applicationName, java.lang.String resourceID)
          Each assembly has two places to look for resources: in the resources folder of the assembly in the apps/${appname}/resources folder of the assembly So resources that are not things like page1.xml or application.xml should go in one of those folders and thus begin with "resources/".
 java.lang.String getAssemblyDirectory()
          The name of the directory that the Assembly expanded to.
 java.lang.String getBuildName()
           
 java.util.List getImports()
           
 java.lang.String getImportsFullPath()
           
 java.lang.String getImportsFullPath(java.lang.String separator)
           
 IContext getImportsFullPathAsContext()
           
 java.lang.String getImportsPath()
           
 java.lang.String getInclude(java.lang.String applicationPath, java.lang.String applicationName, java.lang.String includeName)
          Turn a relative resource name into an include statement for HTML.
 java.lang.String getInclude(java.lang.String applicationPath, java.lang.String applicationName, java.lang.String includeName, java.lang.String cachePrefix)
           
static java.lang.String getMimeType(java.lang.String key)
           
 IContext getResource(java.lang.String key)
           Get the IContext node that contains the references to the resource named by key, where key is relative to the root of this assembly.
 IContext getResource(java.lang.String resourceID, boolean checkImports)
          Get a resource, optionally looking in all imported assemblies.
 java.lang.String getResourceFilename(java.lang.String resourceID)
           
 boolean hasManifestEntry(java.lang.String key)
          Resources are listed in the manifest of this Assembly at run time only, and that entry indicates that the resource can be found in this Assembly context.
 boolean hasResource(java.lang.String key)
           
 void invalidate(java.lang.String key)
          Removes the resources content from the cache.
static boolean isBinaryResource(IContext node)
          This override operates on an IContext node that represents a resource in the Assembly cache.
static boolean isBinaryResource(java.lang.String key)
          This override operates on a String resource name, and inspects the "extension" (the characters after the last dot in the name) to determine if the resourcetype is binary.
 boolean isCacheOn()
           
static java.lang.String listResource(IContext context)
           
 java.lang.String listResource(java.lang.String key)
          Produces a listing showing the attributes of this cached resource.
 StringList listResourceNames()
          Produces a StringList containing a bare listing of relative path resource names that have been read into the memory cache.
 java.lang.String listResourceNames(java.lang.String lineBreak)
          Produces a bare listing of relative path resource names that have been read into the memory cache.
 java.lang.String listResourceNamesInCache()
          Produces a bare listing of relative path resource names that have been read into the memory cache.
 java.util.Map listTemplates(java.lang.String relDirectory)
           
 void logCaching(java.lang.String msg)
           
static void main(java.lang.String[] args)
           
 boolean onDirectory(java.lang.String diveID, java.io.File directory, java.lang.String dirname, java.lang.String relativePath)
          From: IFileDiverListener interface, and is for internal use only.
 void onFile(java.lang.String diveID, java.io.File directory, java.io.File file, java.lang.String filename, java.lang.String relativePath)
          From: IFileDiverListener interface, and is for internal use only.
static IContext readResource(IContext context)
           
protected static IContext readResource(IContext context, java.lang.String key, java.lang.String fullpath)
          Important: doesn't rebind the ASSEMBLYDIR attribute, since this method is static.
 IContext registerApplicationResource(java.lang.String applicationName, java.lang.String resourceID)
          Enter the resource into the Assembly's tree, but even though the file may not exist on disk yet, though it is best to save the resource to disk and then call registerApplicationResource.
 void setAssemblyDirectory(java.lang.String new_value)
          The name of the directory that the Assembly expanded to.
static IContext setBinaryContent(IContext context, byte[] buff, java.lang.String fullpath, java.lang.Long lastModified, boolean inMemory)
           
static IContext setContent(IContext context, java.lang.String content, java.lang.String fullpath, java.lang.Long lastModified, boolean inMemory)
           
 java.lang.String toString()
           
 void update()
          (Optional) Implementations should re-read resources and lists of resources, e.g. files from disk.
 void updateResource(java.lang.String relativePath)
           
 
Methods inherited from class com.dynamide.resource.Pool
getPooledObject, getPoolMax, setPoolMax, setPoolMax
 
Methods inherited from class com.dynamide.resource.ContextNode
bind, bind, bindAll, bindAllAttributes, bindAttribute, dump, dumpAttributes, dumpContext, find, find, find, firstContext, get, getAttribute, getAttributeCount, getAttributes, getContext, getContextCount, getContexts, getKey, getPermission, hasAttribute, hasContext, listAttributeNames, listAttributeNames, listContextNames, listContextNames, lockPermissions, rebind, rebind, rebindAttribute, remove, removeAttribute, removeFirstContext, setKey, unlockPermissions, writeCache
 
Methods inherited from class com.dynamide.DynamideObject
clearProfiler, dump, dumpHTML, expand, finalize, findParentExpander, findParentPage, findParentSession, findTopParentPage, getCategoryID, getDotName, getID, getNextGetter, getObjectID, getOwner, getProfiler, isDebugEnabled, isInfoEnabled, logDebug, logDebug, logDebug, logDebug, logError, logError, logError, logError, logInfo, logInfo, logInfo, logInfo, logWarn, logWarn, logWarn, logWarn, popLogContext, printf, printProfiler, profileEnter, profileLeave, pushLogContext, setDotName, setID, setNextGetter, setObjectID, setOwner, sprintf, useProfiler, walkParents
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.dynamide.resource.IContext
bind, bind, bindAll, bindAllAttributes, bindAttribute, dumpAttributes, dumpContext, find, find, find, firstContext, getAttribute, getAttributeCount, getAttributes, getContext, getContextCount, getContexts, getKey, getPermission, hasAttribute, hasContext, lockPermissions, rebind, rebind, rebindAttribute, remove, removeAttribute, removeFirstContext, setKey, unlockPermissions
 

Field Detail

ACCESSED

public static final java.lang.String ACCESSED
See Also:
Constant Field Values

BINARY

public static final java.lang.String BINARY
See Also:
Constant Field Values

CACHED

public static final java.lang.String CACHED
See Also:
Constant Field Values

CACHE_REL

public static final java.lang.String CACHE_REL
See Also:
Constant Field Values

CONTENT

public static final java.lang.String CONTENT
See Also:
Constant Field Values

FULLPATH

public static final java.lang.String FULLPATH
See Also:
Constant Field Values

HITS

public static final java.lang.String HITS
See Also:
Constant Field Values

MODIFIED

public static final java.lang.String MODIFIED
See Also:
Constant Field Values

ASSEMBLY

public static final java.lang.String ASSEMBLY
See Also:
Constant Field Values

ASSEMBLY_STANDARD_NAME

public static final java.lang.String ASSEMBLY_STANDARD_NAME
See Also:
Constant Field Values

ASSEMBLYDIR

public static final java.lang.String ASSEMBLYDIR
See Also:
Constant Field Values

BASENAME

public static final java.lang.String BASENAME
See Also:
Constant Field Values

BUILD

public static final java.lang.String BUILD
See Also:
Constant Field Values

IMPORTS

public static final java.lang.String IMPORTS
See Also:
Constant Field Values

INTERFACE

public static final java.lang.String INTERFACE
See Also:
Constant Field Values

NAME

public static final java.lang.String NAME
See Also:
Constant Field Values

BASENAMES

public static final java.lang.String BASENAMES
key for the collection of basenames IContexts, which hold the list of assembly-build names that provide this basename.

See Also:
Constant Field Values

CAT_CACHE

public static final java.lang.String CAT_CACHE
See Also:
Constant Field Values

DEFAULT_INTERFACE_NUMBER

public static final java.lang.String DEFAULT_INTERFACE_NUMBER
See Also:
Constant Field Values

FALSE

public static final java.lang.String FALSE
See Also:
Constant Field Values

TRUE

public static final java.lang.String TRUE
See Also:
Constant Field Values

IN_MEMORY_RESOURCE

public static final java.lang.String IN_MEMORY_RESOURCE
See Also:
Constant Field Values

LOG_CACHING

protected static boolean LOG_CACHING

WIDGETS_DIR_REL_RESOURCES

public static final java.lang.String WIDGETS_DIR_REL_RESOURCES
See Also:
Constant Field Values
Constructor Detail

Assembly

public Assembly(DynamideObject owner)
         throws java.lang.SecurityException
Illegal to call directly - use ResourceManger.createAssembly() instead, from the Root ResourceManger.

Throws:
java.lang.SecurityException - if the direct caller is not ResourceManger.createAssembly() on the Root ResourceManger.

Assembly

public Assembly(DynamideObject owner,
                java.lang.String key,
                java.lang.String account,
                java.lang.String RESOURCE_ROOT)
         throws java.lang.SecurityException
Illegal to call directly - use ResourceManger.createAssembly() instead, from the Root ResourceManger.

Throws:
java.lang.SecurityException - if the direct caller is not ResourceManger.createAssembly() on the Root ResourceManger.
Method Detail

createAssembly

public static Assembly createAssembly(ResourceManager resourceManager,
                                      IContext assemblies,
                                      java.io.File assemblyDir,
                                      java.lang.String assemblyName,
                                      java.lang.String account,
                                      java.lang.String RESOURCE_ROOT,
                                      boolean isCacheOn)
                               throws java.lang.Exception
Throws:
java.lang.Exception

extractBinaryResourceContent

public static byte[] extractBinaryResourceContent(IContext node)
                                           throws ResourceException
Get the content of the resource as a byte array.

Returns:
The byte array, unless the resource was not binary, in which case an excpetion is thrown.
Throws:
ResourceException

extractResourceContent

public static java.lang.String extractResourceContent(IContext node)
                                               throws ResourceException
Get the content of the resource as a String from an IContext node.

Returns:
A String, unless the resource was binary, in which case an exception is thrown.
Throws:
ResourceException

findAssembly

public static Assembly findAssembly(IContext assemblies,
                                    java.lang.String basename,
                                    java.lang.String interfaceNumber,
                                    java.lang.String build)
Find Assembly in "assemblies" IContext param, matching basename param, with these rules:


isBinaryResource

public static boolean isBinaryResource(IContext node)
This override operates on an IContext node that represents a resource in the Assembly cache. The resource is binary if its BINARY attribute is TRUE, which is determined by using an internal table at resource read time that maps resource extensions to binary or text resources. This table is accessed by calling isBinaryResource(String).


isBinaryResource

public static boolean isBinaryResource(java.lang.String key)
This override operates on a String resource name, and inspects the "extension" (the characters after the last dot in the name) to determine if the resourcetype is binary. The current implementation returns true for jpeg's, gif's, etc.


getMimeType

public static java.lang.String getMimeType(java.lang.String key)

listResource

public static java.lang.String listResource(IContext context)

readResource

public static IContext readResource(IContext context)

readResource

protected static IContext readResource(IContext context,
                                       java.lang.String key,
                                       java.lang.String fullpath)
Important: doesn't rebind the ASSEMBLYDIR attribute, since this method is static.


setBinaryContent

public static IContext setBinaryContent(IContext context,
                                        byte[] buff,
                                        java.lang.String fullpath,
                                        java.lang.Long lastModified,
                                        boolean inMemory)
Parameters:
inMemory - Indicates that the resource is not to be found on disk, so subsequent calls to getResource will NOT attempt to look for the latest resource from disk, which is useful if you construct a resource in memory or pull if off a socket, etc.

setContent

public static IContext setContent(IContext context,
                                  java.lang.String content,
                                  java.lang.String fullpath,
                                  java.lang.Long lastModified,
                                  boolean inMemory)
Parameters:
inMemory - Indicates that the resource is not to be found on disk, so subsequent calls to getResource will NOT attempt to look for the latest resource from disk, which is useful if you construct a resource in memory or pull if off a socket, etc.

accessed

public static void accessed(IContext context)

extractResourceContent

public java.lang.String extractResourceContent(java.lang.String resourceID)
                                        throws ResourceException
Get the content of the resource as a String, by resourceID.

Returns:
A String, unless the resource was binary, in which case an exception is thrown.
Throws:
ResourceException

findImport

public Assembly findImport(java.lang.String assemblyName,
                           java.lang.String assemblyInterfaceNumber,
                           java.lang.String assemblyBuild)

getAccount

public java.lang.String getAccount()

getApplicationResource

public IContext getApplicationResource(java.lang.String applicationName,
                                       java.lang.String resourceID)
Each assembly has two places to look for resources: So resources that are not things like page1.xml or application.xml should go in one of those folders and thus begin with "resources/".


getAssemblyDirectory

public java.lang.String getAssemblyDirectory()
The name of the directory that the Assembly expanded to.


getBuildName

public java.lang.String getBuildName()

getImports

public java.util.List getImports()

getImportsFullPath

public java.lang.String getImportsFullPath()

getImportsFullPath

public java.lang.String getImportsFullPath(java.lang.String separator)

getImportsFullPathAsContext

public IContext getImportsFullPathAsContext()
Returns:
An IContext that contains the paths, listed as attributes in order of search: the first search fullpath is stored in the attribute "0", the next in attribute 1, and so on.

getImportsPath

public java.lang.String getImportsPath()

getInclude

public java.lang.String getInclude(java.lang.String applicationPath,
                                   java.lang.String applicationName,
                                   java.lang.String includeName)
Turn a relative resource name into an include statement for HTML. examples:
  js/page.js
  images/map.jpg
  


getInclude

public java.lang.String getInclude(java.lang.String applicationPath,
                                   java.lang.String applicationName,
                                   java.lang.String includeName,
                                   java.lang.String cachePrefix)

getResourceFilename

public java.lang.String getResourceFilename(java.lang.String resourceID)

getResource

public IContext getResource(java.lang.String key)

Get the IContext node that contains the references to the resource named by key, where key is relative to the root of this assembly. Use the functions in Assembly, namely isBinaryResource(IContext), extractBinaryResourceContent, and extractResourceContent to get to the actual resource content.

For example:

  IContext context = assembly.getResource("css/dynamide.css");
  String mycss = Assembly.extractResourceContent(context);
  

Also, this would be legal if you didn't know if the resource were binary:

  IContext context = assembly.getResource("css/dynamide.css");
  if (Assembly.isBinaryResource(context)){
       String mycontents = Assembly.extractResourceContent(context);
       ...
  } else {
       byte [] mybytes = Assembly.extractBinaryResourceContent(context);
       ...
  }
  


getResource

public IContext getResource(java.lang.String resourceID,
                            boolean checkImports)
Get a resource, optionally looking in all imported assemblies.


hasManifestEntry

public boolean hasManifestEntry(java.lang.String key)
Resources are listed in the manifest of this Assembly at run time only, and that entry indicates that the resource can be found in this Assembly context.


hasResource

public boolean hasResource(java.lang.String key)

invalidate

public void invalidate(java.lang.String key)
Removes the resources content from the cache.

Parameters:
key - If key is currently cached, remove the contents from the cache, but keep the key to imply that the resource is found in our manifest, but since the value is null, the Assembly should once again look on disk or other repository for the resource.

isCacheOn

public boolean isCacheOn()

listResource

public java.lang.String listResource(java.lang.String key)
Produces a listing showing the attributes of this cached resource.

Returns:
a String with information about the resource, will be the empty String if resource is absent.

listResourceNames

public StringList listResourceNames()
Produces a StringList containing a bare listing of relative path resource names that have been read into the memory cache. You can transform a StringList to a Collection in this instance by using StringList.keysList().

See Also:
listResourceNames()

listResourceNames

public java.lang.String listResourceNames(java.lang.String lineBreak)
Produces a bare listing of relative path resource names that have been read into the memory cache.

See Also:
listResourceNames()

listResourceNamesInCache

public java.lang.String listResourceNamesInCache()
Produces a bare listing of relative path resource names that have been read into the memory cache.

See Also:
listResourceNames()

listTemplates

public java.util.Map listTemplates(java.lang.String relDirectory)
                            throws java.lang.Exception
Throws:
java.lang.Exception

logCaching

public final void logCaching(java.lang.String msg)

onDirectory

public boolean onDirectory(java.lang.String diveID,
                           java.io.File directory,
                           java.lang.String dirname,
                           java.lang.String relativePath)
From: IFileDiverListener interface, and is for internal use only.

Specified by:
onDirectory in interface IFileDiverListener
Parameters:
diveID - This identifies the callback so that you know which thing you are doing if you use the callback interface for two tasks within one class, or within multiple threads.
Returns:
true if you wish to continue diving INTO the named directory, otherwise return false to skip the contents of the named directory.
See Also:
FileTools.directoryDiver(java.lang.String, java.lang.String, com.dynamide.util.IFileDiverListener)

onFile

public void onFile(java.lang.String diveID,
                   java.io.File directory,
                   java.io.File file,
                   java.lang.String filename,
                   java.lang.String relativePath)
From: IFileDiverListener interface, and is for internal use only.

Specified by:
onFile in interface IFileDiverListener
Parameters:
diveID - This identifies the callback so that you know which thing you are doing if you use the callback interface for two tasks within one class, or within multiple threads.
See Also:
FileTools.directoryDiver(java.lang.String, java.lang.String, com.dynamide.util.IFileDiverListener)

registerApplicationResource

public IContext registerApplicationResource(java.lang.String applicationName,
                                            java.lang.String resourceID)
Enter the resource into the Assembly's tree, but even though the file may not exist on disk yet, though it is best to save the resource to disk and then call registerApplicationResource. If isCacheOn() returns true, then any resource read after this call will not find the resource content. If isCacheOn() returns false, then subsequent calls to getResource, etc., will go look on disk for the content. If your resource does not exist on disk, then you will want to set its content via the methods setContent() or setBinaryContent(). Those functions accept the "inMemory" parameter, which indicates that the resource is not to be found on disk, so subsequent calls to getResource will NOT attempt to look for the latest resource from disk. Useful if you construct a resource in memory or pull if off a socket, etc.


setAssemblyDirectory

public void setAssemblyDirectory(java.lang.String new_value)
                          throws java.lang.Exception
The name of the directory that the Assembly expanded to. IMPORTANT: has the side effect of loading the manifest for this Assembly, which in this implementation means reading the directory tree.

Throws:
java.lang.Exception

toString

public java.lang.String toString()
Overrides:
toString in class ContextNode

update

public void update()
Description copied from interface: IContext
(Optional) Implementations should re-read resources and lists of resources, e.g. files from disk.

Specified by:
update in interface IContext
Overrides:
update in class ContextNode
To do:
This class should check disk for updates when this method is called.

updateResource

public void updateResource(java.lang.String relativePath)

main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception
Throws:
java.lang.Exception


Copyright 2001-2013 DYNAMIDE.COM. All Rights Reserved.