1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
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 | |
|
28 | |
|
29 | |
|
30 | |
public abstract class AbstractContainerContext implements UMOContainerContext |
31 | |
{ |
32 | |
|
33 | |
|
34 | |
|
35 | 0 | protected transient Log logger = LogFactory.getLog(getClass()); |
36 | |
|
37 | |
private String name; |
38 | |
|
39 | |
protected AbstractContainerContext(String name) |
40 | 0 | { |
41 | 0 | this.name = name; |
42 | 0 | } |
43 | |
|
44 | |
public String getName() |
45 | |
{ |
46 | 0 | 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 | |
|
57 | 0 | } |
58 | |
|
59 | |
public void dispose() |
60 | |
{ |
61 | |
|
62 | 0 | } |
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 | |
} |