net.xoetrope.xui
Class XProject

java.lang.Object
  extended by net.xoetrope.xui.XProject

public class XProject
extends java.lang.Object

    

A holder for references to the objects and resources used by a Xui project

Copyright (c) Xoetrope Ltd., 2002-2003

$Revision: 2.40 $

License: see License.txt


Field Summary
protected  java.applet.Applet app
          The XProject XApplet Object
protected  java.awt.Frame appFrame
          The XProject Frame Object
protected  java.awt.Window appWindow
          The XProject Window Object
protected  java.lang.String basePackageName
          The package where event hadlers can be found
protected  java.util.Vector bindingFactories
          Stores a Vector of XDataBindingFactory Object for this XProject instance
static int CLOSING
           
static int CREATED
           
protected  java.util.Vector customClassLoaders
          Vector of classloaders used to locate resources for this XProject instance
protected  java.lang.String defaultEncoding
          Encoding with which to read and write XML files.
protected  java.lang.String defaultFile
           
protected  java.lang.Class defaultModelClass
          The default XModel based class to be used in this XProject instance.
protected  java.net.URL documentBase
          The path to the startup directory for this XProject instance
protected  java.lang.String eventHandlerClassName
          The name of the event handler class which is to be used
protected  XExceptionHandler exceptionHandler
          A generic handler for exceptions
protected  java.util.Hashtable imageCache
          Hashtable of images already accessed
static int INITIALIZED
           
protected  java.util.Hashtable managerObjects
          Hashtable for storing other non-XUI object such as Routes and Services
protected  MessageHelper messageHelper
          Store a reference to the MessageHelper utility class
protected  XModel modelRoot
          The root XModel for this XProject instance
protected  XPageManager pageManager
          The XPageManager for this XProject instance
protected  ResourceBundleLoader resourceBundleLoader
          ResourceBundleLoader used to load ResourceBundles
static int STARTED
           
protected  java.util.Properties startSettings
          Properties Object created from the statup properties
protected  java.lang.String startupFile
          The name of the startup file for this XProject instance
protected  int status
           
protected  XStyleManager styleManager
          The XStyleManager for this XProject instance
static int TERMINATED
           
static int UNKNOWN
           
protected  java.lang.String widgetPackageName
          The package name of the components to be used (AWT or Swing)
protected  XmlParserFactory xmlParserFactory
          The XmlParserFactory to be used by this XProject instance
 
Constructor Summary
protected XProject()
          Create a new project
 
Method Summary
 void addCustomClassLoader(java.lang.ClassLoader c)
          Add a custom class loader.
 XuiEventHandler createEventHandler(java.lang.Object owner, XValidationHandler validationHandler)
          Create the XuiEventHandler for the passed owner (XPage) and set it's XValidationHandler
