Sha256: 6a82c5646092dfee338897fd187d6803bbf6e65c7f98155fab16051696fc8d7c

Contents?: true

Size: 1.46 KB

Versions: 3

Compression:

Stored size: 1.46 KB

Contents

/* Copyright 2008 Theo Hultberg/Iconara */

package <%= base_package %>.models.factory
{
	import flash.utils.Dictionary;
	
	import mx.core.Container;
	
	import <%= base_package %>.models.domain.Document;
	import <%= base_package %>.models.constant.DocumentType;
	
	import <%= base_package %>.views.document.*;

	/**
	 * A factory for document views that can create the appropriate view instance for a particular
	 * document type.
	 */
	public class DocumentViewFactory {
		
		private static var _factoryMap:Dictionary;
		
		
		private function get factoryMap( ):Dictionary {
			if ( _factoryMap == null ) {
				_factoryMap = new Dictionary();
				_factoryMap[DocumentType.PLAIN] = PlainDocumentView;
				_factoryMap[DocumentType.RICH]  = RichDocumentView;
			}
			
			return _factoryMap;
		}
		
		
		/**
		 * Creates a view that can display the specified document. 
		 * 
		 * Throws an exception if the document is null or if the document type is not supported.
		 */
		public function createDocumentView(document:Document):Container {
			if ( document == null ) {
				throw new ArgumentError("Cannot create document view, document was null");
			}
			
			if ( factoryMap[document.documentType] == null ) {
				throw new ArgumentError("Cannot create new document view, unknown type: \"" + document.documentType + "\"");
			}
			
			var viewClass:Class = factoryMap[document.documentType];
			
			var view:Container = new viewClass();
			
			view.data = document;
			
			return view;
		}

	}

}

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/DocumentViewFactory.as
emergent-core-0.1.01 rails_generators/emergent_config/templates/app/flex/application/models/factory/DocumentViewFactory.as
emergent-core-0.1.02 rails_generators/emergent_config/templates/app/flex/application/models/factory/DocumentViewFactory.as