## helma.framework.core
Class Application

    java.lang.Object
      helma.framework.core.Application

All Implemented Interfaces:
  java.lang.Runnable

    public final class Application

extends java.lang.Object
implements java.lang.Runnable

The central class of a Helma application. This class keeps a pool of request evaluators (threads with JavaScript interpreters), waits for requests from the Web server or XML-RPC port and dispatches them to the evaluators.

Field Summary
`protected java.util.Vector` `allThreads`
`protected INode` `cachenode`
`protected long` `errorCount`
`protected java.util.Stack` `freeThreads` Collections for evaluator thread pooling
`protected NodeManager` `nmgr`
`protected long` `requestCount`
`protected SkinManager` `skinmgr` The skin manager for this application
`TypeManager` `typemgr` The type manager checks if anything in the application's prototype definitions has been updated prior to each evaluation.
`protected long` `xmlrpcCount`

Constructor Summary
`Application(java.lang.String name)` Simple constructor for dead application instances.
`Application(java.lang.String name, Repository[] repositories, java.io.File dbDir)` Build an application with the given name with the given sources.
`Application(java.lang.String name, Server server)` Build an application with the given name and server instance.
`Application(java.lang.String name, Server server, Repository[] repositories, java.io.File customAppDir, java.io.File customDbDir)` Build an application with the given name, server instance, sources and db directory.

