MATSIM
Public Member Functions | Static Public Attributes | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
org.matsim.lanes.LanesReader Class Reference
Inheritance diagram for org.matsim.lanes.LanesReader:
Inheritance graph
[legend]

Public Member Functions

 LanesReader (Scenario scenario)
 
void readFile (final String filename)
 
void readURL (final URL url)
 

Static Public Attributes

static final String SCHEMALOCATIONV11 = "http://www.matsim.org/files/dtd/laneDefinitions_v1.1.xsd"
 
static final String SCHEMALOCATIONV20 = "http://www.matsim.org/files/dtd/laneDefinitions_v2.0.xsd"
 

Private Member Functions

void parse (InputStream stream) throws JAXBException, SAXException
 

Private Attributes

Lanes lanes
 
LanesFactory factory
 
final ObjectAttributesConverter attributesConverter = new ObjectAttributesConverter()
 

Static Private Attributes

static final Logger log = LogManager.getLogger(LanesReader.class)
 

Detailed Description

Author
dgrether

Definition at line 51 of file LanesReader.java.

Constructor & Destructor Documentation

◆ LanesReader()

org.matsim.lanes.LanesReader.LanesReader ( Scenario  scenario)

Definition at line 65 of file LanesReader.java.

References org.matsim.lanes.Lanes.getFactory(), and org.matsim.api.core.v01.Scenario.getLanes().

65  {
66  this.lanes = scenario.getLanes();
67  this.factory = lanes.getFactory();
68  }
LanesFactory getFactory()
Here is the call graph for this function:

Member Function Documentation

◆ readFile()

void org.matsim.lanes.LanesReader.readFile ( final String  filename)

Implements org.matsim.core.api.internal.MatsimReader.

Definition at line 71 of file LanesReader.java.

References org.matsim.core.utils.io.IOUtils.getInputStream(), org.matsim.lanes.LanesReader.parse(), and org.matsim.core.utils.io.IOUtils.resolveFileOrResource().

71  {
72  try {
73  log.info("reading file " + filename);
74  InputStream inputStream = IOUtils.getInputStream(IOUtils.resolveFileOrResource(filename));
75  parse(inputStream);
76  } catch (JAXBException | SAXException e) {
77  throw new RuntimeException(e);
78  }
79  }
static final Logger log
void parse(InputStream stream)
Here is the call graph for this function:

◆ readURL()

void org.matsim.lanes.LanesReader.readURL ( final URL  url)

Implements org.matsim.core.api.internal.MatsimReader.

Definition at line 82 of file LanesReader.java.

References org.matsim.core.utils.io.IOUtils.getInputStream(), and org.matsim.lanes.LanesReader.parse().

82  {
83  try {
84  log.info("reading file " + url.toString());
85  InputStream inputStream = IOUtils.getInputStream(url);
86  parse(inputStream);
87  } catch (JAXBException | SAXException e) {
88  throw new RuntimeException(e);
89  }
90  }
static final Logger log
void parse(InputStream stream)
Here is the call graph for this function:

◆ parse()

void org.matsim.lanes.LanesReader.parse ( InputStream  stream) throws JAXBException, SAXException
private

Definition at line 92 of file LanesReader.java.

References org.matsim.lanes.LanesToLinkAssignment.addLane(), org.matsim.lanes.Lanes.addLanesToLinkAssignment(), org.matsim.lanes.Lane.addToLaneId(), org.matsim.lanes.Lane.addToLinkId(), org.matsim.utils.objectattributes.ObjectAttributesConverter.convert(), org.matsim.api.core.v01.Id< T >.create(), org.matsim.lanes.LanesFactory.createLane(), org.matsim.lanes.LanesFactory.createLanesToLinkAssignment(), org.matsim.jaxb.lanedefinitions20.ObjectFactory.createXMLLaneTypeXMLCapacity(), org.matsim.jaxb.lanedefinitions20.ObjectFactory.createXMLLaneTypeXMLStartsAt(), org.matsim.utils.objectattributes.attributable.Attributable.getAttributes(), org.matsim.utils.objectattributes.attributable.Attributes.putAttribute(), org.matsim.lanes.Lane.setAlignment(), org.matsim.lanes.Lane.setCapacityVehiclesPerHour(), org.matsim.lanes.Lane.setNumberOfRepresentedLanes(), and org.matsim.lanes.Lane.setStartsAtMeterFromLinkEnd().

Referenced by org.matsim.lanes.LanesReader.readFile(), and org.matsim.lanes.LanesReader.readURL().

