Commit 35acb980 authored by Ådne Karstad's avatar Ådne Karstad

[minor] Add example of validation and loadResource

parent 445fd697
package tdt4250.spp.examples;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
import tdt4250.spp.Program;
import tdt4250.spp.Semester;
import tdt4250.spp.SppPackage;
import tdt4250.spp.University;
public class LoadResourceExample {
public static void main(String[] args) {
ResourceSet resSet = new ResourceSetImpl();
resSet.getPackageRegistry().put(SppPackage.eNS_URI, SppPackage.eINSTANCE);
resSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("xmi", new XMIResourceFactoryImpl());
Resource resource = resSet.getResource(URI.createURI(RunValidationExample.class.getResource("RunValidationExample.xmi").toString()), true);
University uni = (University) resource.getContents().get(0);
for (Program program : uni.getPrograms()) {
for (Semester sem : program.getSemesters()) {
System.out.println("Number of credits for semester " + sem.getYear() + " " + sem.getSeason() + " of program " + program.getName() + ": " + sem.getCredits());
}
}
}
}
package tdt4250.spp.examples;
import org.eclipse.emf.common.util.Diagnostic;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.emf.ecore.util.Diagnostician;
import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
import tdt4250.spp.Program;
import tdt4250.spp.SppPackage;
import tdt4250.spp.University;
public class RunValidationExample {
public static void main(String[] args) {
ResourceSet resSet = new ResourceSetImpl();
resSet.getPackageRegistry().put(SppPackage.eNS_URI, SppPackage.eINSTANCE);
resSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("xmi", new XMIResourceFactoryImpl());
Resource resource = resSet.getResource(URI.createURI(RunValidationExample.class.getResource("RunValidationExample.xmi").toString()), true);
University uni = (University) resource.getContents().get(0);
for (Program program : uni.getPrograms()) {
Diagnostic diagnostics = Diagnostician.INSTANCE.validate(program);
System.out.println(diagnostics.getMessage());
}
}
}
<?xml version="1.0" encoding="UTF-8"?>
<spp:University
xmi:version="2.0"
xmlns:xmi="http://www.omg.org/XMI"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:spp="platform:/plugin/tdt4250.spp.model/model/spp.ecore"
xsi:schemaLocation="platform:/plugin/tdt4250.spp.model/model/spp.ecore spp.ecore"
name="NTNU">
<programs
name="Lektor i realfag"
duration="IntegratedMasters">
<semesters
year="1"
selectedCourses="//@institutes.0/@courses.0"/>
<semesters
season="Spring"
year="1"
selectedCourses="//@institutes.0/@courses.4 //@institutes.1/@courses.1"/>
<semesters
season="Spring"
year="2"
selectedCourses="//@institutes.0/@courses.3"/>
<semesters
year="4"
selectedCourses="//@institutes.0/@courses.1 //@institutes.0/@courses.2"/>
<mandatoryCourses
courses="//@institutes.0/@courses.0 //@institutes.0/@courses.3"/>
</programs>
<institutes
name="Institutt for datateknologi og informatikk">
<courses
code="TDT4110"
name="Informasjonsteknologi, grunnkurs"
credits="7.5"/>
<courses
code="TDT4250"
name="Avansert programvaredesign"
credits="7.5"
level="SecoundDegreeCourse"/>
<courses
code="TDT4175"
name="Informasjonssystemer"
credits="7.5"
level="ThirdYearCourse"/>
<courses
code="TDT4140"
name="Programvareutvikling"
credits="7.5"
level="IntermediateCourse"
season="Spring"/>
<courses
code="TDT4100"
name="Objektorientert programmering"
credits="7.5"
season="Spring"/>
</institutes>
<institutes
name="Institutt for matematiske fag">
<courses
code="MA1101"
name="Grunnkurs i analyse I"
credits="7.5"/>
<courses
code="MA1102"
name="Grunnkurs i analyse II"
credits="7.5"
season="Spring"/>
</institutes>
</spp:University>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment