Changeset 4510


Ignore:
Timestamp:
02/13/14 14:57:31 (10 years ago)
Author:
twagoo
Message:

Completed vlo config factories

Location:
vlo/branches/vlo-3.0/vlo-commons/src/main/java/eu/clarin/cmdi/vlo/config
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • vlo/branches/vlo-3.0/vlo-commons/src/main/java/eu/clarin/cmdi/vlo/config/DefaultVloConfigFactory.java

    r4509 r4510  
    1717package eu.clarin.cmdi.vlo.config;
    1818
     19import java.io.IOException;
    1920import java.io.InputStream;
    2021import javax.xml.bind.JAXBException;
     
    3940
    4041    public VloConfig newConfig() {
    41         InputStream configResourceStream = getClass().getResourceAsStream(DEFAULT_CONFIG_RESOURCE);
    4242        try {
    43             return marshaller.unmarshal(new StreamSource(configResourceStream));
    44         } catch (JAXBException ex) {
    45             throw new RuntimeException("Could not read default configuration due to deserialization error", ex);
     43            InputStream configResourceStream = getClass().getResourceAsStream(DEFAULT_CONFIG_RESOURCE);
     44            try {
     45                return marshaller.unmarshal(new StreamSource(configResourceStream));
     46            } catch (JAXBException ex) {
     47                throw new RuntimeException("Could not read default configuration due to deserialization error", ex);
     48            } finally {
     49                configResourceStream.close();
     50            }
     51        } catch (IOException ex) {
     52            throw new RuntimeException("Could not close stream to default configuration", ex);
    4653        }
    4754    }
  • vlo/branches/vlo-3.0/vlo-commons/src/main/java/eu/clarin/cmdi/vlo/config/XmlVloConfigFactory.java

    r4507 r4510  
    1717package eu.clarin.cmdi.vlo.config;
    1818
     19import java.io.IOException;
     20import java.io.InputStream;
    1921import java.net.URL;
     22import javax.xml.bind.JAXBException;
     23import javax.xml.transform.stream.StreamSource;
    2024
    2125/**
     
    2529public class XmlVloConfigFactory implements VloConfigFactory {
    2630
     31    private final VloConfigMarshaller marshaller;
    2732    private final URL configLocation;
    2833
    2934    public XmlVloConfigFactory(URL configLocation) {
    3035        this.configLocation = configLocation;
     36        try {
     37            this.marshaller = new VloConfigMarshaller();
     38        } catch (JAXBException ex) {
     39            throw new RuntimeException("Could not instantiate configuration marshaller while constructing configuration factory", ex);
     40        }
    3141    }
    3242
    3343    public VloConfig newConfig() {
    34         //TODO: Unmarshal from file
    35         throw new UnsupportedOperationException("Not supported yet.");
     44        try {
     45            final InputStream fileStream = configLocation.openStream();
     46            try {
     47                return marshaller.unmarshal(new StreamSource(fileStream));
     48            } catch (JAXBException ex) {
     49                throw new RuntimeException("Could not deserialize configuration file", ex);
     50            } finally {
     51                fileStream.close();
     52            }
     53        } catch (IOException ex) {
     54            throw new RuntimeException("Could not read configuration file", ex);
     55        }
    3656    }
    37 
    3857}
Note: See TracChangeset for help on using the changeset viewer.