Method Summary
`boolean` `addRepository(Repository rep)` Add a repository to this app's repository list.
`boolean` `authenticate(java.lang.String uname, java.lang.String password)` In contrast to login, this works outside the Hop user object framework.
`protected void` `checkXmlRpcAccess(java.lang.String proto, java.lang.String method)` Check if a method may be invoked via XML-RPC on a prototype.
`void` `clearCache()` Reset the application's object cache, causing all objects to be refetched from the database.
`int` `countActiveEvaluators()`
`int` `countEvaluators()`
`int` `countFreeEvaluators()`
`int` `countMaxActiveEvaluators()`
`int` `countSessions()` Returns the number of currenty active sessions.
`int` `countThreads()`
`Session` `createSession(java.lang.String sessionId)` Return the session currently associated with a given Hop session ID.
`boolean` `debug()` Tell other classes whether they should output logging information for this application.
`ResponseTrans` `execute(RequestTrans req)` Execute a request coming in from a web client.
`java.lang.Object` `executeExternal(java.lang.String method, java.util.Vector args)`
`java.lang.Object` `executeXmlRpc(java.lang.String method, java.util.Vector args)` Called to execute a method via XML-RPC, usally by helma.main.ApplicationManager which acts as default handler/request dispatcher.
`org.apache.commons.logging.Log` `getAccessLog()` get the app's access log.
`int` `getActiveThreads()` Return the number of currently active threads
`java.util.List` `getActiveUsers()` Return a list of Helma nodes (HopObjects - the database object representing the user, not the session object) representing currently logged in users.
`java.io.File` `getAppDir()` Get the application directory.
`java.lang.String` `getBaseURI()` Returns the baseURI for Hrefs in this application.
`INode` `getCacheNode()` Return a transient node that is shared by all evaluators of this application ("app node")
`int` `getCacheUsage()` Returns the number of elements in the NodeManager's cache
`java.lang.String` `getCharset()` Return the name of the character encoding used by this application
`long` `getChecksum()` Get a checksum that mirrors the state of this application in the sense that if anything in the applciation changes, the checksum hopefully will change, too.
`java.lang.Object` `getChildElement(java.lang.Object obj, java.lang.String name)` Retrieve a child element of this object by name.
`java.lang.ClassLoader` `getClassLoader()` Return the application's classloader
`RequestEvaluator` `getCurrentRequestEvaluator()` Get the current RequestEvaluator, or null if the calling thread is not evaluating a request.
`java.lang.Object` `getDataRoot()` This method returns the root object of this application's object tree.
`DbMapping` `getDbMapping(java.lang.String typename)` Get the DbMapping associated with a prototype name in this application
`ResourceProperties` `getDbProperties()` Get the application's db properties
`DbSource` `getDbSource(java.lang.String name)` Return a DbSource object for a given name.
`DocApplication` `getDoc()`
`java.lang.String` `getElementName(java.lang.Object obj)` Return the name to be used to get this element from its parent
`long` `getErrorCount()`
`RequestEvaluator` `getEvaluator()` Returns a free evaluator to handle a request.
`org.apache.commons.logging.Log` `getEventLog()` get the app's event log.
`java.lang.String` `getHrefRootPrototype()` Returns the prototype name that Hrefs in this application should start with.
`java.lang.String` `getJavaClassForPrototype(java.lang.String typename)` Return the java class that a given prototype wraps, or null.
`org.apache.commons.logging.Log` `getLogger(java.lang.String logname)` Get a logger object to log events for this application.
`java.lang.String` `getName()` Return the name of this application
`java.lang.String` `getNodeHref(java.lang.Object elem, java.lang.String actionName)` Return a path to be used in a URL pointing to the given element and action
`NodeManager` `getNodeManager()` Returns the node manager for this application.
`java.lang.Object` `getParentElement(java.lang.Object obj)` Return the parent element of this object.
`ResourceProperties` `getProperties()` Get the application's app properties
`java.lang.String` `getProperty(java.lang.String propname)` Proxy method to get a property from the applications properties.
`java.lang.String` `getProperty(java.lang.String propname, java.lang.String defvalue)` Proxy method to get a property from the applications properties.
`Prototype` `getPrototype(java.lang.Object obj)` Return a prototype for a given node.
`Prototype` `getPrototypeByName(java.lang.String name)` Return the prototype with the given name, if it exists
`java.lang.String` `getPrototypeName(java.lang.Object obj)` Get the name of the prototype to be used for this object.
`java.util.Collection` `getPrototypes()` Return a collection containing all prototypes defined for this application
`java.util.List` `getRegisteredUsers()` Return a list of Helma nodes (HopObjects - the database object representing the user, not the session object) representing registered users of this application.
`java.util.List` `getRepositories()` Returns the repositories of this application
`int` `getRepositoryIndex(Repository rep)` Searches for the index of the given repository for this app.
`long` `getRequestCount()`
`ResourceComparator` `getResourceComparator()` Get a comparator for comparing Resources according to the order of repositories they're contained in.
`java.lang.String` `getRootHref()` Return the href to the root of this application.
`java.lang.String` `getRootId()` Return the id of the object to be used as this application's root object
`DbMapping` `getRootMapping()` Return the prototype of the object to be used as this application's root object
`java.io.File` `getServerDir()` Return the directory of the Helma server
`Session` `getSession(java.lang.String sessionId)` Return the session currently associated with a given Hop session ID.
`SessionManager` `getSessionManager()` Return the application's session manager
`java.util.Map` `getSessions()` Return the whole session map.
`java.util.List` `getSessionsForUsername(java.lang.String username)` Return an array of `SessionBean` objects currently associated with a given Helma user.
`Skin` `getSkin(java.lang.String protoname, java.lang.String skinname, java.lang.Object[] skinpath)` Return a skin for a given object.
`long` `getStarttime()`
`UploadStatus` `getUploadStatus(RequestTrans req)` Return the current upload status.
`INode` `getUserNode(java.lang.String uid)` Returns a Node representing a registered user of this application by his or her user name.
`INode` `getUserRoot()` Returns the Object which contains registered users of this application.
`WrappedNodeManager` `getWrappedNodeManager()` Returns a wrapper containing the node manager for this application.
`long` `getXmlrpcCount()`
`java.lang.String` `getXmlRpcHandlerName()` Return the XML-RPC handler name for this app.
`boolean` `hasExplicitBaseURI()` Return true if the baseURI property is defined in the application properties, false otherwise.
`void` `init()` Get the application ready to run, initializing the evaluators and type manager.
`void` `init(java.lang.String ignoreDirs)` Get the application ready to run, initializing the evaluators and type manager.
`boolean` `isJavaPrototype(java.lang.String typename)` Check whether a prototype is for scripting a java class, i.e.
`boolean` `isRunning()` Returns true if this app is currently running
`void` `logAccess(java.lang.String msg)` Log an application access
`void` `logError(java.lang.String msg)` Log an application error
`void` `logError(java.lang.String msg, java.lang.Throwable error)` Log an application error
`void` `logEvent(java.lang.String msg)` Log a generic application event
`boolean` `loginSession(java.lang.String uname, java.lang.String password, Session session)` Log in a user given his or her user name and password.
`void` `logoutSession(Session session)` Log out a session from this application.
`void` `printThreadStats()` Periodically called to log thread stats for this application
`INode` `registerUser(java.lang.String uname, java.lang.String password)` Register a user with the given user name and password.
`void` `releaseEvaluator(RequestEvaluator ev)` Returns an evaluator back to the pool when the work is done.
`void` `run()` The run method performs periodic tasks like executing the scheduler method and kicking out expired user sessions.
`void` `setBaseURI(java.lang.String uri)` This method sets the base URL of this application which will be prepended to the actual object path.
`protected void` `setCurrentRequestEvaluator(RequestEvaluator eval)` Set the current RequestEvaluator for the calling thread.
`void` `setDataRoot(java.lang.Object root)` Set the application's root element to an arbitrary object.
`boolean` `setNumberOfEvaluators(int n)` This can be used to set the maximum number of evaluators which will be allocated.
`void` `start()` Create and start scheduler and cleanup thread
`void` `stop()` This is called to shut down a running application.
`java.lang.String` `toString()` Return a string representation for this app.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Field Detail

