org.tentackle.appworx
Class AbstractApplication

java.lang.Object
  extended by org.tentackle.appworx.AbstractApplication
Direct Known Subclasses:
Application, ApplicationServer, ConsoleApplication, WebApplication

public abstract class AbstractApplication
extends Object

Common code shared by all different kinds of Tentackle applications, such as Application, ApplicationServer or WebApplication

Author:
harald

Constructor Summary
AbstractApplication()
          Super constructor for all derived classes.
 
Method Summary
 ContextDb createContextDb(Db db)
          Creates the contextdb.
 Db createDb(AppUserInfo userInfo)
          Creates a db (still closed).
 ModificationThread createModificationThread()
          Creates the modification thread ready for being started.
 AppUserInfo createUserInfo(String username, char[] password, String dbPropertiesBaseName)
          Creates a user info.
protected  void detectEE()
          Detects whether this application is running within an EE-container.
protected  void detectJNLP()
          Detects whether this application has been started by JNLP (Java Webstart).
protected  void doConfigureApplication()
          Do anything what's necessary after the connection has been established.
protected  void doFinishStartup()
          Finishes the startup.
The default implementation starts the modification thread, unless the property "nomodthread" is given.
protected  void doInitialize()
          Initializes the application.
 ContextDb getContextDb()
          Gets the server's database context.
 Db getDb()
          Gets the db connection.
 Properties getProperties()
          Gets the current properties.
 String getProperty(String key)
          Gets a property.
static AbstractApplication getRunningApplication()
          Gets the (singleton) application instance currently running.
 AppDbObject getUser()
          Gets the AppDbObject corresponding to the userId in AppUserInfo.
 AppDbObject getUser(long userId)
          Gets the AppDbObject corresponding to the object-ID of a user entity.
 AppUserInfo getUserInfo()
          Gets the user info.
protected  void installPreferences()
          Installs the preferences backend.
The default implementation installs the DbPreferencesFactory unless the property "nodbprefs" is defined.
protected  void installSecurityManager()
          installs the tentackle security manager
 boolean isDeployedByEE()
          Indicates whether this application is running within an EE-container.
 boolean isDeployedByJNLP()
          Indicates whether this application has been started by JNLP (Java Webstart).
protected  void register()
          Registers the application.
protected  void securityRulesChanged()
          Invoked whenever the security rules change.
 void setContextDb(ContextDb contextDb)
          Sets the context db.
Some apps change the context during runtime.
 void setProperties(Properties props)
          Sets the properties to configure the application.
 void setUserInfo(AppUserInfo userInfo)
          Sets the user info.
protected  void unregister()
          Unregisters the application.
 void updateUserId()
          Updates the user id of the userinfo after logged into a remote server.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractApplication

public AbstractApplication()
Super constructor for all derived classes. Detects whether application is running within EE or JNLP.

Method Detail

register

protected void register()
                 throws ApplicationException
Registers the application. Makes sure that only one application is running at a time. Should be invoked in the start-method.

Throws:
ApplicationException - if an application is already running.

unregister

protected void unregister()
                   throws ApplicationException
Unregisters the application. Makes sure that only one application is running at a time. Should be invoked in the stop-method.

Throws:
ApplicationException - if an application is already running.

getRunningApplication

public static AbstractApplication getRunningApplication()
Gets the (singleton) application instance currently running.

Notice: the method is not synchronized because no serious application will invoke getApplication() before getting itself up and running. So, we leave off these singleton maniac codings here.

Returns:
the application, null if no application started

isDeployedByEE

public boolean isDeployedByEE()
Indicates whether this application is running within an EE-container.

Returns:
true if running in an EE container, false if not

detectEE

protected void detectEE()
Detects whether this application is running within an EE-container. The result can be retrieved by isDeployedByEE().


isDeployedByJNLP

public boolean isDeployedByJNLP()
Indicates whether this application has been started by JNLP (Java Webstart).

Returns:
true if invoked by WebStart, false if not

detectJNLP

protected void detectJNLP()
Detects whether this application has been started by JNLP (Java Webstart). The result can be retrieved by isDeployedByJNLP().


setProperties

public void setProperties(Properties props)
Sets the properties to configure the application.