protected  java.awt.Image createImage(java.io.InputStream imgStream)
          Returns an Image, or null if the path was invalid.
 java.net.URL findResource(java.lang.String fileName)
          Find a resource
 java.lang.String findResourceAsString(java.lang.String fileName)
          Find a resource and get its filename (unencoded)
 void fixError(java.lang.String errorName, java.lang.Object sourceObj, java.lang.Throwable t)
          Attempt to fix an error when running a XUI application
 java.awt.Frame getAppFrame()
          Get a areference to the applet's Frame
 java.applet.Applet getApplet()
          Get a reference to the applet object
 java.awt.Window getAppWindow()
          Get a reference to the application's main Window
 java.util.Vector getBindingsFactories()
          Get the binding factories.
 java.io.BufferedInputStream getBufferedInputStream(java.io.File file)
          Gets a buffered stream for a file
 java.io.BufferedInputStream getBufferedInputStream(java.lang.String s)
          Gets a buffered stream for a resource
 java.io.BufferedOutputStream getBufferedOutputStream(java.lang.String file)
          Gets a buffered stream for a file
 java.io.BufferedOutputStream getBufferedOutputStream(java.lang.String file, boolean useProjectParent)
          Gets a buffered stream for a file
 java.io.BufferedReader getBufferedReader(java.io.File file, java.lang.String encoding)
          Gets a BufferedReader for a resource
 java.io.BufferedReader getBufferedReader(java.lang.String file)
          Gets a BufferedReader for a resource
 java.io.BufferedReader getBufferedReader(java.lang.String file, java.lang.String encoding)
          Gets a BufferedReader for a resource
 java.lang.String getDefaultEncoding()
          Get the default file encoding (UTF8 unless modified)
 java.net.URL getDocumentBase()
          Get the applet document base.
 XExceptionHandler getExceptionHandler()
          Set an exception handler for unhandled errors during method response method invocation
 java.lang.Object getIcon(java.lang.String name)
          Loads an image icon
 java.awt.Image getImage(java.lang.String name)
          Loads an image resource
 void getImage(XImageHolder holder, java.lang.String name)
          Loads an image resource in a background thread
 java.io.InputStream getInputStream(java.io.File file)
          Gets a stream for a file
 java.io.InputStream getInputStream(java.lang.String fileName)
          Gets a stream for a resource
 MessageHelper getMessageHelper()
          Get the message helper (for formatting messages)
 XModel getModel()
          Get the root instance of the model.
 java.lang.Object getObject(java.lang.String key)
          Get a manager object
 java.io.OutputStream getOutputStream(java.lang.String file)
          Gets a stream for a file
 java.io.OutputStream getOutputStream(java.lang.String file, boolean useProjectParent)
          Gets a stream for a file
 java.lang.String getPackageName()
          Get the default package name
 XPageManager getPageManager()
          Gets an instance of the page manager.
 java.util.ResourceBundle getResourceBundle(java.lang.String name)
          Get a resource bundle
 ResourceBundleLoader getResourceBundleLoader()
          Get the resource bundle loader
 java.lang.String getStartupFile()
          Get the name of the startup file.
 java.lang.String getStartupParam(java.lang.String name)
          Gets a startup parameter
 int getStartupParamAsInt(java.lang.String name)
          Gets a startup parameter
 int getStatus()
          Get the project status
 XStyleManager getStyleManager()
          Get a reference to the XStyleManager.
 XTranslator getTranslator()
          Get the default translation object
 XTranslator getTranslator(java.lang.String name)
          Get the translation object for the named bundle.
 java.net.URL getUrl(java.lang.String fileName)
          Gets a URL for a resource
 java.lang.String getWidgetPackageName()
          Get the default widget package name
 XmlParserFactory getXmlParserFactory()
          Get the XML parser factory
 void initialise(java.lang.String startFile)
          Setup the project and configure its resources
 void registerBindingFactory(XDataBindingFactory fact)
          Register a binding factory with the project.
 void registerBindingFactory(XDataBindingFactory fact, int pos)
          Register a binding factory with the project.
 void removeObject(java.lang.String key)
          Remove a manager object value
 void resetModel()
          Reset the model to its initial state.
 void setAppFrame(java.awt.Frame frame)
          Set the main Frame reference
 void setApplet(java.applet.Applet applet)
          Set tbe applet reference
 void setAppWindow(java.awt.Window window)
          Set the main Window reference
 void setDefaultEncoding(java.lang.String encoding)
          Set the default file encoding (UTF8 unless modified) see http://java.sun.com/j2se/1.4.2/docs/guide/intl/encoding.doc.html
 void setDefaultFile(java.lang.String file)
          Set the default file/directory specification used to locate files by the getOutputStream( String file, boolean useProjectParent ) method
 void setDefaultModel(java.lang.String className)
          Sets the default model class.
 void setDocumentBase(java.net.URL u)
          Set/Record the URL from which the applet was loaded
 void setEventHandlerClass(java.lang.String className)
          Set the name of the class which will handle events for this XProject instance
 void setExceptionHandler(XExceptionHandler eh)
          Set an exception handler for unhandled errors during method response method invocation
 void setObject(java.lang.String key, java.lang.Object obj)
          Set an manager object value
 void setPackageName(java.lang.String pn)
          Set the default package name.
 void setResourceBundleLoader(ResourceBundleLoader loader)
          Set the object to load language resource bundles
 void setStartupFile(java.lang.String fileName)
          Sets the startup file and loads the associated resource.
 void setStartupParam(java.lang.String name, java.lang.String value)
          Sets a startup parameter
 void setStatus(int newStatus)
          Set the application status
 void setWidgetPackageName(java.lang.String pn)
          Set the default widget package name.
