Coverage Report - org.mule.impl.container.AbstractContainerContext
 
Classes in this File Line Coverage Branch Coverage Complexity
AbstractContainerContext
26%
7/27
0%
0/8
1.4
 
 1  
 /*
 2  
  * $Id: AbstractContainerContext.java 7963 2007-08-21 08:53:15Z dirk.olmes $
 3  
  * --------------------------------------------------------------------------------------
 4  
  * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.com
 5  
  *
 6  
  * The software in this package is published under the terms of the CPAL v1.0
 7  
  * license, a copy of which has been included with this distribution in the
 8  
  * LICENSE.txt file.
 9  
  */
 10  
 
 11  
 package org.mule.impl.container;
 12  
 
 13  
 import org.mule.MuleManager;
 14  
 import org.mule.umo.lifecycle.InitialisationException;
 15  
 import org.mule.umo.manager.ContainerException;
 16  
 import org.mule.umo.manager.UMOContainerContext;
 17  
 import org.mule.util.ChainedReader;
 18  
 import org.mule.util.SystemUtils;
 19  
 
 20  
 import java.io.Reader;
 21  
 import java.io.StringReader;
 22  
 
 23  
 import org.apache.commons.logging.Log;
 24  
 import org.apache.commons.logging.LogFactory;
 25  
 
 26  
 /**
 27  
  * <code>AbstractContainerContext</code> provides base container configuration
 28  
  * functions for handling embedded configuration.
 29  
  */
 30  
 public abstract class AbstractContainerContext implements UMOContainerContext
 31  
 {
 32  
     /**
 33  
      * logger used by this class
 34  
      */
 35  794
     protected transient Log logger = LogFactory.getLog(getClass());
 36  
 
 37  
     private String name;
 38  
 
 39  
     protected AbstractContainerContext(String name)
 40  794
     {
 41  794
         this.name = name;
 42  794
     }
 43  
 
 44  
     public String getName()
 45  
     {
 46  1568
         return name;
 47  
     }
 48  
 
 49  
     public void setName(String name)
 50  
     {
 51  0
         this.name = name;
 52  0
     }
 53  
 
 54  
     public void initialise() throws InitialisationException
 55  
     {
 56  
         // noop
 57  2
     }
 58  
 
 59  
     public void dispose()
 60  
     {
 61  
         // noop
 62  784
     }
 63  
 
 64  
     public final void configure(Reader configuration, String doctype, String encoding)
 65  
         throws ContainerException
 66  
     {
 67  0
         String decl = getXmlDeclaration(encoding);
 68  0
         logger.debug("Using Xml declaration: " + decl);
 69  0
         if (doctype == null)
 70  
         {
 71  0
             doctype = getDefaultDocType();
 72  
         }
 73  0
         if (doctype != null)
 74  
         {
 75  0
             if (!doctype.startsWith("<!DOCTYPE"))
 76  
             {
 77  0
                 doctype = "<!DOCTYPE " + doctype + ">";
 78  
             }
 79  0
             logger.info("Using doctype: " + doctype);
 80  
         }
 81  
         else
 82  
         {
 83  0
             doctype = "";
 84  
         }
 85  0
         StringReader declaration = new StringReader(decl + SystemUtils.LINE_SEPARATOR + doctype);
 86  0
         ChainedReader reader = new ChainedReader(declaration, configuration);
 87  0
         configure(reader);
 88  
 
 89  0
     }
 90  
 
 91  
     protected String getXmlDeclaration(String encoding)
 92  
     {
 93  0
         if (encoding == null)
 94  
         {
 95  0
             encoding = getDefaultEncoding();
 96  
         }
 97  0
         return "<?xml version=\"1.0\" encoding=\"" + encoding.toUpperCase() + "\"?>";
 98  
     }
 99  
 
 100  
     protected String getDefaultDocType()
 101  
     {
 102  0
         return null;
 103  
     }
 104  
 
 105  
     protected String getDefaultEncoding()
 106  
     {
 107  0
         return MuleManager.getConfiguration().getEncoding();
 108  
     }
 109  
 
 110  
     public abstract void configure(Reader configuration) throws ContainerException;
 111  
 }