com.cc.framework.ui.painter
Class PainterFactory

java.lang.Object
  extended bycom.cc.framework.ui.painter.PainterFactory
All Implemented Interfaces:
Factory, java.io.Serializable
Direct Known Subclasses:
AjaxPainterFactory, DefPainterFactory, GlobalPainterFactory, HtmlPainterFactory

public abstract class PainterFactory
extends java.lang.Object
implements Factory, java.io.Serializable

A painter factory is responsible for the rendering of HTML control elements like lists, trees or tabsets. A painter creates a special GUI layout (skin). For example the default painter from the painter.def package generates the GUI which is shown in the trial version. New user interfaces can be provided by customizing the stylesheet which comes with the default painter or by creating new painters. Customizing the stylesheets can be done in future with the ResourceFactory Tool. The application must register a painter at startup. This can be done in the application or the session scope. If a painter is registered in the application scope the GUI (skin) will be offered to all users. If a user should select between different GUI layouts (skins) the painters must be registered in the users session.

Example: register a painter in the session scope. This can be done in the logon action of the application

 // select a special painter for the user
 session.setAttribute(PainterFactory.SESSION_PAINTER, new MyPainterFactory());
 

Example: register the painter in the application scope. This can be done in the GenericServlet.init() method of the controller servlet.

 // register a painter for the application
 getServletContext().setAttribute(PainterFactory.APPLICATION_PAINTER,
 		new MyPainterFactory());
 

The framework selects a painter in the following way.

  1. Request scope
  2. Session scope
  3. Application scope
  4. If no painter will be found the the Default Painter Factory will be used DefPainterFactory

Since:
1.0
Version:
$Revision: 1.49 $
Author:
Harald Schulz
See Also:
Serialized Form

Field Summary
private static java.lang.ThreadLocal painterStackIterator
          Iterator to iterate all registered painter factories.
private  ResourceMap resources
          The Resource Map.
private static long serialVersionUID
          Serial Version UID
 
Constructor Summary
PainterFactory()
          Constructor
 
Method Summary
static ActionPainter createActionPainter(PainterContext ctx, ControlAction action)
          Creates an ActionPainter.
static FramePainter createFramePainter(ControlPainter controlPainter)
          Helper Function.
static void createHeaderIncludes(javax.servlet.jsp.PageContext pageContext)
          Creates all Include-Tags in the HTML-Pages which are necessary for the Framework to work well (css, javascripts, ...).
static ControlPainter createPainter(javax.servlet.jsp.PageContext pageContext, Control ctrl)
          Helper Function.
static PainterContext createPainterContext(javax.servlet.jsp.PageContext pageContext, Control ctrl)
          Creates the painter context
protected abstract  ResourceMap createResourceMap()
          Creates the Painters Resource Map
protected  ActionPainter doCreateActionPainter(PainterContext ctx, ControlAction action)
          Creates an ActionPainter.
protected  FramePainter doCreateFramePainter(PainterContext painterContext, Control ctrl)
          Creates a frame painter for the control specified in the argument.
protected abstract  void doCreateHeaderIncludes(javax.servlet.jsp.JspWriter writer)
          Creates all Include-Tags in the HTML-Pages which are necessary for the Framework to work well (css, javascripts, ...).
protected abstract  ControlPainter doCreatePainter(PainterContext painterContext, Control ctrl)
          Creates a painter for the control specified in the argument.
 PainterContext doCreatePainterContext(javax.servlet.jsp.PageContext pageContext, Control ctrl)
          Creates the painter context
 boolean equals(java.lang.Object obj)
           
static Color getColorResource(javax.servlet.jsp.PageContext pageContext, java.lang.String resourceKey)
          Retrieves the value for the given color key
abstract  java.lang.String getFactoryId()
          Returns an unique String which identifies the PainterFactory.
static java.util.List getFactoyStack(javax.servlet.jsp.PageContext pageContext)
          Returns the registered painter factories.
static ImageModel getImageResource(javax.servlet.jsp.PageContext pageContext, int size, java.lang.String resourceKey)
          Retrieves the value for the given resource key
static ImageModel getImageResource(javax.servlet.jsp.PageContext pageContext, java.lang.String resourceKey)
          Retrieves the value for the given resource key
 ResourceMap getResources()
          Gets the painters Resource Map
