com.dynamide.resource
Class ContextNode

java.lang.Object
  extended by com.dynamide.DynamideObject
      extended by com.dynamide.resource.ContextNode
All Implemented Interfaces:
IContext, IGet
Direct Known Subclasses:
JDOMFile, Pool, WebAppEntry

public class ContextNode
extends DynamideObject
implements IContext


Field Summary
 
Fields inherited from class com.dynamide.DynamideObject
m_id
 
Constructor Summary
ContextNode(DynamideObject owner)
           
ContextNode(DynamideObject owner, java.lang.String key)
           
ContextNode(java.lang.String key)
           
 
Method Summary
 IContext bind(IContext context)
          Binds an IContext node by the name in node.getKey().
 IContext bind(java.lang.String key, IContext context)
          Accepts Object and IContext items.
 void bindAll(java.util.Map children)
          Add children en masse.
 void bindAllAttributes(java.util.Map attributes)
          Set the attributes en masse.
 void bindAttribute(java.lang.String attributeName, java.lang.Object value)
           
 java.lang.String dump()
          Subclasses can override this with something more descriptive, for logging and debugging.
 java.lang.String dumpAttributes(boolean html)
           
 java.lang.String dumpContext(boolean html)
           
 java.lang.Object find(java.lang.String path)
          Search using "/" as the separator, by simply calling find(path, "/").
 java.lang.Object find(java.lang.String[] path)
          Find an object, based on a path that is an array of strings, one for each context, starting from "this" object,
For example, if you already have a handle to the root WebApps context, called "webapps" here: webapps.find({"/dynamide/demo"}); Or, String[] path = {"/dynamide/demo"}; webapps.find(path); To search from the root, use ResourceManager.find(String[]), which it gets from ContextNode.
 java.lang.Object find(java.lang.String path, java.lang.String separator)
           Find an object based on the path from the current context, using "separator" as the path element separator.
 IContext firstContext()
          simply return the first context in list of contexts, or null if list is empty.
 java.lang.Object get(java.lang.String what)
          Subclasses can override this.
 java.lang.Object getAttribute(java.lang.String attributeName)
           
 int getAttributeCount()
          You can use this method to return zero if you have not yet instantiated a collection of attributes.
 java.util.Map getAttributes()
          You must not return null if the attributes are empty, but rather always return an empty Map.
 IContext getContext(java.lang.String key)
           You either use the concrete com.dynamide.resource.ContextNode as a node in the context tree, or you implement this IContext interface.
 int getContextCount()
           
 java.util.Map getContexts()
          You must not return null if the contexts collection is empty, but rather always return an empty Map.
 java.lang.String getKey()
           
 java.security.Permission getPermission(java.lang.String permissionName)
           
 boolean hasAttribute(java.lang.String key)
           
 boolean hasContext(java.lang.String key)
           
 StringList listAttributeNames(IContext context, boolean sort)
           
 java.lang.String listAttributeNames(IContext context, boolean sort, java.lang.String lineBreak)
           
 StringList listContextNames(IContext context, boolean sort)
           
 java.lang.String listContextNames(IContext context, boolean sort, java.lang.String lineBreak)
           
 void lockPermissions(java.security.Permissions permissions)
          Once permissions are set using lockPermissions, impls should not allow them to be changed.
 IContext rebind(IContext context)
          Binds an IContext node by the name in context.getKey().
 IContext rebind(java.lang.String key, IContext context)
          Accepts Object and IContext items.
 void rebindAttribute(java.lang.String attributeName, java.lang.Object value)
           
 IContext remove(java.lang.String key)
           
 java.lang.Object removeAttribute(java.lang.String key)
           
 IContext removeFirstContext()
          simply return the first context in list of contexts, and remove it, or null if list is empty.
 void setKey(java.lang.String key)
           
 java.lang.String toString()
           
 void unlockPermissions(java.security.Permissions permissions)
           
 void update()
          (Optional) Implementations should re-read resources and lists of resources, e.g. files from disk.
 void writeCache(java.lang.String prefix, java.io.File rootDirectory)
           
 
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
 

Constructor Detail

ContextNode

public ContextNode(DynamideObject owner)

ContextNode

public ContextNode(DynamideObject owner,
                   java.lang.String key)

ContextNode

public ContextNode(java.lang.String key)
Method Detail

getKey

public java.lang.String getKey()
Specified by:
getKey in interface IContext

setKey

public void setKey(java.lang.String key)
Specified by:
setKey in interface IContext

lockPermissions

public void lockPermissions(java.security.Permissions permissions)
                     throws java.lang.SecurityException
Once permissions are set using lockPermissions, impls should not allow them to be changed. To change, you should rebind in the parent context. But you have to have permission to rebind, so that is safe (you need the 'rebindable' permission).

