From 162f1b41196bd3bcdf7e743e4daebcb87f3ac60b Mon Sep 17 00:00:00 2001 From: Catrope Date: Tue, 2 Apr 2013 11:44:23 -0700 Subject: [PATCH] Convert AnnotationFactory and MetaItemFactory to NamedClassFactories Change-Id: Ic6e3a336050a335c88ef41735c0f4e470c5b75b6 --- modules/ve/dm/ve.dm.AnnotationFactory.js | 6 +++--- modules/ve/dm/ve.dm.MetaItemFactory.js | 6 +++--- modules/ve/dm/ve.dm.ModelRegistry.js | 11 ++++++++--- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/modules/ve/dm/ve.dm.AnnotationFactory.js b/modules/ve/dm/ve.dm.AnnotationFactory.js index 9918065fa4..b035fda525 100644 --- a/modules/ve/dm/ve.dm.AnnotationFactory.js +++ b/modules/ve/dm/ve.dm.AnnotationFactory.js @@ -9,17 +9,17 @@ * DataModel annotation factory. * * @class - * @extends ve.Factory + * @extends ve.NamedClassFactory * @constructor */ ve.dm.AnnotationFactory = function VeDmAnnotationFactory() { // Parent constructor - ve.Factory.call( this ); + ve.NamedClassFactory.call( this ); }; /* Inheritance */ -ve.inheritClass( ve.dm.AnnotationFactory, ve.Factory ); +ve.inheritClass( ve.dm.AnnotationFactory, ve.NamedClassFactory ); /* Initialization */ diff --git a/modules/ve/dm/ve.dm.MetaItemFactory.js b/modules/ve/dm/ve.dm.MetaItemFactory.js index 1ebc773f9f..04aae6672c 100644 --- a/modules/ve/dm/ve.dm.MetaItemFactory.js +++ b/modules/ve/dm/ve.dm.MetaItemFactory.js @@ -9,17 +9,17 @@ * DataModel meta item factory. * * @class - * @extends ve.Factory + * @extends ve.NamedClassFactory * @constructor */ ve.dm.MetaItemFactory = function VeDmMetaItemFactory() { // Parent constructor - ve.Factory.call( this ); + ve.NamedClassFactory.call( this ); }; /* Inheritance */ -ve.inheritClass( ve.dm.MetaItemFactory, ve.Factory ); +ve.inheritClass( ve.dm.MetaItemFactory, ve.NamedClassFactory ); /* Methods */ diff --git a/modules/ve/dm/ve.dm.ModelRegistry.js b/modules/ve/dm/ve.dm.ModelRegistry.js index cb6c753f72..6f7f453009 100644 --- a/modules/ve/dm/ve.dm.ModelRegistry.js +++ b/modules/ve/dm/ve.dm.ModelRegistry.js @@ -71,22 +71,27 @@ function addType( obj /*, ...*/ ) { * Register a model type. * @param {string} name Symbolic name for the model * @param {ve.dm.Model} constructor Subclass of ve.dm.Model + * @throws Models must be subclasses of ve.dm.Model + * @throws No factory associated with this ve.dm.Model subclass */ ve.dm.ModelRegistry.prototype.register = function ( constructor ) { var i, j, tags, types, name = constructor.static && constructor.static.name; if ( typeof name !== 'string' || name === '' ) { throw new Error( 'Model names must be strings and must not be empty' ); } + if ( !( constructor.prototype instanceof ve.dm.Model ) ) { + throw new Error( 'Models must be subclasses of ve.dm.Model' ); + } // Register the model with the right factory if ( constructor.prototype instanceof ve.dm.Annotation ) { - ve.dm.annotationFactory.register( name, constructor ); + ve.dm.annotationFactory.register( constructor ); } else if ( constructor.prototype instanceof ve.dm.Node ) { ve.dm.nodeFactory.register( constructor ); } else if ( constructor.prototype instanceof ve.dm.MetaItem ) { - ve.dm.metaItemFactory.register( name, constructor ); + ve.dm.metaItemFactory.register( constructor ); } else { - throw new Error( 'Models must be subclasses of ve.dm.Annotation, ve.dm.Node or ve.dm.MetaItem' ); + throw new Error( 'No factory associated with this ve.dm.Model subclass' ); } // Call parent implementation ve.Registry.prototype.register.call( this, name, constructor );