KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mule > impl > container > AbstractContainerContext


1 /*
2  * $Id: AbstractContainerContext.java 3798 2006-11-04 04:07:14Z aperepel $
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 MuleSource MPL
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.apache.commons.lang.SystemUtils;
14 import org.apache.commons.logging.Log;
15 import org.apache.commons.logging.LogFactory;
16 import org.mule.MuleManager;
17 import org.mule.umo.lifecycle.InitialisationException;
18 import org.mule.umo.manager.ContainerException;
19 import org.mule.umo.manager.UMOContainerContext;
20 import org.mule.util.ChainedReader;
21
22 import java.io.Reader JavaDoc;
23 import java.io.StringReader JavaDoc;
24
25 /**
26  * <code>AbstractContainerContext</code> provides base container configuration
27  * functions for handling embedded configuration
28  *
29  * @author <a HREF="mailto:ross.mason@symphonysoft.com">Ross Mason</a>
30  * @version $Revision: 3798 $
31  */

32 public abstract class AbstractContainerContext implements UMOContainerContext
33 {
34     /**
35      * logger used by this class
36      */

37     protected transient Log logger = LogFactory.getLog(getClass());
38
39     private String JavaDoc name;
40
41     protected AbstractContainerContext(String JavaDoc name)
42     {
43         this.name = name;
44     }
45
46     public String JavaDoc getName()
47     {
48         return name;
49     }
50
51     public void setName(String JavaDoc name)
52     {
53         this.name = name;
54     }
55
56     public void initialise() throws InitialisationException
57     {
58         // noop
59
}
60
61     public void dispose()
62     {
63         // noop
64
}
65
66     public final void configure(Reader configuration, String JavaDoc doctype, String JavaDoc encoding)
67         throws ContainerException
68     {
69         String JavaDoc decl = getXmlDeclaration(encoding);
70         logger.debug("Using Xml declaration: " + decl);
71         if (doctype == null)
72         {
73             doctype = getDefaultDocType();
74         }
75         if (doctype != null)
76         {
77             if (!doctype.startsWith("<!DOCTYPE"))
78             {
79                 doctype = "<!DOCTYPE " + doctype + ">";
80             }
81             logger.info("Using doctype: " + doctype);
82         }
83         else
84         {
85             doctype = "";
86         }
87         StringReader JavaDoc declaration = new StringReader JavaDoc(decl + SystemUtils.LINE_SEPARATOR + doctype);
88         ChainedReader reader = new ChainedReader(declaration, configuration);
89         configure(reader);
90
91     }
92
93     protected String JavaDoc getXmlDeclaration(String JavaDoc encoding)
94     {
95         if (encoding == null)
96         {
97             encoding = getDefaultEncoding();
98         }
99         return "<?xml version=\"1.0\" encoding=\"" + encoding.toUpperCase() + "\"?>";
100     }
101
102     protected String JavaDoc getDefaultDocType()
103     {
104         return null;
105     }
106
107     protected String JavaDoc getDefaultEncoding()
108     {
109         return MuleManager.getConfiguration().getEncoding();
110     }
111
112     public abstract void configure(Reader configuration) throws ContainerException;
113 }
114
Popular Tags