### nmgr

    protected NodeManager nmgr

### typemgr

    public TypeManager typemgr

  The type manager checks if anything in the application's prototype definitions has been updated prior to each evaluation.

### skinmgr

    protected SkinManager skinmgr

  The skin manager for this application

### freeThreads

    protected java.util.Stack freeThreads

  Collections for evaluator thread pooling

### allThreads

    protected java.util.Vector allThreads

### cachenode

    protected INode cachenode

### requestCount

    protected volatile long requestCount

### xmlrpcCount

    protected volatile long xmlrpcCount

### errorCount

    protected volatile long errorCount

Constructor Detail

### Application

    public Application(java.lang.String name)

  Simple constructor for dead application instances.

### Application

    public Application(java.lang.String name,
                       Repository[] repositories,
                       java.io.File dbDir)
                throws java.rmi.RemoteException,
                       java.lang.IllegalArgumentException

  Build an application with the given name with the given sources. No Server-wide properties are created or used.

  Throws:
    `java.rmi.RemoteException`
    `java.lang.IllegalArgumentException`

### Application

    public Application(java.lang.String name,
                       Server server)
                throws java.rmi.RemoteException,
                       java.lang.IllegalArgumentException

  Build an application with the given name and server instance. The app directories will be created if they don't exist already.

  Throws:
    `java.rmi.RemoteException`
    `java.lang.IllegalArgumentException`

### Application

    public Application(java.lang.String name,
                       Server server,
                       Repository[] repositories,
                       java.io.File customAppDir,
                       java.io.File customDbDir)
                throws java.rmi.RemoteException,
                       java.lang.IllegalArgumentException

  Build an application with the given name, server instance, sources and db directory.

  Throws:
    `java.rmi.RemoteException`
    `java.lang.IllegalArgumentException`

Method Detail

### init

    public void init()
              throws DatabaseException,
                     java.lang.IllegalAccessException,
                     java.lang.InstantiationException,
                     java.lang.ClassNotFoundException,
                     java.lang.InterruptedException

  Get the application ready to run, initializing the evaluators and type manager.

  Throws:
    `DatabaseException`
    `java.lang.IllegalAccessException`
    `java.lang.InstantiationException`
    `java.lang.ClassNotFoundException`
    `java.lang.InterruptedException`

### init

    public void init(java.lang.String ignoreDirs)
              throws DatabaseException,
                     java.lang.IllegalAccessException,
                     java.lang.InstantiationException,
                     java.lang.ClassNotFoundException,
                     java.lang.InterruptedException

  Get the application ready to run, initializing the evaluators and type manager.

  Parameters:
    `ignoreDirs` - comma separated list of directory names to ignore
  Throws:
    `DatabaseException`
    `java.lang.IllegalAccessException`
    `java.lang.InstantiationException`
    `java.lang.ClassNotFoundException`
    `java.lang.InterruptedException`

### start

    public void start()

  Create and start scheduler and cleanup thread