protected  java.lang.String slashify(java.lang.String path, boolean isDirectory)
          Taken from java.io.File in JDK 1.4
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

UNKNOWN

public static final int UNKNOWN
See Also:
Constant Field Values

CREATED

public static final int CREATED
See Also:
Constant Field Values

INITIALIZED

public static final int INITIALIZED
See Also:
Constant Field Values

STARTED

public static final int STARTED
See Also:
Constant Field Values

CLOSING

public static final int CLOSING
See Also:
Constant Field Values

TERMINATED

public static final int TERMINATED
See Also:
Constant Field Values

styleManager

protected XStyleManager styleManager
The XStyleManager for this XProject instance


pageManager

protected XPageManager pageManager
The XPageManager for this XProject instance


modelRoot

protected XModel modelRoot
The root XModel for this XProject instance


xmlParserFactory

protected XmlParserFactory xmlParserFactory
The XmlParserFactory to be used by this XProject instance


messageHelper

protected MessageHelper messageHelper
Store a reference to the MessageHelper utility class


bindingFactories

protected java.util.Vector bindingFactories
Stores a Vector of XDataBindingFactory Object for this XProject instance


startupFile

protected java.lang.String startupFile
The name of the startup file for this XProject instance


startSettings

protected java.util.Properties startSettings
Properties Object created from the statup properties


documentBase

protected java.net.URL documentBase
The path to the startup directory for this XProject instance


managerObjects

protected java.util.Hashtable managerObjects
Hashtable for storing other non-XUI object such as Routes and Services


defaultModelClass

protected java.lang.Class defaultModelClass
The default XModel based class to be used in this XProject instance. Defaulted to XBaseModel


eventHandlerClassName

protected java.lang.String eventHandlerClassName
The name of the event handler class which is to be used


defaultFile

protected java.lang.String defaultFile

defaultEncoding

protected java.lang.String defaultEncoding
Encoding with which to read and write XML files. Defaulted to UTF-8


basePackageName

protected java.lang.String basePackageName
The package where event hadlers can be found


widgetPackageName

protected java.lang.String widgetPackageName
The package name of the components to be used (AWT or Swing)


app

protected java.applet.Applet app
The XProject XApplet Object


appWindow

protected java.awt.Window appWindow
The XProject Window Object


appFrame

protected java.awt.Frame appFrame
The XProject Frame Object


customClassLoaders

protected java.util.Vector customClassLoaders
Vector of classloaders used to locate resources for this XProject instance


resourceBundleLoader

protected ResourceBundleLoader resourceBundleLoader
ResourceBundleLoader used to load ResourceBundles


imageCache

protected java.util.Hashtable imageCache
Hashtable of images already accessed


exceptionHandler

protected XExceptionHandler exceptionHandler
A generic handler for exceptions


status

protected int status
Constructor Detail

XProject

protected XProject()
Create a new project

Method Detail

initialise

public void initialise(java.lang.String startFile)
Setup the project and configure its resources

Parameters:
startFile - the startup file

getStyleManager

public XStyleManager getStyleManager()
Get a reference to the XStyleManager. A new instance is created if required

Returns:
the style manager
Since:
1.03

getPageManager

public XPageManager getPageManager()
Gets an instance of the page manager. A new instance is created if required

Returns:
the XPageManager instance
Since:
1.03

getModel

public XModel getModel()
Get the root instance of the model. This class is unique to the project so it should be unique. If no instance has been created then a new one is constructed.

Returns:
the root XModel instance.

setDefaultModel

public void setDefaultModel(java.lang.String className)
Sets the default model class. By default the XBaseModel is used. An instance is not constructed till the first call to getInstance(). If an instance has been constructed then this method will have no effect.

Parameters:
className - the name of the model class e.g. net.xoetrope.xui.data.XBaseModel

resetModel

public void resetModel()
Reset the model to its initial state. Discard all the child nodess


getXmlParserFactory

public XmlParserFactory getXmlParserFactory()
Get the XML parser factory

Returns:
the parser factory

createEventHandler

public XuiEventHandler createEventHandler(java.lang.Object owner,
                                          XValidationHandler validationHandler)
Create the XuiEventHandler for the passed owner (XPage) and set it's XValidationHandler

Parameters:
owner - The XPage for which the passed XValidationHandler is working
validationHandler - The XValidationHandler for this XProject instance
Returns:
The created XuiEventHandler

setEventHandlerClass

public void setEventHandlerClass(java.lang.String className)
Set the name of the class which will handle events for this XProject instance

Parameters:
className - The name of the event handler class

getExceptionHandler

public XExceptionHandler getExceptionHandler()
Set an exception handler for unhandled errors during method response method invocation

Returns:
the exception handler

setExceptionHandler

public void setExceptionHandler(XExceptionHandler eh)
Set an exception handler for unhandled errors during method response method invocation

Parameters:
eh - the exception handler

getMessageHelper

public MessageHelper getMessageHelper()
Get the message helper (for formatting messages)

Returns:
the message helper

getBindingsFactories

public java.util.Vector getBindingsFactories()
Get the binding factories. The binding factories are requested to create component data bindings when a page is loaded from XML.

Returns:
the registered binding factories

registerBindingFactory

public void registerBindingFactory(XDataBindingFactory fact,
                                   int pos)
Register a binding factory with the project. The factories are used to add bindings in the order in which they appear in the array of bindings and the iteration of factories stops once a binding is created.

Parameters:
fact - the new factory
pos - the postion in the array at which to add the factory.

registerBindingFactory

public void registerBindingFactory(XDataBindingFactory fact)
Register a binding factory with the project. The bindingg is appended to the list of bindings.

Parameters:
fact - the new factory

getStartupFile

public java.lang.String getStartupFile()
Get the name of the startup file.

Returns:
the startup file name, normally startup.properties

setStartupFile

public void setStartupFile(java.lang.String fileName)
Sets the startup file and loads the associated resource.

Parameters:
fileName - the name of the startup resource file.

getStartupParam

public java.lang.String getStartupParam(java.lang.String name)
Gets a startup parameter

Parameters:
name - the paramenter name
Returns:
the value

setStartupParam

public void setStartupParam(java.lang.String name,
                            java.lang.String value)
Sets a startup parameter

Parameters:
name - the paramenter name
value - the new value

getStartupParamAsInt

public int getStartupParamAsInt(java.lang.String name)
Gets a startup parameter

Parameters:
name - the paramenter name
Returns:
the value

getStatus

public int getStatus()
Get the project status

Returns:
the current status

setStatus

public void setStatus(int newStatus)
Set the application status

Parameters:
newStatus - the new status

getObject

public java.lang.Object getObject(java.lang.String key)
Get a manager object

Parameters:
key - the name of the object e.g. "Routes", "Services"
Returns:
the object instance or null if it hasn't been added

setObject

public void setObject(java.lang.String key,
                      java.lang.Object obj)
Set an manager object value

Parameters:
key - the name of the object e.g. "Routes", "Services"
obj - the object instance

removeObject

public void removeObject(java.lang.String key)
Remove a manager object value

Parameters:
key - the name of the object e.g. "Routes", "Services"

getIcon

public java.lang.Object getIcon(java.lang.String name)
Loads an image icon