static java.lang.String getStringResource(javax.servlet.jsp.PageContext pageContext, java.lang.String resourceKey)
          Retrieves the value for the given resource key
static java.lang.String getStringResource(javax.servlet.jsp.PageContext pageContext, java.lang.String resourceKey, boolean returnNull)
          Retrieves the value for the given resource key
static java.lang.String getStringResource(javax.servlet.jsp.PageContext pageContext, java.lang.String resourceKey, java.lang.Object[] params, boolean returnNull)
          Retrieves the value for the given resource key
 int hashCode()
           
static boolean isFactorySelected(javax.servlet.jsp.PageContext pageContext, java.lang.String factoryId)
          Checks if the specified Factory is registered
protected static boolean isRegisteredInScopeList(PainterFactory painter, java.util.List painterList)
          Checks if a painter is already registered in the painter list
static java.util.Iterator iterator(javax.servlet.jsp.PageContext pageContext, boolean topDown)
          Returns an iterator to iterate all registered painter factories.
static PainterFactory lookupFactory(javax.servlet.jsp.PageContext pageContext, java.lang.String factoryId)
          Returns the specified painter factory by its factory id
static void registerApplicationPainter(javax.servlet.ServletContext ctx, PainterFactory painter)
          Registers a Painter in the Application Scope
static void registerApplicationPainters(javax.servlet.ServletContext ctx)
          Registers the global painters in the Application Scope (ajax,html and global)
static void registerRequestPainter(javax.servlet.http.HttpServletRequest request, PainterFactory painter)
          Registers a Painter in the Session Scope.
static void registerSessionPainter(javax.servlet.http.HttpSession session, PainterFactory painter)
          Registers a Painter in the Session Scope.
static void resetApplicationPainter(javax.servlet.ServletContext ctx)
          Resets the PainterFactory at application scope
static void resetSessionPainter(javax.servlet.http.HttpServletRequest request)
          Resets the PainterFactory at request scope
static void resetSessionPainter(javax.servlet.http.HttpSession session)
          Resets the PainterFactory at session scope
 java.lang.String toString()
          Returns the unique id of the painter factory
static void unregisterApplicationPainter(javax.servlet.ServletContext ctx, PainterFactory painter)
          Unregisters a Painter from the Application Scope
static void unregisterRequestPainter(javax.servlet.http.HttpServletRequest request, PainterFactory painter)
          Unregisters a Painter from the request Scope
static void unregisterSessionPainter(javax.servlet.http.HttpSession session, PainterFactory painter)
          Unregisters a Painter from the Session Scope
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

serialVersionUID

private static final long serialVersionUID
Serial Version UID

See Also:
Constant Field Values

painterStackIterator

private static java.lang.ThreadLocal painterStackIterator
Iterator to iterate all registered painter factories. The framework uses a thread local variable to improve performance since the factory stack iterator is used often by the framework.

Since the iterator is thread local you can not store it. otherwise it's internal state my be changed by another method!


resources

private ResourceMap resources
The Resource Map. It contains the local Image definitions for this painter

Constructor Detail

PainterFactory

public PainterFactory()
Constructor

Method Detail

getFactoryId

public abstract java.lang.String getFactoryId()
Returns an unique String which identifies the PainterFactory.

Returns:
The unique Id of the PainterFactory.

getResources

public ResourceMap getResources()
Gets the painters Resource Map

Returns:
Resource Map

equals

public boolean equals(java.lang.Object obj)
See Also:
Object.equals(java.lang.Object)

hashCode

public int hashCode()
See Also:
Object.hashCode()

toString

public java.lang.String toString()
Returns the unique id of the painter factory

Returns:
The unique id

createResourceMap

protected abstract ResourceMap createResourceMap()
Creates the Painters Resource Map

Returns:
The Resource Map

doCreatePainter

protected abstract ControlPainter doCreatePainter(PainterContext painterContext,
                                                  Control ctrl)
Creates a painter for the control specified in the argument. This method must be implemented by a concrete sub class.

Note: This method will be called from the PainterFactory!

Parameters:
painterContext - The context of the JSP page where the control is defined. So it is possible for the painter to get the ActionMappings if required. The ActionMappings are necessary for the generation of hyperlinks.
ctrl - The instance of the control for which a painter should be created
Returns:
The painter for the specified control

doCreateFramePainter

