Changeset 2661


Ignore:
Timestamp:
03/07/13 11:23:41 (11 years ago)
Author:
keeloo
Message:

Fixed the code for accessing the parameter file via a stream.

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  
    44import java.io.File;
    55import java.io.InputStream;
     6import java.util.logging.Level;
    67import org.simpleframework.xml.core.Persister;
    78
     
    7071   
    7172    /**
    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.
    7375     */
    7476    private String fileName;
     
    132134    public Object ConfigFromFile() {
    133135       
    134         // may be change the name of to something reflecting the stream idea
     136        Object object = null;
    135137
    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);
    137141
    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) {
    159143           
    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            }
    170161        }
    171162
  • vlo/branches/vlo-2.13-param/vlo_importer/src/main/java/eu/clarin/cmdi/vlo/config/ConfigFromFile.java

    r2600 r2661  
    3737     * Configure by reading from an XML file
    3838     *
    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
    4041     *
    4142     * @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  
    1010import org.slf4j.LoggerFactory;
    1111
     12
     13    /**
     14
     15     */
     16
    1217/**
    1318 * VLO configuration<br><br>
     
    4045 * after
    4146 *
    42  * {@literal VloConfig.read();}<br><br>
    43  *
    44  * or
    45  *
    46  * {@literal VloConfig.read();}<br><br>
     47 * {@literal VloConfig.readPackagedConfig();}<br><br>
    4748 *
    4849 * has been issued from a certain context, you can reference a parameter by
     
    5152 *
    5253 * 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 *
    5370 *
    5471 * Through the get and set methods, the application is indifferent to the origin
     
    114131   
    115132    /**
    116      * Create a static reference to the class itself to collect the members
    117      * denoting parameters. Because these members themselves are static, the
    118      * reference will point the a fixed set of parameters. Please note that the
    119      * reference needs to be a protected reference because of access from one
    120      * of the extending VloWebApp class.
    121      */
    122     protected static VloConfig config = null;
    123 
    124     /**
    125133     * Read the configuration from the packaged XML configuration file. 
    126134     *
    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
    130136     */
    131137    public static void readPackagedConfig() {
    132138       
    133139        // set the name of the packaged configuration file
    134         String fileName = "/VloConfig";
     140        String fileName = "/VloConfig.xml";
    135141       
    136142        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.
    146153     *
    147154     * @param fileName the name of the file to read the configuration from
    148      *
    149      * @return the configuration
    150155     */
    151156    public static void readConfig(String fileName) {
    152        
    153         // may it is safe to first expand the name a litte bit more
    154157
    155158        if (config == null) {
     
    158161        }
    159162
    160         // get the XML file configuration from the file by invoking ...
     163        // get the XML file configuration from the file
    161164        read(fileName, config);
    162165    }
    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 the
    169      * packaged configuration.
    170      *
    171      * Invoke this method instead of readConfig() if you want to change
    172      * the parameters because the application is run in a context different
    173      * from the usual one. Here, modifications of the parameters inspired on
    174      * the difference in context can be made.
    175      *
    176      * A web application can serve as a typical example of a difference in
    177      * context: the application itself runs in a web server container, while the
    178      * tests associated with the web application will be run outside this
    179      * container.
    180      *     
    181      */
    182166
    183167    /**
     
    199183    @ElementList // directive for Simple
    200184    private static List<DataRoot> dataRoots;
    201    
    202     public static List<DataRoot> getDataRoots() {
    203         return dataRoots;
    204     }
    205185   
    206186    @Element
     
    277257     * application.
    278258     */
     259    public static List<DataRoot> getDataRoots() {
     260        return dataRoots;
     261    }
    279262   
    280263    /**
  • vlo/branches/vlo-2.13-param/vlo_importer/xsdMapping.txt

    r2657 r2661  
    1 This file is generated on Mar 1, 2013 2:41:50 PM and only used to document the mapping.
     1This file is generated on Mar 7, 2013 12:22:39 PM and only used to document the mapping.
    22This file contains xsd name and a list of conceptName with xpath mappings that are generated.
    33---------------------
Note: See TracChangeset for help on using the changeset viewer.