Parameters:
name - the image resource name
Returns:
the image

getImage

public java.awt.Image getImage(java.lang.String name)
Loads an image resource

Parameters:
name - the image resource name
Returns:
the image

getImage

public void getImage(XImageHolder holder,
                     java.lang.String name)
Loads an image resource in a background thread

Parameters:
holder - the component containing to display the image
name - the image resource name

getInputStream

public java.io.InputStream getInputStream(java.lang.String fileName)
Gets a stream for a resource

Parameters:
fileName - the resource file name
Returns:
the InputStream

findResourceAsString

public java.lang.String findResourceAsString(java.lang.String fileName)
Find a resource and get its filename (unencoded)

Parameters:
fileName - the resource file name
Returns:
the complete filename

findResource

public java.net.URL findResource(java.lang.String fileName)
Find a resource

Parameters:
fileName - the resource file name
Returns:
the resource URL or null if it is not found

getBufferedInputStream

public java.io.BufferedInputStream getBufferedInputStream(java.lang.String s)
Gets a buffered stream for a resource

Parameters:
s - the resource name
Returns:
the input stream

getUrl

public java.net.URL getUrl(java.lang.String fileName)
Gets a URL for a resource

Parameters:
fileName - the resource file name
Returns:
the InputStream

addCustomClassLoader

public void addCustomClassLoader(java.lang.ClassLoader c)
Add a custom class loader. Customer class loaders are sometimes added to help locate resources in file structures, jars, remote locations etc...

Parameters:
c - the classloader

getInputStream

public java.io.InputStream getInputStream(java.io.File file)
Gets a stream for a file

Parameters:
file - the file
Returns:
the input stream

getBufferedInputStream

public java.io.BufferedInputStream getBufferedInputStream(java.io.File file)
Gets a buffered stream for a file

Parameters:
file - the file
Returns:
the input stream

getBufferedReader

public java.io.BufferedReader getBufferedReader(java.lang.String file)
                                         throws java.lang.Exception
Gets a BufferedReader for a resource

Parameters:
file - the resource file name
Returns:
the BufferedReader
Throws:
java.lang.Exception - throw an exception if there's a problem

getBufferedReader

public java.io.BufferedReader getBufferedReader(java.lang.String file,
                                                java.lang.String encoding)
                                         throws java.lang.Exception
Gets a BufferedReader for a resource

Parameters:
file - the resource file name
encoding - the input encoding e.g. "UTF8" or null for the default encoding (UTF8 unless it has been changed)
Returns:
the BufferedReader
Throws:
java.lang.Exception - throw an exception if there's a problem

getBufferedReader

public java.io.BufferedReader getBufferedReader(java.io.File file,
                                                java.lang.String encoding)
                                         throws java.lang.Exception
Gets a BufferedReader for a resource

Parameters:
file - the resource file
encoding - the input encoding e.g. "UTF8" or null for the default encoding (UTF8 unless it has been changed)
Returns:
the BufferedReader
Throws:
java.lang.Exception - throw an exception if there a problem

getOutputStream

public java.io.OutputStream getOutputStream(java.lang.String file)
Gets a stream for a file

Parameters:
file - the file
Returns:
the output stream

getBufferedOutputStream

public java.io.BufferedOutputStream getBufferedOutputStream(java.lang.String file)
Gets a buffered stream for a file

Parameters:
file - the file
Returns:
the output stream

getOutputStream

public java.io.OutputStream getOutputStream(java.lang.String file,
                                            boolean useProjectParent)
Gets a stream for a file

Parameters:
file - the file
useProjectParent - use the projects default file specification to locate the file
Returns:
the output stream

getBufferedOutputStream

public java.io.BufferedOutputStream getBufferedOutputStream(java.lang.String file,
                                                            boolean useProjectParent)
Gets a buffered stream for a file

Parameters:
file - the file
useProjectParent - use the projects default file specification to locate the file
Returns:
the output stream

setPackageName