92  {
93  ObjectFactory fac = new ObjectFactory();
94  JAXBContext jc = JAXBContext.newInstance(org.matsim.jaxb.lanedefinitions20.ObjectFactory.class);
95  Unmarshaller u = jc.createUnmarshaller();
96  u.setSchema(SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI).newSchema(getClass().getResource("/dtd/laneDefinitions_v2.0.xsd")));
97 
98  XMLLaneDefinitions xmlLaneDefinitions;
99  try {
100  xmlLaneDefinitions = (XMLLaneDefinitions) u.unmarshal(stream);
101  }
102  finally {
103  try {
104  if (stream != null) { stream.close(); }
105  } catch (IOException e) {
106  log.warn("Could not close stream.", e);
107  }
108  }
109 
110  //convert the parsed xml-instances to basic instances
111  for (XMLLanesToLinkAssignmentType lldef : xmlLaneDefinitions
112  .getLanesToLinkAssignment()) {
113  LanesToLinkAssignment l2lAssignment = factory.createLanesToLinkAssignment(Id.create(lldef
114  .getLinkIdRef(), Link.class));
115  for (XMLLaneType laneType : lldef.getLane()) {
116  Lane lane = factory.createLane(Id.create(laneType.getId(), Lane.class));
117 
118  if (!laneType.getLeadsTo().getToLane().isEmpty()) {
119  for (XMLIdRefType toLaneId : laneType.getLeadsTo().getToLane()){
120  lane.addToLaneId(Id.create(toLaneId.getRefId(), Lane.class));
121  }
122  }
123  else if (!laneType.getLeadsTo().getToLink().isEmpty()){
124  for (XMLIdRefType toLinkId : laneType.getLeadsTo().getToLink()){
125  lane.addToLinkId(Id.create(toLinkId.getRefId(), Link.class));
126  }
127  }
128 
129  if (laneType.getCapacity() == null){
130  log.warn("Capacity not set in lane definition, using default...");
131  laneType.setCapacity(fac.createXMLLaneTypeXMLCapacity());
132  }
133  lane.setCapacityVehiclesPerHour(laneType.getCapacity().getVehiclesPerHour());
134 
135  if (laneType.getRepresentedLanes() == null) {
136  laneType.setRepresentedLanes(fac
137  .createXMLLaneTypeXMLRepresentedLanes());
138  }
139  lane.setNumberOfRepresentedLanes(laneType.getRepresentedLanes()
140  .getNumber());
141 
142  if (laneType.getStartsAt() == null) {
143  laneType.setStartsAt(fac.createXMLLaneTypeXMLStartsAt());
144  }
145  lane.setStartsAtMeterFromLinkEnd(laneType.getStartsAt().getMeterFromLinkEnd());
146 
147  lane.setAlignment(laneType.getAlignment());
148 
149  if (laneType.getAttributes()!=null && !laneType.getAttributes().getAttributeList().isEmpty()) {
150  for (XMLAttributeType att : laneType.getAttributes().getAttributeList()){
151  Object attribute = attributesConverter.convert(att.getClazz(), att.getValue());
152  // Note: when I refactored this, the behavior was that if a converter was not found,
153  // the attribute was read as String. This is inconsistent with the way attributes are read normally,
154  // and I cannot see a use for it, so I just ignored the attribute, as is done in other readers.
155  // td, apr 18
156  if (attribute != null) lane.getAttributes().putAttribute(att.getName(), attribute);
157  }
158  }
159 
160  l2lAssignment.addLane(lane);
161  }
162  this.lanes.addLanesToLinkAssignment(l2lAssignment);
163  }
164  }
final ObjectAttributesConverter attributesConverter
static final Logger log
Lane createLane(Id< Lane > laneId)
void addLanesToLinkAssignment(LanesToLinkAssignment assignment)
void addToLaneId(Id< Lane > id)
LanesToLinkAssignment createLanesToLinkAssignment(Id< Link > linkIdReference)
Here is the call graph for this function:

Member Data Documentation

◆ log

final Logger org.matsim.lanes.LanesReader.log = LogManager.getLogger(LanesReader.class)
staticprivate

Definition at line 53 of file LanesReader.java.

◆ SCHEMALOCATIONV11

final String org.matsim.lanes.LanesReader.SCHEMALOCATIONV11 = "http://www.matsim.org/files/dtd/laneDefinitions_v1.1.xsd"
static

Definition at line 56 of file LanesReader.java.

◆ SCHEMALOCATIONV20

final String org.matsim.lanes.LanesReader.SCHEMALOCATIONV20 = "http://www.matsim.org/files/dtd/laneDefinitions_v2.0.xsd"
static

Definition at line 58 of file LanesReader.java.

Referenced by org.matsim.lanes.LanesWriter.write().

◆ lanes

Lanes org.matsim.lanes.LanesReader.lanes
private

Definition at line 60 of file LanesReader.java.

◆ factory

LanesFactory org.matsim.lanes.LanesReader.factory
private

Definition at line 61 of file LanesReader.java.

◆ attributesConverter

final ObjectAttributesConverter org.matsim.lanes.LanesReader.attributesConverter = new ObjectAttributesConverter()
private

Definition at line 63 of file LanesReader.java.


The documentation for this class was generated from the following file: