Changeset 4510
- Timestamp:
- 02/13/14 14:57:31 (10 years ago)
- 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 17 17 package eu.clarin.cmdi.vlo.config; 18 18 19 import java.io.IOException; 19 20 import java.io.InputStream; 20 21 import javax.xml.bind.JAXBException; … … 39 40 40 41 public VloConfig newConfig() { 41 InputStream configResourceStream = getClass().getResourceAsStream(DEFAULT_CONFIG_RESOURCE);42 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); 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); 46 53 } 47 54 } -
vlo/branches/vlo-3.0/vlo-commons/src/main/java/eu/clarin/cmdi/vlo/config/XmlVloConfigFactory.java
r4507 r4510 17 17 package eu.clarin.cmdi.vlo.config; 18 18 19 import java.io.IOException; 20 import java.io.InputStream; 19 21 import java.net.URL; 22 import javax.xml.bind.JAXBException; 23 import javax.xml.transform.stream.StreamSource; 20 24 21 25 /** … … 25 29 public class XmlVloConfigFactory implements VloConfigFactory { 26 30 31 private final VloConfigMarshaller marshaller; 27 32 private final URL configLocation; 28 33 29 34 public XmlVloConfigFactory(URL configLocation) { 30 35 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 } 31 41 } 32 42 33 43 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 } 36 56 } 37 38 57 }
Note: See TracChangeset
for help on using the changeset viewer.