Implementation of SimStadtRepository

From SIMSTADT
Jump to: navigation, search

Contents

[edit] Overview

Module SimStadtRepository has three responsibilities:

  • Administration of SimStadt projects and models
  • Access to models via the central class SimStadtModel
  • Administration and access to so called libraries, that is XML files providing enumerations, default values, type mappings etc. about building physics, building usage, and so on.

The project structure should look like this:

Workflow Implementation ProjectStructure.jpg

[edit] Running tests with JUnit

To test the functions to read the building physics library from an xml file and convert them into Java objects right click above class test.LoadSimlib and execute "Run as -> JUnit Test". The result should be some output in the console and report in the JUnit pane indicating which test cases have passed and which did not work as expected:

Workflow Implementation JUnitTests.jpg

[edit] Edit and validate a building physics library

An building physics library example is stored in "simlibGermanyIWU2005.xml" according to the xml schema file "SimStadtLibraries.xsd". While importing them, e.g. when executing tests, the xml file is validated against its schema. Take this fragment of the library as an example.

	. . .
	<buildingType id="SFH">
		<outWalls>
			<windowRatio>0.2</windowRatio>
			<shortWaveReflectance>0.2</shortWaveReflectance>
		</outWalls>
		<groundShell>
			<windowRatio>0.0</windowRatio>
		</groundShell>
		<pitchedRoof>
			<windowRatio>0.1</windowRatio>
			<shortWaveReflectance>0.2</shortWaveReflectance>
		</pitchedRoof>
		<flatRoof>
			<windowRatio>0.0</windowRatio>
		</flatRoof>
		<description>Single Family House</description>
		<buildingYearRange toInclusive="1918">
			<averageStoreysHeight>2.6</averageStoreysHeight>
			<buildingEffectiveThermalCapacity>130</buildingEffectiveThermalCapacity>
			<thermalBridgeUValue>0.1</thermalBridgeUValue>
			<undirectHeatedArea>0.0</undirectHeatedArea>
			<outWalls>
				<constructionTypeId>1</constructionTypeId>
				<windowTypeId>wt3</windowTypeId>
				<uValue>1.7</uValue>
			</outWalls>
	. . .

If you change the <windowTypeId> from wt3 to wt33, save the file and run the tests, they will fail, because no window type with id wt33 is defined in the library. You may also notice that in the moment you type "wt33", a red error badge appears at the right margin of the editor. Hoover over it to see the error message. This is because Eclipse automatically validates xml files against their schema. (However, certain errors are only detected after issuing the command "Validate" in the context menu of an xml file.)

[edit] Change the building physics library schema and (re)generate Java sources accordingly

XML schemas like the above may change from time to time. It would be quite cumbersome to manually adapt the Java sources for import and export of xml files that are instances of the schema. For this reason the Java Architecture for XML Binding (JAXB) let us generate the required Java classes automatically from an XML schema. To try this, simply delete all classes in package eu.simstadt.simlib.jaxb just to recognize that the project will not compile anymore. Then, right click over the schema file SimStadtRepository and execute "Generate -> JAXB Classes...". In the following dialog determine that the files will generated into project SimStadtRepository and package eu.simstadt.simlib.jaxb. Confirm all other settings. The project should compile and run as before.

Note that Subversion recognizes and indicates the generated files as changed. However, we did not change the semantics of the schema (and thus Java classes), so these files should not be committed, but reverted to the old state. To do so, right click the package node eu.simstadt.simlib and execute "Team -> Revert...".

Personal tools
Namespaces

Variants
Actions
Navigation
Toolbox