public void setPackageName(java.lang.String pn)
Set the default package name. The default package when accessing user event handlers.

Parameters:
pn - The name of the package to be used

getPackageName

public java.lang.String getPackageName()
Get the default package name

Returns:
the default package name

setWidgetPackageName

public void setWidgetPackageName(java.lang.String pn)
Set the default widget package name. The default package name is used when constructing widgets.

Parameters:
pn - The name of the widget package to be used

getWidgetPackageName

public java.lang.String getWidgetPackageName()
Get the default widget package name

Returns:
the default widget package name

getDocumentBase

public java.net.URL getDocumentBase()
Get the applet document base.

Returns:
the url

setDocumentBase

public void setDocumentBase(java.net.URL u)
Set/Record the URL from which the applet was loaded

Parameters:
u - The path to the start directory

setApplet

public void setApplet(java.applet.Applet applet)
Set tbe applet reference

Parameters:
applet - The XApplet

setAppFrame

public void setAppFrame(java.awt.Frame frame)
Set the main Frame reference

Parameters:
frame - The main application frame

setAppWindow

public void setAppWindow(java.awt.Window window)
Set the main Window reference

Parameters:
window - The main application window

getApplet

public java.applet.Applet getApplet()
Get a reference to the applet object

Returns:
a reference to the applet

getAppFrame

public java.awt.Frame getAppFrame()
Get a areference to the applet's Frame

Returns:
a reference to the frame

getAppWindow

public java.awt.Window getAppWindow()
Get a reference to the application's main Window

Returns:
a reference to the Window

slashify

protected java.lang.String slashify(java.lang.String path,
                                    boolean isDirectory)
Taken from java.io.File in JDK 1.4

Parameters:
path - The path to be corrected
isDirectory - Does the path lead to a directory?
Returns:
The corrected path String

createImage

protected java.awt.Image createImage(java.io.InputStream imgStream)
Returns an Image, or null if the path was invalid.

Parameters:
imgStream - The InputStream from which the image is to be read
Returns:
The Image created from the InputStream

getDefaultEncoding

public java.lang.String getDefaultEncoding()
Get the default file encoding (UTF8 unless modified)

Returns:
the encoding

setDefaultEncoding

public void setDefaultEncoding(java.lang.String encoding)
Set the default file encoding (UTF8 unless modified) see http://java.sun.com/j2se/1.4.2/docs/guide/intl/encoding.doc.html

Parameters:
encoding - the encoding e.g. "UTF8" or "ISO-8859-1"

setResourceBundleLoader

public void setResourceBundleLoader(ResourceBundleLoader loader)
Set the object to load language resource bundles

Parameters:
loader - the new loader

getResourceBundleLoader

public ResourceBundleLoader getResourceBundleLoader()
Get the resource bundle loader

Returns:
the loader

getResourceBundle

public java.util.ResourceBundle getResourceBundle(java.lang.String name)
Get a resource bundle

Parameters:
name - the unqualified name of the resource bundle
Returns:
The ResourceBundle created from the passed name

getTranslator

public XTranslator getTranslator()
Get the default translation object

Returns:
the translation object that operates on the resource bundle

getTranslator

public XTranslator getTranslator(java.lang.String name)
Get the translation object for the named bundle.

Parameters:
name - the name of the resource used for translation
Returns:
the translation object that operates on the resource bundle

setDefaultFile

public void setDefaultFile(java.lang.String file)
Set the default file/directory specification used to locate files by the getOutputStream( String file, boolean useProjectParent ) method

Parameters:
file - the file or directory specification

fixError

public void fixError(java.lang.String errorName,
                     java.lang.Object sourceObj,
                     java.lang.Throwable t)
Attempt to fix an error when running a XUI application

Parameters:
errorName - the name of the error, this should correzpond to a fully qualified class name or a class within the net.xoetrope.selfhealing package
sourceObj - the instance of the class from which the error handler was invoked, or the object being repaired
t - throwable the exception that was trapped, or null