Open main menu

CDOT Wiki β

Facade

Revision as of 15:58, 25 January 2007 by Smcavoy (talk | contribs) (Apache Excalibur)

Facade Pattern

The Facade Pattern is used to consolidate numerous complicated objects and function calls in a single interface.

UML Example

Code Examples

Java

C++

C# .NET

VB .NET

Open Source Applications

Apache Excalibur

/**

* A facade to the modularized *LoggerManager building system.
* Add methods here to create LoggerManagers to your preference.
*
* @author <a href="mailto:dev@nospamavalon.apache.org">Avalon Development Team</a>
* @version CVS $Revision: 1.3 $ $Date: 2004/03/10 13:54:50 $
* @since 4.0
*/

public class Facade {

   /**
    * Assemble a new LoggerManager running on top of LogKit
    * configured from a configuration file logging to a supplied
    * logger as a fallback.
    * Use this method as a sample showing how to assemble your
    * own LoggerManager running on top of LogKit flavour.
    */
   public static LoggerManager createLogKitConfigurable(
           final String prefix, final String switchTo )
   {
       final org.apache.log.Hierarchy hierarchy = new Hierarchy();
       final LoggerManager bare = new LogKitAdapter( hierarchy );
       final LoggerManager decorated = applyDecorators( bare, prefix, switchTo );
       final LoggerManagerTee tee = new LoggerManagerTee( decorated );
       tee.addTee( new LogKitLoggerHelper( hierarchy ) );
       tee.addTee( new LogKitConfHelper( hierarchy ) );
       tee.makeReadOnly();
       return tee;
   }
   /**
    * Assemble LoggerManager for Log4J system configured
    * via a configuration file. All the logging errors
    * will go to System.err however.
    */
   public static LoggerManager createLog4JConfigurable(
           final String prefix, final String switchTo )
   {
       final LoggerManager bare = new Log4JConfAdapter();
       final LoggerManager decorated = applyDecorators( bare, prefix, switchTo );
       return decorated;
   }
   private static LoggerManager applyDecorators( LoggerManager target,
           final String prefix, final String switchTo )
   {
       if ( switchTo != null )
       {
           target = new LogToSelfDecorator( target, switchTo );
       }
       if ( prefix != null && prefix.length() > 0 )
       {
           target = new PrefixDecorator( target, prefix );
       }
       target = new CachingDecorator( target );
       return target;
   }

}

Apache Tomcat

Links