### stop

    public void stop()

  This is called to shut down a running application.

### isRunning

    public boolean isRunning()

  Returns true if this app is currently running

  Returns:
    true if the app is running

### getAppDir

    public java.io.File getAppDir()

  Get the application directory.

  Returns:
    the application directory, or first file based repository

### getResourceComparator

    public ResourceComparator getResourceComparator()

  Get a comparator for comparing Resources according to the order of repositories they're contained in.

  Returns:
    a comparator that sorts resources according to their repositories

### getEvaluator

    public RequestEvaluator getEvaluator()

  Returns a free evaluator to handle a request.

### releaseEvaluator

    public void releaseEvaluator(RequestEvaluator ev)

  Returns an evaluator back to the pool when the work is done.

### setNumberOfEvaluators

    public boolean setNumberOfEvaluators(int n)

  This can be used to set the maximum number of evaluators which will be allocated. If evaluators are required beyound this number, an error will be thrown.

### getActiveThreads

    public int getActiveThreads()

  Return the number of currently active threads

### execute

    public ResponseTrans execute(RequestTrans req)

  Execute a request coming in from a web client.

### executeXmlRpc

    public java.lang.Object executeXmlRpc(java.lang.String method,
                                          java.util.Vector args)
                                   throws java.lang.Exception

  Called to execute a method via XML-RPC, usally by helma.main.ApplicationManager which acts as default handler/request dispatcher.

  Throws:
    `java.lang.Exception`

### executeExternal

    public java.lang.Object executeExternal(java.lang.String method,
                                            java.util.Vector args)
                                     throws java.lang.Exception

  Throws:
    `java.lang.Exception`

### clearCache

    public void clearCache()

  Reset the application's object cache, causing all objects to be refetched from the database.

### getCacheUsage

    public int getCacheUsage()

  Returns the number of elements in the NodeManager's cache

### setDataRoot

    public void setDataRoot(java.lang.Object root)

  Set the application's root element to an arbitrary object. After this is called with a non-null object, the helma node manager will be bypassed. This function can be used to script and publish any Java object structure with Helma.

### getDataRoot

    public java.lang.Object getDataRoot()

  This method returns the root object of this application's object tree.

### getRootMapping

    public DbMapping getRootMapping()

  Return the prototype of the object to be used as this application's root object

### getRootId

    public java.lang.String getRootId()

  Return the id of the object to be used as this application's root object

### getUserRoot

    public INode getUserRoot()

  Returns the Object which contains registered users of this application.

### getNodeManager

    public NodeManager getNodeManager()

  Returns the node manager for this application. The node manager is the gateway to the helma.objectmodel packages, which perform the mapping of objects to relational database tables or the embedded database.

### getWrappedNodeManager

    public WrappedNodeManager getWrappedNodeManager()

  Returns a wrapper containing the node manager for this application. The node manager is the gateway to the helma.objectmodel packages, which perform the mapping of objects to relational database tables or the embedded database.

### getSessionManager

    public SessionManager getSessionManager()

  Return the application's session manager

  Returns:
    the SessionManager instance used by this app

### getCacheNode

    public INode getCacheNode()

  Return a transient node that is shared by all evaluators of this application ("app node")

### getUserNode

    public INode getUserNode(java.lang.String uid)

  Returns a Node representing a registered user of this application by his or her user name.

### getPrototype

    public Prototype getPrototype(java.lang.Object obj)

  Return a prototype for a given node. If the node doesn't specify a prototype, return the generic hopobject prototype.

### getPrototypeByName

    public Prototype getPrototypeByName(java.lang.String name)

  Return the prototype with the given name, if it exists

### getPrototypes

    public java.util.Collection getPrototypes()

  Return a collection containing all prototypes defined for this application

### getSkin

    public Skin getSkin(java.lang.String protoname,
                        java.lang.String skinname,
                        java.lang.Object[] skinpath)
                 throws java.io.IOException

  Return a skin for a given object. The skin is found by determining the prototype to use for the object, then looking up the skin for the prototype.

  Throws:
    `java.io.IOException`

### createSession

    public Session createSession(java.lang.String sessionId)

  Return the session currently associated with a given Hop session ID. Create a new session if necessary.