Specified by:
lockPermissions in interface IContext
Throws:
java.lang.SecurityException

unlockPermissions

public void unlockPermissions(java.security.Permissions permissions)
                       throws java.lang.SecurityException
Specified by:
unlockPermissions in interface IContext
Throws:
java.lang.SecurityException

getPermission

public java.security.Permission getPermission(java.lang.String permissionName)
Specified by:
getPermission in interface IContext

get

public java.lang.Object get(java.lang.String what)
                     throws java.lang.Exception
Description copied from class: DynamideObject
Subclasses can override this.

Specified by:
get in interface IGet
Overrides:
get in class DynamideObject
Throws:
java.lang.Exception

getAttribute

public java.lang.Object getAttribute(java.lang.String attributeName)
Specified by:
getAttribute in interface IContext

hasAttribute

public boolean hasAttribute(java.lang.String key)
Specified by:
hasAttribute in interface IContext

getAttributeCount

public int getAttributeCount()
Description copied from interface: IContext
You can use this method to return zero if you have not yet instantiated a collection of attributes. Calling classes should check getAttributeCount() first as an optimization.

Specified by:
getAttributeCount in interface IContext

getAttributes

public java.util.Map getAttributes()
Description copied from interface: IContext
You must not return null if the attributes are empty, but rather always return an empty Map. Callers should check getAttributeCount() first if they wish to perform optimally. This avoids the expense of creating an empty Map if the collection is null.

Specified by:
getAttributes in interface IContext

bindAttribute

public void bindAttribute(java.lang.String attributeName,
                          java.lang.Object value)
                   throws java.lang.SecurityException,
                          ObjectAlreadyBoundException
Specified by:
bindAttribute in interface IContext
Throws:
java.lang.SecurityException
ObjectAlreadyBoundException

rebindAttribute

public void rebindAttribute(java.lang.String attributeName,
                            java.lang.Object value)
                     throws java.lang.SecurityException
Specified by:
rebindAttribute in interface IContext
Throws:
java.lang.SecurityException

bindAllAttributes

public void bindAllAttributes(java.util.Map attributes)
                       throws java.lang.SecurityException,
                              ObjectAlreadyBoundException
Set the attributes en masse.

Specified by:
bindAllAttributes in interface IContext
Throws:
java.lang.SecurityException
ObjectAlreadyBoundException

firstContext

public IContext firstContext()
Description copied from interface: IContext
simply return the first context in list of contexts, or null if list is empty.

Specified by:
firstContext in interface IContext

removeFirstContext

public IContext removeFirstContext()
Description copied from interface: IContext
simply return the first context in list of contexts, and remove it, or null if list is empty.

Specified by:
removeFirstContext in interface IContext

getContext

public IContext getContext(java.lang.String key)
Description copied from interface: IContext

You either use the concrete com.dynamide.resource.ContextNode as a node in the context tree, or you implement this IContext interface. Then for getResource, return the "this" pointer to your implementation object. Optionally, you can perform some other operation to get the actual resource, in which case your concrete class is a proxy, lazy-loader, etc.

All implementations should check for the special cases: "." means "this context", as does the empty string, "". For both, return the current context, which in most implementations means:

        public IContext getContext(String key){
            if ( key.equals(".") || key.length() == 0 ) {
                return this;
            }
            ...
        }


 

Specified by:
getContext in interface IContext
Returns:
null if not found.

hasContext

public boolean hasContext(java.lang.String key)
Specified by:
hasContext in interface IContext

getContextCount

public int getContextCount()
Specified by:
getContextCount in interface IContext

getContexts

public java.util.Map getContexts()
Description copied from interface: IContext
You must not return null if the contexts collection is empty, but rather always return an empty Map. Callers should check getContextCount() first if they wish to perform optimally. This avoids the expense of creating an empty Map if the collection is null.

Specified by:
getContexts in interface IContext

bindAll

public void bindAll(java.util.Map children)
             throws java.lang.SecurityException,
                    ObjectAlreadyBoundException
Add children en masse.

Specified by:
bindAll in interface IContext
Throws:
java.lang.SecurityException
ObjectAlreadyBoundException

bind

public IContext bind(java.lang.String key,
                     IContext context)
              throws java.lang.SecurityException,
                     ObjectAlreadyBoundException
Accepts Object and IContext items. If IContext, then it can behave as a subcontext. Otherwise it won't be walked. Throws ObjectAlreadyBoundException if object exists as a child already -- use rebind instead.

Specified by:
bind in interface IContext
Returns:
a reference to the new context just bound.
Throws:
java.lang.SecurityException
ObjectAlreadyBoundException

bind

public IContext bind(IContext context)
              throws java.lang.SecurityException,
                     ObjectAlreadyBoundException
