Sha256: 6c9ff92ae1e6f08357668403233429082df24ccfc1aa519c76845a678a042e45

Contents?: true

Size: 1.59 KB

Versions: 3

Compression:

Stored size: 1.59 KB

Contents

/* Copyright 2008 Theo Hultberg/Iconara */

package <%= base_package %>.models.factory
{
	import flash.utils.Dictionary;
	
	import <%= base_package %>.models.constant.DocumentType;
	import <%= base_package %>.models.domain.Document;
	import <%= base_package %>.models.domain.PlainDocument;
	import <%= base_package %>.models.domain.RichDocument;

	/**
	 * A factory for creating Document instances. The specific implementation created
	 * depends on the DocumentType that is passed to the createDocument method.
	 */
	public class DocumentFactory {
		
		private static var _factoryMap : Dictionary;
		
		
		private function get factoryMap( ):Dictionary {
			if ( _factoryMap == null ) {
				_factoryMap = new Dictionary();
				_factoryMap[DocumentType.PLAIN] = PlainDocument;
				_factoryMap[DocumentType.RICH]  = RichDocument;
			}
			
			return _factoryMap;
		}
		
		
		/**
		 * Create a new document of the specified type using some default data.
		 * 
		 * Throws an exception if this factory cannot create documents of the specified type.
		 */
		public function createDocument(type:DocumentType, data:*=null):Document {
			if ( factoryMap[type] == null ) {
				throw new ArgumentError("Cannot create document, unknown type: \"" + type + "\"");
			}
			
			var documentClass : Class = factoryMap[type];
		
			var document : Document = new documentClass();

			if (data != null ) {
				
			} else {
				document.content.title = "Untitled ";
				document.content.body = "";
				document.content.abstract = "";
				document.content.menuTitle = "";
				document.content.subTitle = "";
			}
		
			return document;
		}

	}

}

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
emergent-core-0.1.0 rails_generators/emergent_config/templates/app/flex/application/models/factory/DocumentFactory.as
emergent-core-0.1.01 rails_generators/emergent_config/templates/app/flex/application/models/factory/DocumentFactory.as
emergent-core-0.1.02 rails_generators/emergent_config/templates/app/flex/application/models/factory/DocumentFactory.as