Commit 8377520b authored by Ådne Karstad's avatar Ådne Karstad

[minor] Add datatype for CourseCode with check

parent 5a644f49
......@@ -48,7 +48,7 @@
eType="#//Course"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="Course">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="code" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="code" eType="#//CourseCode"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="name" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="credits" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EFloat"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="level" eType="#//CourseLevelType"/>
......@@ -56,6 +56,7 @@
<eStructuralFeatures xsi:type="ecore:EReference" name="responsibleUnit" eType="#//Institute"
eOpposite="#//Institute/courses"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EDataType" name="CourseCode" instanceClassName="java.lang.String"/>
<eClassifiers xsi:type="ecore:EClass" name="Specialisation">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="name" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="program" eType="#//Program"
......
......@@ -23,6 +23,7 @@
<genEnumLiterals ecoreEnumLiteral="spp.ecore#//CourseLevelType/ThirdYearCourse"/>
<genEnumLiterals ecoreEnumLiteral="spp.ecore#//CourseLevelType/SecoundDegreeCourse"/>
</genEnums>
<genDataTypes ecoreDataType="spp.ecore#//CourseCode"/>
<genClasses ecoreClass="spp.ecore#//University">
<genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference spp.ecore#//University/programs"/>
<genFeatures createChild="false" ecoreFeature="ecore:EAttribute spp.ecore#//University/name"/>
......
......@@ -33,7 +33,7 @@ public interface Course extends EObject {
* @return the value of the '<em>Code</em>' attribute.
* @see #setCode(String)
* @see tdt4250.spp.SppPackage#getCourse_Code()
* @model
* @model dataType="tdt4250.spp.CourseCode"
* @generated
*/
String getCode();
......
......@@ -4,6 +4,7 @@ package tdt4250.spp;
import org.eclipse.emf.ecore.EAttribute;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EDataType;
import org.eclipse.emf.ecore.EEnum;
import org.eclipse.emf.ecore.EOperation;
import org.eclipse.emf.ecore.EPackage;
......@@ -592,6 +593,17 @@ public interface SppPackage extends EPackage {
int COURSE_LEVEL_TYPE = 10;
/**
* The meta object id for the '<em>Course Code</em>' data type.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @see java.lang.String
* @see tdt4250.spp.impl.SppPackageImpl#getCourseCode()
* @generated
*/
int COURSE_CODE = 11;
/**
* Returns the meta object for class '{@link tdt4250.spp.University <em>University</em>}'.
* <!-- begin-user-doc -->
......@@ -1041,6 +1053,17 @@ public interface SppPackage extends EPackage {
*/
EEnum getCourseLevelType();
/**
* Returns the meta object for data type '{@link java.lang.String <em>Course Code</em>}'.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @return the meta object for data type '<em>Course Code</em>'.
* @see java.lang.String
* @model instanceClass="java.lang.String"
* @generated
*/
EDataType getCourseCode();
/**
* Returns the factory that creates the instances of the model.
* <!-- begin-user-doc -->
......@@ -1422,6 +1445,16 @@ public interface SppPackage extends EPackage {
*/
EEnum COURSE_LEVEL_TYPE = eINSTANCE.getCourseLevelType();
/**
* The meta object literal for the '<em>Course Code</em>' data type.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @see java.lang.String
* @see tdt4250.spp.impl.SppPackageImpl#getCourseCode()
* @generated
*/
EDataType COURSE_CODE = eINSTANCE.getCourseCode();
}
} //SppPackage
......@@ -84,6 +84,8 @@ public class SppFactoryImpl extends EFactoryImpl implements SppFactory {
return createSeasonTypeFromString(eDataType, initialValue);
case SppPackage.COURSE_LEVEL_TYPE:
return createCourseLevelTypeFromString(eDataType, initialValue);
case SppPackage.COURSE_CODE:
return createCourseCodeFromString(eDataType, initialValue);
default:
throw new IllegalArgumentException("The datatype '" + eDataType.getName() + "' is not a valid classifier");
}
......@@ -103,6 +105,8 @@ public class SppFactoryImpl extends EFactoryImpl implements SppFactory {
return convertSeasonTypeToString(eDataType, instanceValue);
case SppPackage.COURSE_LEVEL_TYPE:
return convertCourseLevelTypeToString(eDataType, instanceValue);
case SppPackage.COURSE_CODE:
return convertCourseCodeToString(eDataType, instanceValue);
default:
throw new IllegalArgumentException("The datatype '" + eDataType.getName() + "' is not a valid classifier");
}
......@@ -256,6 +260,27 @@ public class SppFactoryImpl extends EFactoryImpl implements SppFactory {
return instanceValue == null ? null : instanceValue.toString();
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public String createCourseCodeFromString(EDataType eDataType, String initialValue) {
if (! initialValue.matches("[A-Z]{2,4}[0-9]{4}")) {
throw new IllegalArgumentException("Course code must have the format [A-Z]{2,4}[0-9]{4}, e.g. TDT4250");
}
return (String)super.createFromString(eDataType, initialValue);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated NOPE
*/
public String convertCourseCodeToString(EDataType eDataType, Object instanceValue) {
return super.convertToString(eDataType, instanceValue);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
......
......@@ -4,6 +4,7 @@ package tdt4250.spp.impl;
import org.eclipse.emf.ecore.EAttribute;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EDataType;
import org.eclipse.emf.ecore.EEnum;
import org.eclipse.emf.ecore.EOperation;
import org.eclipse.emf.ecore.EPackage;
......@@ -111,6 +112,13 @@ public class SppPackageImpl extends EPackageImpl implements SppPackage {
*/
private EEnum courseLevelTypeEEnum = null;
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
private EDataType courseCodeEDataType = null;
/**
* Creates an instance of the model <b>Package</b>, registered with
* {@link org.eclipse.emf.ecore.EPackage.Registry EPackage.Registry} by the package
......@@ -602,6 +610,16 @@ public class SppPackageImpl extends EPackageImpl implements SppPackage {
return courseLevelTypeEEnum;
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public EDataType getCourseCode() {
return courseCodeEDataType;
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
......@@ -682,6 +700,9 @@ public class SppPackageImpl extends EPackageImpl implements SppPackage {
levelTypeEEnum = createEEnum(LEVEL_TYPE);
seasonTypeEEnum = createEEnum(SEASON_TYPE);
courseLevelTypeEEnum = createEEnum(COURSE_LEVEL_TYPE);
// Create data types
courseCodeEDataType = createEDataType(COURSE_CODE);
}
/**
......@@ -744,7 +765,7 @@ public class SppPackageImpl extends EPackageImpl implements SppPackage {
initEOperation(getSemester__GetCredits(), ecorePackage.getEFloat(), "getCredits", 0, 1, IS_UNIQUE, IS_ORDERED);
initEClass(courseEClass, Course.class, "Course", !IS_ABSTRACT, !IS_INTERFACE, IS_GENERATED_INSTANCE_CLASS);
initEAttribute(getCourse_Code(), ecorePackage.getEString(), "code", null, 0, 1, Course.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
initEAttribute(getCourse_Code(), this.getCourseCode(), "code", null, 0, 1, Course.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
initEAttribute(getCourse_Name(), ecorePackage.getEString(), "name", null, 0, 1, Course.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
initEAttribute(getCourse_Credits(), ecorePackage.getEFloat(), "credits", null, 0, 1, Course.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
initEAttribute(getCourse_Level(), this.getCourseLevelType(), "level", null, 0, 1, Course.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
......@@ -780,6 +801,9 @@ public class SppPackageImpl extends EPackageImpl implements SppPackage {
addEEnumLiteral(courseLevelTypeEEnum, CourseLevelType.THIRD_YEAR_COURSE);
addEEnumLiteral(courseLevelTypeEEnum, CourseLevelType.SECOUND_DEGREE_COURSE);
// Initialize data types
initEDataType(courseCodeEDataType, String.class, "CourseCode", IS_SERIALIZABLE, !IS_GENERATED_INSTANCE_CLASS);
// Create resource
createResource(eNS_URI);
......
......@@ -107,6 +107,8 @@ public class SppValidator extends EObjectValidator {
return validateSeasonType((SeasonType)value, diagnostics, context);
case SppPackage.COURSE_LEVEL_TYPE:
return validateCourseLevelType((CourseLevelType)value, diagnostics, context);
case SppPackage.COURSE_CODE:
return validateCourseCode((String)value, diagnostics, context);
default:
return true;
}
......@@ -319,6 +321,15 @@ public class SppValidator extends EObjectValidator {
return true;
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public boolean validateCourseCode(String courseCode, DiagnosticChain diagnostics, Map<Object, Object> context) {
return true;
}
/**
* Returns the resource locator that will be used to fetch messages for this validator's diagnostics.
* <!-- begin-user-doc -->
......
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