Description copied from interface: IContext
Binds an IContext node by the name in node.getKey(). If the key hasn't been set, use bind(String,IContext). Note the return value is the IContext node you just passed in, so you can chain statements if you like. Here's an example, using the concrete class com.dynamide.resource.ContextNode:
     IContext root = new ContextNode(null, "root");
     root.bind(new ContextNode(null, "child1")).bind(new ContextNode(null, "child2"));
 

Specified by:
bind in interface IContext
Returns:
a reference to the new context just bound.
Throws:
java.lang.SecurityException
ObjectAlreadyBoundException
See Also:
IContext.bind(String,IContext)

rebind

public IContext rebind(java.lang.String key,
                       IContext context)
                throws java.lang.SecurityException
Accepts Object and IContext items. If IContext, then it can behave as a subcontext. Otherwise it won't be walked.

Specified by:
rebind in interface IContext
Returns:
a reference to the new context just bound.
Throws:
java.lang.SecurityException
See Also:
IContext.bind(String,IContext)

rebind

public IContext rebind(IContext context)
                throws java.lang.SecurityException
Description copied from interface: IContext
Binds an IContext node by the name in context.getKey(). If the key hasn't been set, use rebind(String,IContext). Won't throw an ObjectAlreadyBoundException if one exists with the same key, just silently replaces it.

Specified by:
rebind in interface IContext
Returns:
a reference to the new context just bound.
Throws:
java.lang.SecurityException
See Also:
IContext.rebind(String,IContext)

remove

public IContext remove(java.lang.String key)
                throws java.lang.SecurityException
Specified by:
remove in interface IContext
Throws:
java.lang.SecurityException

removeAttribute

public java.lang.Object removeAttribute(java.lang.String key)
                                 throws java.lang.SecurityException
Specified by:
removeAttribute in interface IContext
Returns:
the Attribute object removed, which may be null, or null if not found.
Throws:
java.lang.SecurityException

find

public java.lang.Object find(java.lang.String[] path)
Description copied from interface: IContext

Find an object, based on a path that is an array of strings, one for each context, starting from "this" object,
For example, if you already have a handle to the root WebApps context, called "webapps" here:

    webapps.find({"/dynamide/demo"});
  
Or,
    String[] path = {"/dynamide/demo"};
    webapps.find(path);
  
To search from the root, use ResourceManager.find(String[]), which it gets from ContextNode.
Here's an example that shows two strings in the array, and uses the ResourceManager to search from the root of the context tree. Example:
           String [] path= {"web-apps", "/dynamide/demo"};
     Object o = ResourceManager.find(path)
  

Same rules as getContext(), which include: if the path is "" or ".', return a pointer to "this".

Specified by:
find in interface IContext
Parameters:
path - construct an array of strings, one for each context, starting from this object, for example: find({"web-apps", "/dynamide/demo"}); then, to search from the root, use ResourceManager.find(String[]).
Returns:
A reference to "this" if path is zero length.
See Also:
IContext.find(String,String), find(String [] path), IContext.getContext(String)

find

public java.lang.Object find(java.lang.String path)
Search using "/" as the separator, by simply calling find(path, "/").

Specified by:
find in interface IContext

find

public java.lang.Object find(java.lang.String path,
                             java.lang.String separator)
Description copied from interface: IContext

Find an object based on the path from the current context, using "separator" as the path element separator. Take care that separator does not appear in element names. If you cannot ensure this, use find(String[] path) instead.

Same rules as getContext(String), which include: if the path is "" or ".', return a pointer to "this".

Specified by:
find in interface IContext
Returns:
A reference to "this" if path is empty.
See Also:
IContext.find(String [] path), find(String [] path), IContext.getContext(String)

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
To do:
this class does nothing with this call. Subclasses probably should be the correct place for implementations.

dump

public java.lang.String dump()
Description copied from class: DynamideObject
Subclasses can override this with something more descriptive, for logging and debugging.

Overrides:
dump in class DynamideObject

dumpContext

public java.lang.String dumpContext(boolean html)
Specified by:
dumpContext in interface IContext

writeCache

public void writeCache(java.lang.String prefix,
                       java.io.File rootDirectory)
                throws java.lang.Exception
Throws:
java.lang.Exception

toString

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

listContextNames

public java.lang.String listContextNames(IContext context,
                                         boolean sort,
                                         java.lang.String lineBreak)

listContextNames

public StringList listContextNames(IContext context,
                                   boolean sort)

listAttributeNames

public java.lang.String listAttributeNames(IContext context,
                                           boolean sort,
                                           java.lang.String lineBreak)

listAttributeNames

public StringList listAttributeNames(IContext context,
                                     boolean sort)

dumpAttributes

public java.lang.String dumpAttributes(boolean html)
Specified by:
dumpAttributes in interface IContext


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