Changeset 2661
- Timestamp:
- 03/07/13 11:23:41 (11 years ago)
- Location:
- vlo/branches/vlo-2.13-param/vlo_importer
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
vlo/branches/vlo-2.13-param/vlo_importer/src/main/java/eu/clarin/cmdi/vlo/config/ConfigFilePersister.java
r2657 r2661 4 4 import java.io.File; 5 5 import java.io.InputStream; 6 import java.util.logging.Level; 6 7 import org.simpleframework.xml.core.Persister; 7 8 … … 70 71 71 72 /** 72 * The name of the XML file defining the members of the annotated class 73 * The absolute name of the XML file defining the members of the annotated 74 * class. 73 75 */ 74 76 private String fileName; … … 132 134 public Object ConfigFromFile() { 133 135 134 // may be change the name of to something reflecting the stream idea136 Object object = null; 135 137 136 Object object; 138 // try to resolve the absolute name of configuration file to a stream 139 InputStream sourceAsStream; 140 sourceAsStream = ConfigFilePersister.class.getResourceAsStream(fileName); 137 141 138 // File configSource; 139 // configSource = new File(fileName); 140 141 // configSource = new InputStream(filename); 142 143 // seems to be clean, that is: without reference to context 144 145 // configSource = getClass().getClassLoader().getResourceAsStream(fileName); 146 147 Class c = null; 148 try { 149 c = Class.forName("eu.clarin.cmdi.vlo.config.ConfigFilePersister"); 150 } catch (Exception ex) { 151 // This should not happen. 152 } 153 154 /** 155 * The point is that here some merging will take place. Find a suitable 156 * name for c. Another point is that now the filename should take the 157 * place of the absName 158 */ 142 if (sourceAsStream == null) { 159 143 160 String absName = "/VloConfig.xml"; 161 162 InputStream configSource = c.getResourceAsStream(absName); 163 164 try { 165 // object = persister.read(configClass, configSource); 166 object = persister.read(configClass, configSource, true); 167 } catch (Exception e) { 168 object = null; 169 logger.log(e); 144 // the resource cannot be found inside the package, try outside 145 File sourceAsFile; 146 147 sourceAsFile = new File(fileName); 148 try { 149 object = persister.read(configClass, sourceAsFile, true); 150 } catch (Exception e) { 151 logger.log(e); 152 } 153 154 } else { 155 // the resource can be found in eu.clarin.cmdi.vlo.config 156 try { 157 object = persister.read(configClass, sourceAsStream, true); 158 } catch (Exception e) { 159 logger.log(e); 160 } 170 161 } 171 162 -
vlo/branches/vlo-2.13-param/vlo_importer/src/main/java/eu/clarin/cmdi/vlo/config/ConfigFromFile.java
r2600 r2661 37 37 * Configure by reading from an XML file 38 38 * 39 * @param fileName 39 * @param fileName the absolute name of the file to read the configuration 40 * from, for example the packaged configuration file /VloConfig.xml 40 41 * 41 42 * @param config the object whose annotated members will be assigned a value -
vlo/branches/vlo-2.13-param/vlo_importer/src/main/java/eu/clarin/cmdi/vlo/config/VloConfig.java
r2660 r2661 10 10 import org.slf4j.LoggerFactory; 11 11 12 13 /** 14 15 */ 16 12 17 /** 13 18 * VLO configuration<br><br> … … 40 45 * after 41 46 * 42 * {@literal VloConfig.read();}<br><br> 43 * 44 * or 45 * 46 * {@literal VloConfig.read();}<br><br> 47 * {@literal VloConfig.readPackagedConfig();}<br><br> 47 48 * 48 49 * has been issued from a certain context, you can reference a parameter by … … 51 52 * 52 53 * in any scope, also the scope from which the read message was send. 54 * 55 * 56 * 57 * Move the following remarks to a general remark in the class description, a 58 * remark indicating what you could do if you do not want to use the packaged 59 * configuration. 60 * 61 * 62 * Here, modifications of the parameters inspired on the difference 63 * in context can be made. 64 * 65 * A web application can serve as a typical example of a difference in context: 66 * the application itself runs in a web server container, while the tests 67 * associated with the web application will be run outside this container. * 68 * 69 * 53 70 * 54 71 * Through the get and set methods, the application is indifferent to the origin … … 114 131 115 132 /** 116 * Create a static reference to the class itself to collect the members117 * denoting parameters. Because these members themselves are static, the118 * reference will point the a fixed set of parameters. Please note that the119 * reference needs to be a protected reference because of access from one120 * of the extending VloWebApp class.121 */122 protected static VloConfig config = null;123 124 /**125 133 * Read the configuration from the packaged XML configuration file. 126 134 * 127 * @param fileName the name of the file to read the configuration from 128 * 129 * @return the configuration 135 * @param fileName the name of the file to read the configuration from 130 136 */ 131 137 public static void readPackagedConfig() { 132 138 133 139 // set the name of the packaged configuration file 134 String fileName = "/VloConfig ";140 String fileName = "/VloConfig.xml"; 135 141 136 142 VloConfig.readConfig (fileName); 137 138 // return config; 139 } 140 141 /** 142 * Read the configuration from an XML file. 143 * 144 * Please invoke this method if you want a configuration different from 145 * the one that is represented in the packages XML file. 143 } 144 145 // VLO application configuration 146 static VloConfig config = null; 147 148 /** 149 * Read the configuration from a file. 150 * 151 * Please invoke this method instead of readPackagedConfig if you want to 152 * read the configuration from a file external to the VloConfig package. 146 153 * 147 154 * @param fileName the name of the file to read the configuration from 148 *149 * @return the configuration150 155 */ 151 156 public static void readConfig(String fileName) { 152 153 // may it is safe to first expand the name a litte bit more154 157 155 158 if (config == null) { … … 158 161 } 159 162 160 // get the XML file configuration from the file by invoking ...163 // get the XML file configuration from the file 161 164 read(fileName, config); 162 165 } 163 164 /**165 * Read the configuration from an XML file.166 *167 * Move the following remarks to a general remark in the class description,168 * a remark indicating what you could do if you do not want to use the169 * packaged configuration.170 *171 * Invoke this method instead of readConfig() if you want to change172 * the parameters because the application is run in a context different173 * from the usual one. Here, modifications of the parameters inspired on174 * the difference in context can be made.175 *176 * A web application can serve as a typical example of a difference in177 * context: the application itself runs in a web server container, while the178 * tests associated with the web application will be run outside this179 * container.180 *181 */182 166 183 167 /** … … 199 183 @ElementList // directive for Simple 200 184 private static List<DataRoot> dataRoots; 201 202 public static List<DataRoot> getDataRoots() {203 return dataRoots;204 }205 185 206 186 @Element … … 277 257 * application. 278 258 */ 259 public static List<DataRoot> getDataRoots() { 260 return dataRoots; 261 } 279 262 280 263 /** -
vlo/branches/vlo-2.13-param/vlo_importer/xsdMapping.txt
r2657 r2661 1 This file is generated on Mar 1, 2013 2:41:50PM and only used to document the mapping.1 This file is generated on Mar 7, 2013 12:22:39 PM and only used to document the mapping. 2 2 This file contains xsd name and a list of conceptName with xpath mappings that are generated. 3 3 ---------------------
Note: See TracChangeset
for help on using the changeset viewer.