protected FramePainter doCreateFramePainter(PainterContext painterContext,
                                            Control ctrl)
Creates a frame painter for the control specified in the argument. This method must be implemented by a concrete sub class.

Note: This method will be called from the PainterFactory!

Parameters:
painterContext - The context of the JSP page where the control is defined. So it is possible for the painter to get the ActionMappings if required. The ActionMappings are necessary for the generation of hyperlinks.
ctrl - The instance of the control for which a frame painter should be created
Returns:
The frame painter for the specified control

doCreateActionPainter

protected ActionPainter doCreateActionPainter(PainterContext ctx,
                                              ControlAction action)
Creates an ActionPainter. The Painter is used by Controls to render Actions into the user interface

Parameters:
ctx - The Painter Context
action - ControlAction
Returns:
ActionPainter

doCreatePainterContext

public PainterContext doCreatePainterContext(javax.servlet.jsp.PageContext pageContext,
                                             Control ctrl)
Creates the painter context

Parameters:
pageContext - PageContext
ctrl - Control
Returns:
PainterContext

doCreateHeaderIncludes

protected abstract void doCreateHeaderIncludes(javax.servlet.jsp.JspWriter writer)
                                        throws java.io.IOException
Creates all Include-Tags in the HTML-Pages which are necessary for the Framework to work well (css, javascripts, ...). This Method must be overridden by a concrete Painter Class.

Parameters:
writer - The JspWriter
Throws:
java.io.IOException - If an input or output exception occurred

createHeaderIncludes

public static void createHeaderIncludes(javax.servlet.jsp.PageContext pageContext)
Creates all Include-Tags in the HTML-Pages which are necessary for the Framework to work well (css, javascripts, ...).

Parameters:
pageContext - The PageContext

createPainter

public static ControlPainter createPainter(javax.servlet.jsp.PageContext pageContext,
                                           Control ctrl)
Helper Function. Creates a Painter for the specified Control. Therefore the registered painter will be used.

Parameters:
pageContext - PageContext
ctrl - Control
Returns:
ControlPainter

createFramePainter

public static FramePainter createFramePainter(ControlPainter controlPainter)
Helper Function. Creates a Painter for the specified Control. Therefore the registered painter will be used.

Parameters:
controlPainter - The ControlPainter
Returns:
FramePainter or null

createActionPainter

public static ActionPainter createActionPainter(PainterContext ctx,
                                                ControlAction action)
Creates an ActionPainter. The Painter is used by Controls to render Actions into the user interface

Parameters:
ctx - The Painter Context
action - ControlAction
Returns:
ActionPainter

createPainterContext

public static PainterContext createPainterContext(javax.servlet.jsp.PageContext pageContext,
                                                  Control ctrl)
Creates the painter context

Parameters:
pageContext - PageContext
ctrl - Control
Returns:
PainterContext

isFactorySelected

public static boolean isFactorySelected(javax.servlet.jsp.PageContext pageContext,
                                        java.lang.String factoryId)
Checks if the specified Factory is registered

Parameters:
pageContext - The PageContext
factoryId - The unique Id of the factory
Returns:
boolean

lookupFactory

public static PainterFactory lookupFactory(javax.servlet.jsp.PageContext pageContext,
                                           java.lang.String factoryId)
Returns the specified painter factory by its factory id

Parameters:
pageContext - The PageContext
factoryId - The unique id of the factory
Returns:
painter factory instance or null

getStringResource

public static java.lang.String getStringResource(javax.servlet.jsp.PageContext pageContext,
                                                 java.lang.String resourceKey,
                                                 java.lang.Object[] params,
                                                 boolean returnNull)
Retrieves the value for the given resource key

Parameters:
pageContext - JSP Page Context
resourceKey - the resource key
params - Array with parameters for markup substitution
returnNull - controls whether to return null or a not present indicator
Returns:
value or null

getStringResource

public static java.lang.String getStringResource(javax.servlet.jsp.PageContext pageContext,
                                                 java.lang.String resourceKey,
                                                 boolean returnNull)
Retrieves the value for the given resource key

Parameters:
pageContext - JSP Page Context
resourceKey - the resource key
returnNull - controls whether to return null or a not present indicator
Returns:
value or null

getStringResource

public static java.lang.String getStringResource(javax.servlet.jsp.PageContext pageContext,
                                                 java.lang.String resourceKey)
