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

Written marshaller/unmarshaller for VloConfig?

File:
1 edited

Legend:

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

    r4507 r4509  
    1515 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
    1616 */
     17package eu.clarin.cmdi.vlo.config;
    1718
    18 package eu.clarin.cmdi.vlo.config;
     19import java.io.InputStream;
     20import javax.xml.bind.JAXBException;
     21import javax.xml.transform.stream.StreamSource;
    1922
    2023/**
     
    2427public class DefaultVloConfigFactory implements VloConfigFactory {
    2528
     29    public static final String DEFAULT_CONFIG_RESOURCE = "/VloConfig.xml";
     30    private final VloConfigMarshaller marshaller;
     31
     32    public DefaultVloConfigFactory() {
     33        try {
     34            this.marshaller = new VloConfigMarshaller();
     35        } catch (JAXBException ex) {
     36            throw new RuntimeException("Could not instantiate configuration marshaller while constructing configuration factory", ex);
     37        }
     38    }
     39
    2640    public VloConfig newConfig() {
    27         return new VloConfig();
     41        InputStream configResourceStream = getClass().getResourceAsStream(DEFAULT_CONFIG_RESOURCE);
     42        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);
     46        }
    2847    }
    29    
    3048}
Note: See TracChangeset for help on using the changeset viewer.