1 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 ; 23 import java.io.StringReader ; 24 25 32 public abstract class AbstractContainerContext implements UMOContainerContext 33 { 34 37 protected transient Log logger = LogFactory.getLog(getClass()); 38 39 private String name; 40 41 protected AbstractContainerContext(String name) 42 { 43 this.name = name; 44 } 45 46 public String getName() 47 { 48 return name; 49 } 50 51 public void setName(String name) 52 { 53 this.name = name; 54 } 55 56 public void initialise() throws InitialisationException 57 { 58 } 60 61 public void dispose() 62 { 63 } 65 66 public final void configure(Reader configuration, String doctype, String encoding) 67 throws ContainerException 68 { 69 String 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 declaration = new StringReader (decl + SystemUtils.LINE_SEPARATOR + doctype); 88 ChainedReader reader = new ChainedReader(declaration, configuration); 89 configure(reader); 90 91 } 92 93 protected String getXmlDeclaration(String 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 getDefaultDocType() 103 { 104 return null; 105 } 106 107 protected String getDefaultEncoding() 108 { 109 return MuleManager.getConfiguration().getEncoding(); 110 } 111 112 public abstract void configure(Reader configuration) throws ContainerException; 113 } 114 | Popular Tags |