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

Completed vlo config factories

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.