1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package de.smartics.properties.config.transfer.templatestream;
17
18 import org.apache.commons.lang.StringEscapeUtils;
19 import org.apache.commons.lang.StringUtils;
20
21
22
23
24
25 public class JBoss7NamingFactory extends Factory
26 {
27
28
29
30
31
32
33
34
35
36
37 public static final String DEFAULT_JNDI_PREFIX =
38 "java:/smartics-properties/config";
39
40
41
42
43
44
45 private String jndiPrefix = DEFAULT_JNDI_PREFIX;
46
47
48
49
50 private final ValueEscaper escaper = new JndiValueEscaper();
51
52
53
54
55
56
57
58
59 public JBoss7NamingFactory()
60 {
61 setLineIntro(" <!-- source: ${location} -->${newline}");
62 setEscaper(escaper);
63
64 internalSetTemplate(jndiPrefix);
65 }
66
67
68
69
70
71
72 private final class JndiValueEscaper implements ValueEscaper
73 {
74 @Override
75 public String escapeConfigKey(final String value)
76 {
77 final String normValue = StringUtils.replace(value, "/", "|");
78 return escapeValue(normValue);
79 }
80
81 @Override
82 public String escapeName(final String value)
83 {
84 final String normValue = StringUtils.replace(value, ".", "/");
85 return escapeValue(normValue);
86 }
87
88 @Override
89 public String escapeValue(final String value)
90 {
91 return StringEscapeUtils.escapeXml(value);
92 }
93 }
94
95
96
97
98
99 private void internalSetTemplate(final String jndiPrefix)
100 {
101 final String template =
102 " <simple name=\""
103 + jndiPrefix
104 + "/${configKey}/${name}\" value=\"${value}\" type=\"java.lang.String\"/>${newline}";
105 setTemplate(template);
106 }
107
108
109
110
111
112
113
114
115 public String getJndiPrefix()
116 {
117 return jndiPrefix;
118 }
119
120
121
122
123
124
125 public void setJndiPrefix(final String jndiPrefix)
126 {
127 this.jndiPrefix = jndiPrefix;
128 internalSetTemplate(jndiPrefix);
129 }
130
131
132
133
134
135
136
137
138 @Override
139 public StreamPropertySink create() throws IllegalStateException
140 {
141 setDocumentIntro("<!-- Add this XML fragment inside the ${newline}"
142 + " <subsystem xmlns=\"urn:jboss:domain:naming:1.1\">${newline}"
143 + " <bindings>${newline}" + "-->${newline}${newline}");
144 setDocumentExtro("<!--${newline} </bindings>${newline} </subsystem>${newline}-->${newline}");
145
146 return super.create();
147 }
148
149
150
151 }