EMlab-generation Documentation  1.0
Documentation of the EMLab-Generation model.
PowerPlantCSVFactory.java
1 /*******************************************************************************
2  * Copyright 2013 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  ******************************************************************************/
16 package emlab.gen.domain.factory;
17 
18 import java.io.InputStreamReader;
19 import java.util.List;
20 
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
23 import org.springframework.beans.factory.InitializingBean;
24 import org.springframework.transaction.annotation.Transactional;
25 
26 import com.googlecode.jcsv.CSVStrategy;
27 import com.googlecode.jcsv.reader.CSVReader;
28 import com.googlecode.jcsv.reader.internal.CSVReaderBuilder;
29 
34 
39 public class PowerPlantCSVFactory implements InitializingBean {
40 
41  String csvFile;
42 
43  static final Logger logger = LoggerFactory.getLogger(PowerPlantCSVFactory.class);
44 
45  private List<EnergyProducer> producers;
46 
47  private List<PowerGeneratingTechnology> technologies;
48 
49  private List<PowerGridNode> powerGridNodes;
50 
51  @Transactional
52  @Override
53  public void afterPropertiesSet() throws Exception {
54  logger.warn("Reading power plant from CSV file: " + csvFile);
55  InputStreamReader inputStreamReader = new InputStreamReader(this.getClass().getResourceAsStream(csvFile));
56 
57  CSVReader<PowerPlant> csvPersonReader = new CSVReaderBuilder<PowerPlant>(inputStreamReader).entryParser(
58  new PowerPlantEntryParser(producers, technologies, powerGridNodes))
59  .strategy(new CSVStrategy(',', '\"', '#', true, true))
60  .build();
61  List<PowerPlant> powerplants = csvPersonReader.readAll();
62  }
63 
64  public String getCsvFile() {
65  return csvFile;
66  }
67 
68  public void setCsvFile(String csvFile) {
69  this.csvFile = csvFile;
70  }
71 
72  public List<EnergyProducer> getProducers() {
73  return producers;
74  }
75 
76  public void setProducers(List<EnergyProducer> producers) {
77  this.producers = producers;
78  }
79 
80  public List<PowerGeneratingTechnology> getTechnologies() {
81  return technologies;
82  }
83 
84  public void setTechnologies(List<PowerGeneratingTechnology> technologies) {
85  this.technologies = technologies;
86  }
87 
88  public List<PowerGridNode> getPowerGridNodes() {
89  return powerGridNodes;
90  }
91 
92  public void setPowerGridNodes(List<PowerGridNode> powerGridNodes) {
93  this.powerGridNodes = powerGridNodes;
94  }
95 
96 }