Must be set before starting the application.
By default the following properties will be honoured:

Parameters:
props - the properties to configure the application

getProperties

public Properties getProperties()
Gets the current properties.

Returns:
the properties

getProperty

public String getProperty(String key)
Gets a property.

Parameters:
key - the property's name
Returns:
the value of the key, null if no such property, the empty string if no value for this property.

getDb

public Db getDb()
Gets the db connection.

Returns:
the db connection, null if not yet configured

setContextDb

public void setContextDb(ContextDb contextDb)
Sets the context db.
Some apps change the context during runtime. They should set the context here, whenever changed.

Parameters:
contextDb - the new context

getContextDb

public ContextDb getContextDb()
Gets the server's database context.

Returns:
the database context

getUserInfo

public AppUserInfo getUserInfo()
Gets the user info.

Returns:
the user info

setUserInfo

public void setUserInfo(AppUserInfo userInfo)
Sets the user info. Some applications may change the userinfo.

Parameters:
userInfo - the user info

updateUserId

public void updateUserId()
                  throws ApplicationException
Updates the user id of the userinfo after logged into a remote server.

Throws:
ApplicationException

getUser

public AppDbObject getUser(long userId)
Gets the AppDbObject corresponding to the object-ID of a user entity.

Should be overridden if application provides a user entity. The default implementation returns null.

Parameters:
userId - the user id
Returns:
the user object, null if unknown

getUser

public AppDbObject getUser()
Gets the AppDbObject corresponding to the userId in AppUserInfo.

The default implementation invokes getUser(long).

Returns:
the logged in user object, null if unknown

createUserInfo

public AppUserInfo createUserInfo(String username,
                                  char[] password,
                                  String dbPropertiesBaseName)
Creates a user info. The default implementation creates an AppUserInfo. If the username is null, the current system user will be used. Override this method if the application uses a subclass of AppUserInfo.

Parameters:
username - is the name of the user, null if System.getProperty("user.name")
password - is the password, null if none
dbPropertiesBaseName - is the resource bundle basename of the db-property file, null if "Db"
Returns:
the user info

createDb

public Db createDb(AppUserInfo userInfo)
Creates a db (still closed). The default implementation creates a standard Db.

Parameters:
userInfo - the user info
Returns:
the created Db

createContextDb

public ContextDb createContextDb(Db db)
Creates the contextdb. Override this method if the application uses a subclass of ContextDb.

Parameters:
db - the database connection
Returns:
the db context

createModificationThread

public ModificationThread createModificationThread()
Creates the modification thread ready for being started. The default implementation creates the modthread with a polling interval of 2 seconds which does not clone the db connection.

Returns:
the created modification thread

installPreferences

protected void installPreferences()
Installs the preferences backend.
The default implementation installs the DbPreferencesFactory unless the property "nodbprefs" is defined. The server uses the system preferences. The property "userprefs" forces usage of user preferences (default is system prefs for servers). The preferences are set to be readonly by default.


installSecurityManager

protected void installSecurityManager()
installs the tentackle security manager


securityRulesChanged

protected void securityRulesChanged()
Invoked whenever the security rules change.


doInitialize

protected void doInitialize()
                     throws ApplicationException
Initializes the application.

This is the first step when an application is launched.

The default implementation first parses the properties for system properties. System properties start with "SYSTEM_" followed by the original property name.
Then the Java security manager is installed if the property "secman=...." is given. Overrides should invoke super.doInitialize() and perform any other necessary steps before construction of the GUI.

Throws:
ApplicationException - if initialization failes

doConfigureApplication

protected void doConfigureApplication()
                               throws ApplicationException
Do anything what's necessary after the connection has been established. Setup preferences, etc... The default creates the modification thread (but does not start it), installs the Preferences and tentackle's SecurityManager.

Throws:
ApplicationException

doFinishStartup

protected void doFinishStartup()
                        throws ApplicationException
Finishes the startup.
The default implementation starts the modification thread, unless the property "nomodthread" is given.

Throws:
ApplicationException


Copyright © 2001-2008 Harald Krake, Bergstr. 48, 78098 Triberg, Germany, harald@krake.de