Retrieves the value for the given resource key

Parameters:
pageContext - JSP Page Context
resourceKey - the resource key
Returns:
value or null

getColorResource

public static Color getColorResource(javax.servlet.jsp.PageContext pageContext,
                                     java.lang.String resourceKey)
Retrieves the value for the given color key

Parameters:
pageContext - JSP Page Context
resourceKey - the resource key
Returns:
value or null

getImageResource

public static ImageModel getImageResource(javax.servlet.jsp.PageContext pageContext,
                                          java.lang.String resourceKey)
Retrieves the value for the given resource key

Parameters:
pageContext - JSP Page Context
resourceKey - the resource key
Returns:
value or null

getImageResource

public static ImageModel getImageResource(javax.servlet.jsp.PageContext pageContext,
                                          int size,
                                          java.lang.String resourceKey)
Retrieves the value for the given resource key

Parameters:
pageContext - JSP Page Context
size - Image Size
resourceKey - the resource key
Returns:
value or null

iterator

public static java.util.Iterator iterator(javax.servlet.jsp.PageContext pageContext,
                                          boolean topDown)
Returns an iterator to iterate all registered painter factories. This method uses a thread local variable to improve performance since the factory stack iterator is used often by the framework.

Since the iterator is thread local you can not store it. otherwise it's internal state my be changed by another method!

Parameters:
pageContext - JSP Page Context
topDown - creates an top down iterator when true. Creates a reverse iterator when false>
Returns:
iterator for PainterFactory elements

getFactoyStack

public static java.util.List getFactoyStack(javax.servlet.jsp.PageContext pageContext)
Returns the registered painter factories.

Parameters:
pageContext - PageContext
Returns:
ordered collection of painter factories

resetSessionPainter

public static void resetSessionPainter(javax.servlet.http.HttpServletRequest request)
Resets the PainterFactory at request scope

Parameters:
request - HttpServletRequest

resetSessionPainter

public static void resetSessionPainter(javax.servlet.http.HttpSession session)
Resets the PainterFactory at session scope

Parameters:
session - HttpSession

resetApplicationPainter

public static void resetApplicationPainter(javax.servlet.ServletContext ctx)
Resets the PainterFactory at application scope

Parameters:
ctx - ServletContext

registerRequestPainter

public static void registerRequestPainter(javax.servlet.http.HttpServletRequest request,
                                          PainterFactory painter)
Registers a Painter in the Session Scope.

Parameters:
request - HttpServletRequest
painter - PainterFactory

unregisterRequestPainter

public static void unregisterRequestPainter(javax.servlet.http.HttpServletRequest request,
                                            PainterFactory painter)
Unregisters a Painter from the request Scope

Parameters:
request - HttpServletRequest
painter - PainterFactory to unregister

registerSessionPainter

public static void registerSessionPainter(javax.servlet.http.HttpSession session,
                                          PainterFactory painter)
Registers a Painter in the Session Scope.

Parameters:
session - HttpSession
painter - PainterFactory

unregisterSessionPainter

public static void unregisterSessionPainter(javax.servlet.http.HttpSession session,
                                            PainterFactory painter)
Unregisters a Painter from the Session Scope

Parameters:
session - HttpSession
painter - PainterFactory to unregister

registerApplicationPainters

public static void registerApplicationPainters(javax.servlet.ServletContext ctx)
Registers the global painters in the Application Scope (ajax,html and global)

Parameters:
ctx - ServletContext

registerApplicationPainter

public static void registerApplicationPainter(javax.servlet.ServletContext ctx,
                                              PainterFactory painter)
Registers a Painter in the Application Scope

Parameters:
ctx - ServletContext
painter - PainterFactory to register

unregisterApplicationPainter

public static void unregisterApplicationPainter(javax.servlet.ServletContext ctx,
                                                PainterFactory painter)
Unregisters a Painter from the Application Scope

Parameters:
ctx - ServletContext
painter - PainterFactory to unregister

isRegisteredInScopeList

protected static boolean isRegisteredInScopeList(PainterFactory painter,
                                                 java.util.List painterList)
Checks if a painter is already registered in the painter list

Parameters:
painter - the painter to check
painterList - the painter list to search
Returns:
returns true if the painter is already registered in the list


Copyright © 2000-2005 SCC Informationssysteme GmbH. All Rights Reserved.