com.dynamide.resource
Interface IContext

All Known Implementing Classes:
AbstractWidget, Account, Application, Assembly, ContextNode, Field, JDOMFile, Page, Persistent, Pool, ResourceManager, Session, WebAppEntry, Widget, WidgetType

public interface IContext

Defines the node of a tree of IContext nodes, implementing the Composite pattern.


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 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 dumpAttributes(boolean html)
           
 java.lang.String dumpContext(boolean html)
           
 java.lang.Object find(java.lang.String path)
           Find an object based on the path from the current context, using "/" as the path element separator.
 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 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 attributeName)
           
 boolean hasContext(java.lang.String key)
           
 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)
          Won't throw an ObjectAlreadyBoundException if one exists with the same key, just silently replaces it.
 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)
           
 void unlockPermissions(java.security.Permissions permissions)
           
 void update()
          (Optional) Implementations should re-read resources and lists of resources, e.g. files from disk.
 

Method Detail

getKey

java.lang.String getKey()

setKey

void setKey(java.lang.String key)

lockPermissions

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).

Throws:
java.lang.SecurityException

unlockPermissions

void unlockPermissions(java.security.Permissions permissions)
                       throws java.lang.SecurityException
Throws:
java.lang.SecurityException

getPermission

java.security.Permission getPermission(java.lang.String permissionName)

getAttribute

java.lang.Object getAttribute(java.lang.String attributeName)

hasAttribute

boolean hasAttribute(java.lang.String attributeName)

getAttributeCount

int getAttributeCount()
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.


getAttributes

java.util.Map getAttributes()
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.


bindAttribute

void bindAttribute(java.lang.String attributeName,
                   java.lang.Object value)
                   throws java.lang.SecurityException,
                          ObjectAlreadyBoundException
Throws:
java.lang.SecurityException
ObjectAlreadyBoundException

rebindAttribute

void rebindAttribute(java.lang.String attributeName,
                     java.lang.Object value)
                     throws java.lang.SecurityException
Throws:
java.lang.SecurityException

bindAllAttributes

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

Throws:
java.lang.SecurityException
ObjectAlreadyBoundException

firstContext

IContext firstContext()
simply return the first context in list of contexts, or null if list is empty.


removeFirstContext

IContext removeFirstContext()
simply return the first context in list of contexts, and remove it, or null if list is empty.


getContext

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. 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;
            }
            ...
        }


 

Returns:
null if not found.

hasContext

boolean hasContext(java.lang.String key)

getContexts

java.util.Map getContexts()
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.


getContextCount

int getContextCount()

bindAll

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

Throws:
java.lang.SecurityException
ObjectAlreadyBoundException

bind

IContext bind(java.lang.String key,
              IContext context)
              throws java.lang.SecurityException,
                     ObjectAlreadyBoundException
Accepts IContext items. IContexts can behave as a subcontexts, if they have more than zero IContext nodes. Also, IContexts can have attributes, such as pooling information. Throws ObjectAlreadyBoundException if object exists as a child already -- use rebind instead.

Returns:
a reference to the new context just bound.
Throws:
java.lang.SecurityException
ObjectAlreadyBoundException

bind

IContext bind(IContext context)
              throws java.lang.SecurityException,
                     ObjectAlreadyBoundException
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"));
 

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

rebind

IContext rebind(java.lang.String key,
                IContext context)
                throws java.lang.SecurityException
Won't throw an ObjectAlreadyBoundException if one exists with the same key, just silently replaces it.

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

rebind

IContext rebind(IContext context)
                throws java.lang.SecurityException
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.

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

remove

IContext remove(java.lang.String key)
                throws java.lang.SecurityException
Throws:
java.lang.SecurityException

removeAttribute

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

find

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.
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".

Parameters:
path - An array of strings, each one naming a context.
See Also:
find(String,String), ContextNode.find(String [] path), getContext(String)

find

java.lang.Object find(java.lang.String path)

Find an object based on the path from the current context, using "/" as the path element separator. This method will return the wrong result if the context id's can contain slashes themselves, such as resource locations within the Assembly tree.


find

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. 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".

See Also:
find(String [] path), ContextNode.find(String [] path), getContext(String)

update

void update()
(Optional) Implementations should re-read resources and lists of resources, e.g. files from disk.


dumpContext

java.lang.String dumpContext(boolean html)

dumpAttributes

java.lang.String dumpAttributes(boolean html)


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