Revision a6cf7618 gss/src/gr/ebs/gss/server/configuration/GSSConfigurationFactory.java
b/gss/src/gr/ebs/gss/server/configuration/GSSConfigurationFactory.java | ||
---|---|---|
18 | 18 |
*/ |
19 | 19 |
package gr.ebs.gss.server.configuration; |
20 | 20 |
|
21 |
import java.io.File; |
|
22 |
import java.net.MalformedURLException; |
|
23 |
import java.net.URL; |
|
24 |
|
|
21 | 25 |
import org.apache.commons.configuration.ConfigurationException; |
26 |
import org.apache.commons.configuration.ConfigurationUtils; |
|
22 | 27 |
import org.apache.commons.configuration.DataConfiguration; |
23 | 28 |
import org.apache.commons.configuration.PropertiesConfiguration; |
24 | 29 |
import org.apache.commons.configuration.reloading.FileChangedReloadingStrategy; |
... | ... | |
78 | 83 |
gssConfig.setBasePath(""); |
79 | 84 |
gssConfig.setFileName(configFilename); |
80 | 85 |
gssConfig.setEncoding("ISO-8859-7"); |
81 |
// Set automatic reloading |
|
82 |
gssConfig.setReloadingStrategy(new FileChangedReloadingStrategy()); |
|
86 |
// Set automatic reloading.
|
|
87 |
gssConfig.setReloadingStrategy(new VfsFileChangedReloadingStrategy());
|
|
83 | 88 |
gssConfig.load(); |
84 |
// Decorator |
|
89 |
// Decorator.
|
|
85 | 90 |
configuration = new DataConfiguration(gssConfig); |
86 | 91 |
} |
87 | 92 |
return configuration; |
... | ... | |
95 | 100 |
} |
96 | 101 |
} |
97 | 102 |
|
103 |
/** |
|
104 |
* Extends the FileChangedReloadingStrategy from Commons Configuration, adding |
|
105 |
* support for files in JBoss MC VFS. |
|
106 |
* |
|
107 |
* @author past |
|
108 |
*/ |
|
109 |
private static class VfsFileChangedReloadingStrategy extends FileChangedReloadingStrategy { |
|
110 |
/** Constant for the jar URL protocol.*/ |
|
111 |
private static final String JAR_PROTOCOL = "jar"; |
|
112 |
/** Constant for the JBoss MC VFSFile URL protocol.*/ |
|
113 |
private static final String VFSFILE_PROTOCOL = "vfsfile"; |
|
114 |
|
|
115 |
@Override |
|
116 |
protected File getFile() |
|
117 |
{ |
|
118 |
return configuration.getURL() != null ? fileFromURL(configuration |
|
119 |
.getURL()) : configuration.getFile(); |
|
120 |
} |
|
121 |
|
|
122 |
/** |
|
123 |
* Helper method for transforming a URL into a file object. This method |
|
124 |
* handles file: and jar: URLs, as well as JBoss VFS-specific vfsfile: |
|
125 |
* URLs. |
|
126 |
* |
|
127 |
* @param url the URL to be converted |
|
128 |
* @return the resulting file or <b>null </b> |
|
129 |
*/ |
|
130 |
private File fileFromURL(URL url) |
|
131 |
{ |
|
132 |
if (VFSFILE_PROTOCOL.equals(url.getProtocol())) |
|
133 |
{ |
|
134 |
String path = url.getPath(); |
|
135 |
try |
|
136 |
{ |
|
137 |
return ConfigurationUtils.fileFromURL(new URL("file:" + path)); |
|
138 |
} |
|
139 |
catch (MalformedURLException mex) |
|
140 |
{ |
|
141 |
return null; |
|
142 |
} |
|
143 |
} |
|
144 |
else if (JAR_PROTOCOL.equals(url.getProtocol())) |
|
145 |
{ |
|
146 |
String path = url.getPath(); |
|
147 |
try |
|
148 |
{ |
|
149 |
return ConfigurationUtils.fileFromURL(new URL(path.substring(0, |
|
150 |
path.indexOf('!')))); |
|
151 |
} |
|
152 |
catch (MalformedURLException mex) |
|
153 |
{ |
|
154 |
return null; |
|
155 |
} |
|
156 |
} else |
|
157 |
return ConfigurationUtils.fileFromURL(url); |
|
158 |
} |
|
159 |
} |
|
98 | 160 |
} |
Also available in: Unified diff