### getActiveUsers

    public java.util.List getActiveUsers()

  Return a list of Helma nodes (HopObjects - the database object representing the user, not the session object) representing currently logged in users.

### getRegisteredUsers

    public java.util.List getRegisteredUsers()

  Return a list of Helma nodes (HopObjects - the database object representing the user, not the session object) representing registered users of this application.

### getSessionsForUsername

    public java.util.List getSessionsForUsername(java.lang.String username)

  Return an array of `SessionBean` objects currently associated with a given Helma user.

### getSession

    public Session getSession(java.lang.String sessionId)

  Return the session currently associated with a given Hop session ID.

### getSessions

    public java.util.Map getSessions()

  Return the whole session map.

### countSessions

    public int countSessions()

  Returns the number of currenty active sessions.

### registerUser

    public INode registerUser(java.lang.String uname,
                              java.lang.String password)

  Register a user with the given user name and password.

### loginSession

    public boolean loginSession(java.lang.String uname,
                                java.lang.String password,
                                Session session)

  Log in a user given his or her user name and password.

### logoutSession

    public void logoutSession(Session session)

  Log out a session from this application.

### authenticate

    public boolean authenticate(java.lang.String uname,
                                java.lang.String password)

  In contrast to login, this works outside the Hop user object framework. Instead, the user is authenticated against a passwd file in the application directory. This is to have some sort of authentication available *before* the application is up and running, i.e. for application setup tasks.

### getRootHref

    public java.lang.String getRootHref()
                                 throws java.io.UnsupportedEncodingException

  Return the href to the root of this application.

  Throws:
    `java.io.UnsupportedEncodingException`

### getNodeHref

    public java.lang.String getNodeHref(java.lang.Object elem,
                                        java.lang.String actionName)
                                 throws java.io.UnsupportedEncodingException

  Return a path to be used in a URL pointing to the given element and action

  Throws:
    `java.io.UnsupportedEncodingException`

### getBaseURI

    public java.lang.String getBaseURI()

  Returns the baseURI for Hrefs in this application.

### setBaseURI

    public void setBaseURI(java.lang.String uri)

  This method sets the base URL of this application which will be prepended to the actual object path.

### hasExplicitBaseURI

    public boolean hasExplicitBaseURI()

  Return true if the baseURI property is defined in the application properties, false otherwise.

### getHrefRootPrototype

    public java.lang.String getHrefRootPrototype()

  Returns the prototype name that Hrefs in this application should start with.

### debug

    public boolean debug()

  Tell other classes whether they should output logging information for this application.

### getCurrentRequestEvaluator

    public RequestEvaluator getCurrentRequestEvaluator()

  Get the current RequestEvaluator, or null if the calling thread is not evaluating a request.

  Returns:
    the RequestEvaluator belonging to the current thread

### setCurrentRequestEvaluator

    protected void setCurrentRequestEvaluator(RequestEvaluator eval)

  Set the current RequestEvaluator for the calling thread.

  Parameters:
    `eval` - the RequestEvaluator belonging to the current thread

### getClassLoader

    public java.lang.ClassLoader getClassLoader()

  Return the application's classloader

### getElementName

    public java.lang.String getElementName(java.lang.Object obj)

  Return the name to be used to get this element from its parent

### getChildElement

    public java.lang.Object getChildElement(java.lang.Object obj,
                                            java.lang.String name)

  Retrieve a child element of this object by name.

### getParentElement

    public java.lang.Object getParentElement(java.lang.Object obj)

  Return the parent element of this object.

### getPrototypeName

    public java.lang.String getPrototypeName(java.lang.Object obj)

  Get the name of the prototype to be used for this object. This will determine which scripts, actions and skins can be called on it within the Helma scripting and rendering framework.

### getDoc

    public DocApplication getDoc()

### logError

    public void logError(java.lang.String msg,
                         java.lang.Throwable error)

  Log an application error

### logError

    public void logError(java.lang.String msg)

  Log an application error

### logEvent

    public void logEvent(java.lang.String msg)

  Log a generic application event

### logAccess

    public void logAccess(java.lang.String msg)

  Log an application access

### getEventLog

    public org.apache.commons.logging.Log getEventLog()

  get the app's event log.

### getAccessLog

    public org.apache.commons.logging.Log getAccessLog()

  get the app's access log.

### getLogger

    public org.apache.commons.logging.Log getLogger(java.lang.String logname)

  Get a logger object to log events for this application.

### run

    public void run()

  The run method performs periodic tasks like executing the scheduler method and kicking out expired user sessions.

  Specified by:
    `run` in interface `java.lang.Runnable`

### isJavaPrototype

    public boolean isJavaPrototype(java.lang.String typename)

  Check whether a prototype is for scripting a java class, i.e. if there's an entry for it in the class.properties file.

### getJavaClassForPrototype

    public java.lang.String getJavaClassForPrototype(java.lang.String typename)

  Return the java class that a given prototype wraps, or null.

### getDbSource

    public DbSource getDbSource(java.lang.String name)

  Return a DbSource object for a given name. A DbSource is a relational database defined in a db.properties file.

### getName

    public java.lang.String getName()

  Return the name of this application

### addRepository

    public boolean addRepository(Repository rep)

  Add a repository to this app's repository list. This is used for ZipRepositories contained in top-level file repositories, for instance.

  Parameters:
    `rep` - the repository to add
  Returns:
    if the repository was not yet contained

### getRepositoryIndex

    public int getRepositoryIndex(Repository rep)

  Searches for the index of the given repository for this app. The arguement must be a root argument, or -1 will be returned.

  Parameters:
    `rep` - one of this app's root repositories.
  Returns:
    the index of the first occurrence of the argument in this list; returns `-1` if the object is not found.

### getRepositories

    public java.util.List getRepositories()

  Returns the repositories of this application

  Returns:
    iterator through application repositories

### getServerDir

    public java.io.File getServerDir()

  Return the directory of the Helma server

### getDbMapping

    public DbMapping getDbMapping(java.lang.String typename)

  Get the DbMapping associated with a prototype name in this application

### getUploadStatus

    public UploadStatus getUploadStatus(RequestTrans req)

  Return the current upload status.

  Parameters:
    `req` - the upload RequestTrans
  Returns:
    the current upload status.

### getChecksum

    public long getChecksum()

  Get a checksum that mirrors the state of this application in the sense that if anything in the applciation changes, the checksum hopefully will change, too.

### getProperty

    public java.lang.String getProperty(java.lang.String propname)

  Proxy method to get a property from the applications properties.

### getProperty

    public java.lang.String getProperty(java.lang.String propname,
                                        java.lang.String defvalue)

  Proxy method to get a property from the applications properties.

### getProperties

    public ResourceProperties getProperties()

  Get the application's app properties

  Returns:
    the properties reflecting the app.properties

### getDbProperties

    public ResourceProperties getDbProperties()

  Get the application's db properties

  Returns:
    the properties reflecting the db.properties

### getXmlRpcHandlerName

    public java.lang.String getXmlRpcHandlerName()

  Return the XML-RPC handler name for this app. The contract is to always return the same string, even if it has been changed in the properties file during runtime, so the app gets unregistered correctly.

### toString

    public java.lang.String toString()

  Return a string representation for this app.

  Overrides:
    `toString` in class `java.lang.Object`

### countThreads

    public int countThreads()

### countEvaluators

    public int countEvaluators()

### countFreeEvaluators

    public int countFreeEvaluators()

### countActiveEvaluators

    public int countActiveEvaluators()

### countMaxActiveEvaluators

    public int countMaxActiveEvaluators()

### getRequestCount

    public long getRequestCount()

### getXmlrpcCount

    public long getXmlrpcCount()

### getErrorCount

    public long getErrorCount()

### getStarttime

    public long getStarttime()

  Returns:
    ...

### getCharset

    public java.lang.String getCharset()

  Return the name of the character encoding used by this application

  Returns:
    the character encoding

### printThreadStats

    public void printThreadStats()

  Periodically called to log thread stats for this application

### checkXmlRpcAccess

    protected void checkXmlRpcAccess(java.lang.String proto,
                                     java.lang.String method)
                              throws java.lang.Exception

  Check if a method may be invoked via XML-RPC on a prototype.

  Throws:
    `java.lang.Exception`

Copyright © 1998-1998-${year} Helma.org. All Rights Reserved.