├── .gitignore ├── CONTRIBUTORS.textile ├── LICENSE ├── README.markdown ├── build ├── build.properties ├── build.xml └── libs │ ├── FLoxy.swc │ ├── flexUnitTasks-4.1.0-8.jar │ ├── flexunit-4.1.0-8-as3_4.1.0.16076.swc │ ├── flexunit-4.1.0-8-flex_4.1.0.16076.swc │ ├── flexunit-aircilistener-4.1.0-8-4.1.0.16076.swc │ ├── flexunit-cilistener-4.1.0-8-4.1.0.16076.swc │ ├── flexunit-flexcoverlistener-4.1.0-8-4.1.0.16076.swc │ ├── flexunit-uilistener-4.1.0-8-4.1.0.16076.swc │ ├── fluint-extensions-4.1.0-8-4.1.0.16076.swc │ ├── hamcrest-as3-1.1.1.swc │ └── mockolate-0.11.0-flex.swc ├── misc ├── SwizCodeFormatting.properties └── SwizMetadataSourceMateConfig.xml ├── src ├── design.xml ├── manifest.xml ├── metadata.xml └── org │ └── swizframework │ ├── controller │ └── AbstractController.as │ ├── core │ ├── Bean.as │ ├── BeanFactory.as │ ├── BeanLoader.as │ ├── BeanProvider.as │ ├── IBeanFactory.as │ ├── IBeanFactoryAware.as │ ├── IBeanProvider.as │ ├── IDispatcherAware.as │ ├── IDisposable.as │ ├── IInitializing.as │ ├── ISetUpValidator.as │ ├── ISwiz.as │ ├── ISwizAware.as │ ├── ISwizConfig.as │ ├── ISwizHost.as │ ├── ISwizInterface.as │ ├── ITearDownValidator.as │ ├── Prototype.as │ ├── Swiz.as │ ├── SwizConfig.as │ ├── SwizManager.as │ └── mxml │ │ └── Swiz.as │ ├── events │ ├── BeanEvent.as │ ├── ChainEvent.as │ └── SwizEvent.as │ ├── factories │ └── MetadataHostFactory.as │ ├── metadata │ ├── EventHandlerMetadataTag.as │ ├── EventTypeExpression.as │ ├── InjectMetadataTag.as │ ├── PostConstructMetadataTag.as │ └── PreDestroyMetadataTag.as │ ├── processors │ ├── BaseMetadataProcessor.as │ ├── DispatcherProcessor.as │ ├── EventHandlerProcessor.as │ ├── IBeanProcessor.as │ ├── IFactoryProcessor.as │ ├── IMetadataProcessor.as │ ├── IProcessor.as │ ├── InjectProcessor.as │ ├── PostConstructProcessor.as │ ├── PreDestroyProcessor.as │ ├── ProcessorPriority.as │ ├── SwizInterfaceProcessor.as │ └── ViewProcessor.as │ ├── reflection │ ├── BaseMetadataHost.as │ ├── BaseMetadataTag.as │ ├── BindableMetadataHost.as │ ├── ClassConstant.as │ ├── Constant.as │ ├── IMetadataHost.as │ ├── IMetadataTag.as │ ├── MetadataArg.as │ ├── MetadataHostClass.as │ ├── MetadataHostMethod.as │ ├── MetadataHostProperty.as │ ├── MethodParameter.as │ ├── TypeCache.as │ └── TypeDescriptor.as │ ├── storage │ ├── ISharedObjectBean.as │ └── SharedObjectBean.as │ └── utils │ ├── DomainUtil.as │ ├── ModuleTypeUtil.as │ ├── async │ ├── AbstractAsynchronousDispatcherOperation.as │ ├── AbstractAsynchronousOperation.as │ ├── AsyncTokenOperation.as │ ├── AsynchronousChainOperation.as │ ├── AsynchronousEvent.as │ ├── AsynchronousIOOperation.as │ ├── IAsynchronousEvent.as │ └── IAsynchronousOperation.as │ ├── chain │ ├── AbstractChain.as │ ├── AsyncCommandChainStep.as │ ├── BaseChainStep.as │ ├── BaseCompositeChain.as │ ├── ChainType.as │ ├── ChainUtil.as │ ├── CommandChain.as │ ├── CommandChainStep.as │ ├── EventChain.as │ ├── EventChainStep.as │ ├── FunctionChainStep.as │ ├── IAsyncChainStep.as │ ├── IAutonomousChainStep.as │ ├── IChain.as │ └── IChainStep.as │ ├── commands │ ├── CommandMap.as │ ├── ICommand.as │ └── IEventAwareCommand.as │ ├── event │ └── EventHandler.as │ ├── logging │ ├── AbstractSwizLoggingTarget.as │ ├── SwizLogEvent.as │ ├── SwizLogEventLevel.as │ ├── SwizLogger.as │ └── SwizTraceTarget.as │ ├── services │ ├── AMFUtil.as │ ├── ChannelSetHelper.as │ ├── IServiceHelper.as │ ├── IURLRequestHelper.as │ ├── MockDelegateHelper.as │ ├── ServiceHelper.as │ ├── SwizResponder.as │ ├── SwizURLRequest.as │ └── URLRequestHelper.as │ └── test │ └── AutowiredTestCase.as └── test ├── SwizTestRunner.mxml ├── org └── swizframework │ ├── reflection │ ├── ClassConstantTest.as │ └── TypeCacheTests.as │ └── storage │ └── SharedObjectBeanTest.as └── testSuites ├── ReflectionTestsSuite.as └── StorageTestSuite.as /.gitignore: -------------------------------------------------------------------------------- 1 | /.settings/* 2 | 3 | /html-template/* 4 | /bin/* 5 | /dist/* 6 | /docs/* 7 | 8 | .actionScriptProperties 9 | .flexProperties 10 | .flexLibProperties 11 | .fxpProperties 12 | .project 13 | .sourceMate 14 | .sourceMateMetadataSettings 15 | setEnv.sh 16 | 17 | Icon 18 | Thumbs.db 19 | .DS_Store 20 | 21 | -------------------------------------------------------------------------------- /CONTRIBUTORS.textile: -------------------------------------------------------------------------------- 1 | h2. Framework Contributors 2 | 3 | * "Chris Scott":http://github.com/asstrochris 4 | * "Ben Clinkinbeard":http://github.com/bclinkinbeard 5 | * "Sönke Rohde":http://github.com/srohde 6 | * "Ryan Campbell":http://github.com/ryancampbell 7 | * "Darron Schall":http://github.com/darronschall 8 | * "David Tucker":http://github.com/davidtucker 9 | * "John Yanarella":http://github.com/johnyanarella 10 | * "Cliff Meyers":http://github.com/cliffmeyers 11 | * "Brian Kotek":http://github.com/brian428 12 | * "Adam Lehman":adrocknaphobia@gmail.com 13 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2010 Swiz Framework Contributors 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); you may not 4 | use this file except in compliance with the License. You may obtain a copy of 5 | the License. You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 | WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 | License for the specific language governing permissions and limitations under 13 | the License. -------------------------------------------------------------------------------- /README.markdown: -------------------------------------------------------------------------------- 1 | Swiz is a brutally simple micro-architecture for creating Rich Internet Applications with ActionScript 3 and Adobe Flex 2 | 3 | ## How to Contribute 4 | 5 | The Swiz team welcomes contributions to the framework in the form of pull requests. Please note that active development happens in the develop branch, so you should fork from and submit to it, not master. 6 | 7 | ## Documentation and Reporting Bugs 8 | 9 | Swiz does not use GitHub for issue tracking or documentation. Documentation can be found in the [Swiz wiki](https://swizframework.jira.com/wiki/) and bugs and feature requests should be entered in the [Swiz JIRA instance](https://swizframework.jira.com). **Note: you need to be logged in first** 10 | 11 | ## Building 12 | 13 | You can compile the library .swc file using: 14 | 15 | ant -f ./build/build.xml compile -------------------------------------------------------------------------------- /build/build.properties: -------------------------------------------------------------------------------- 1 | # Versioning 2 | swiz.version = v1.4.0 3 | swiz.name = swiz-framework-${swiz.version} 4 | swiz.name.flex3 = ${swiz.name}-flex3 5 | swiz.namespace = http://swiz.swizframework.org 6 | 7 | # flex sdk 8 | flex.sdk = /Applications/Adobe\ Flash\ Builder\ 4\ Plug-in/sdks/4.0.0 9 | 10 | # Unit tests 11 | test.application.name = SwizTestRunner.mxml 12 | test.artifact.name = SwizTestRunner.swf 13 | 14 | # Setup paths for build 15 | build.libs.loc = ${basedir}/build/libs 16 | src.loc = ${basedir}/src 17 | test.src.loc = ${basedir}/test 18 | libs.loc = ${basedir}/libs 19 | bin.loc = ${basedir}/bin 20 | test.bin.loc = ${basedir}/bin-test 21 | report.loc = ${basedir}/report 22 | report.html.loc = ${basedir}/report/html 23 | docs.loc = ${basedir}/docs 24 | dist.loc = ${basedir}/dist 25 | -------------------------------------------------------------------------------- /build/libs/FLoxy.swc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swiz/swiz-framework/0e933bea83c029acf3150acd30b6d8f759dce84f/build/libs/FLoxy.swc -------------------------------------------------------------------------------- /build/libs/flexUnitTasks-4.1.0-8.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swiz/swiz-framework/0e933bea83c029acf3150acd30b6d8f759dce84f/build/libs/flexUnitTasks-4.1.0-8.jar -------------------------------------------------------------------------------- /build/libs/flexunit-4.1.0-8-as3_4.1.0.16076.swc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swiz/swiz-framework/0e933bea83c029acf3150acd30b6d8f759dce84f/build/libs/flexunit-4.1.0-8-as3_4.1.0.16076.swc -------------------------------------------------------------------------------- /build/libs/flexunit-4.1.0-8-flex_4.1.0.16076.swc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swiz/swiz-framework/0e933bea83c029acf3150acd30b6d8f759dce84f/build/libs/flexunit-4.1.0-8-flex_4.1.0.16076.swc -------------------------------------------------------------------------------- /build/libs/flexunit-aircilistener-4.1.0-8-4.1.0.16076.swc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swiz/swiz-framework/0e933bea83c029acf3150acd30b6d8f759dce84f/build/libs/flexunit-aircilistener-4.1.0-8-4.1.0.16076.swc -------------------------------------------------------------------------------- /build/libs/flexunit-cilistener-4.1.0-8-4.1.0.16076.swc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swiz/swiz-framework/0e933bea83c029acf3150acd30b6d8f759dce84f/build/libs/flexunit-cilistener-4.1.0-8-4.1.0.16076.swc -------------------------------------------------------------------------------- /build/libs/flexunit-flexcoverlistener-4.1.0-8-4.1.0.16076.swc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swiz/swiz-framework/0e933bea83c029acf3150acd30b6d8f759dce84f/build/libs/flexunit-flexcoverlistener-4.1.0-8-4.1.0.16076.swc -------------------------------------------------------------------------------- /build/libs/flexunit-uilistener-4.1.0-8-4.1.0.16076.swc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swiz/swiz-framework/0e933bea83c029acf3150acd30b6d8f759dce84f/build/libs/flexunit-uilistener-4.1.0-8-4.1.0.16076.swc -------------------------------------------------------------------------------- /build/libs/fluint-extensions-4.1.0-8-4.1.0.16076.swc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swiz/swiz-framework/0e933bea83c029acf3150acd30b6d8f759dce84f/build/libs/fluint-extensions-4.1.0-8-4.1.0.16076.swc -------------------------------------------------------------------------------- /build/libs/hamcrest-as3-1.1.1.swc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swiz/swiz-framework/0e933bea83c029acf3150acd30b6d8f759dce84f/build/libs/hamcrest-as3-1.1.1.swc -------------------------------------------------------------------------------- /build/libs/mockolate-0.11.0-flex.swc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swiz/swiz-framework/0e933bea83c029acf3150acd30b6d8f759dce84f/build/libs/mockolate-0.11.0-flex.swc -------------------------------------------------------------------------------- /misc/SwizMetadataSourceMateConfig.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /src/design.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /src/manifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /src/org/swizframework/controller/AbstractController.as: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Swiz Framework Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.swizframework.controller 18 | { 19 | import flash.events.IEventDispatcher; 20 | import flash.net.URLLoader; 21 | import flash.net.URLRequest; 22 | 23 | import mx.rpc.AsyncToken; 24 | 25 | import org.swizframework.core.IDispatcherAware; 26 | import org.swizframework.core.ISwiz; 27 | import org.swizframework.core.ISwizAware; 28 | import org.swizframework.utils.chain.AsyncCommandChainStep; 29 | import org.swizframework.utils.chain.ChainType; 30 | import org.swizframework.utils.chain.CommandChain; 31 | import org.swizframework.utils.services.SwizResponder; 32 | import org.swizframework.utils.services.SwizURLRequest; 33 | 34 | public class AbstractController implements ISwizAware, IDispatcherAware 35 | { 36 | public var _swiz:ISwiz; 37 | private var _dispatcher:IEventDispatcher; 38 | 39 | public function AbstractController() 40 | { 41 | } 42 | 43 | public function set swiz( swiz :ISwiz ):void 44 | { 45 | _swiz = swiz; 46 | } 47 | 48 | /** IDispatcherAware implementation */ 49 | public function set dispatcher( dispatcher:IEventDispatcher ):void 50 | { 51 | _dispatcher = dispatcher; 52 | } 53 | 54 | public function get dispatcher():IEventDispatcher 55 | { 56 | return _dispatcher; 57 | } 58 | 59 | /** Delegates execute service call to Swiz */ 60 | protected function executeServiceCall( call:AsyncToken, resultHandler:Function, 61 | faultHandler:Function = null, handlerArgs:Array = null ):AsyncToken 62 | { 63 | 64 | if( faultHandler == null && _swiz.config.defaultFaultHandler != null ) 65 | faultHandler = _swiz.config.defaultFaultHandler; 66 | 67 | call.addResponder( new SwizResponder( resultHandler, faultHandler, handlerArgs ) ); 68 | 69 | return call; 70 | } 71 | 72 | /** Delegates execute url request call to Swiz */ 73 | protected function executeURLRequest( request:URLRequest, resultHandler:Function, faultHandler:Function = null, 74 | progressHandler:Function = null, httpStatusHandler:Function = null, 75 | handlerArgs:Array = null ):URLLoader 76 | { 77 | 78 | if( faultHandler == null && _swiz.config.defaultFaultHandler != null ) 79 | faultHandler = _swiz.config.defaultFaultHandler; 80 | 81 | return new SwizURLRequest( request, resultHandler, faultHandler, progressHandler, httpStatusHandler, handlerArgs ).loader; 82 | } 83 | 84 | /** Delegates create command to Swiz */ 85 | protected function createCommand( delayedCall:Function, args:Array, resultHandler:Function, 86 | faultHandler:Function = null, handlerArgs:Array = null ):AsyncCommandChainStep 87 | { 88 | return new AsyncCommandChainStep( delayedCall, args, resultHandler, faultHandler, handlerArgs ); 89 | } 90 | 91 | /** Constructs a dynamic command */ 92 | public function createChain( mode:String = ChainType.SEQUENCE ):CommandChain 93 | { 94 | return new CommandChain( mode ); 95 | } 96 | } 97 | } -------------------------------------------------------------------------------- /src/org/swizframework/core/Bean.as: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Swiz Framework Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.swizframework.core 18 | { 19 | import org.swizframework.reflection.TypeDescriptor; 20 | 21 | [DefaultProperty( "source" )] 22 | 23 | public class Bean 24 | { 25 | // ======================================== 26 | // protected properties 27 | // ======================================== 28 | 29 | protected var _source:*; 30 | 31 | // ======================================== 32 | // public properties 33 | // ======================================== 34 | 35 | /** 36 | * Source 37 | */ 38 | public function get source():* 39 | { 40 | return _source; 41 | } 42 | 43 | public function set source( value:* ):void 44 | { 45 | _source = value; 46 | } 47 | 48 | /** 49 | * Name 50 | */ 51 | public var name:String; 52 | 53 | /** 54 | * Type Descriptor 55 | */ 56 | public var typeDescriptor:TypeDescriptor; 57 | 58 | /** 59 | * BeanFactory 60 | */ 61 | public var beanFactory:IBeanFactory; 62 | 63 | /** 64 | * Initialzed 65 | */ 66 | public var initialized:Boolean = false; 67 | 68 | public function get type():* 69 | { 70 | return source; 71 | } 72 | 73 | // ======================================== 74 | // constructor 75 | // ======================================== 76 | 77 | public function Bean( source:* = null, name:String = null, typeDescriptor:TypeDescriptor = null ) 78 | { 79 | this.source = source; 80 | this.name = name; 81 | this.typeDescriptor = typeDescriptor; 82 | } 83 | 84 | // ======================================== 85 | // public methods 86 | // ======================================== 87 | 88 | public function toString():String 89 | { 90 | return "Bean{ source: " + source + ", name: " + name + " }"; 91 | } 92 | } 93 | } -------------------------------------------------------------------------------- /src/org/swizframework/core/BeanLoader.as: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Swiz Framework Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.swizframework.core 18 | { 19 | import org.swizframework.utils.logging.SwizLogger; 20 | 21 | /** 22 | * @deprecated 23 | */ 24 | public class BeanLoader extends BeanProvider 25 | { 26 | // ======================================== 27 | // protected properties 28 | // ======================================== 29 | 30 | protected var logger:SwizLogger = SwizLogger.getLogger( this ); 31 | 32 | // ======================================== 33 | // Constructor 34 | // ======================================== 35 | 36 | /** 37 | * Constructor, logs as deprecated 38 | */ 39 | public function BeanLoader( beans:Array = null ) 40 | { 41 | super( beans ); 42 | logger.warn("BeanLoader is deprecated! Please refactor your loaders to BeanProvider as this class will be removed eventually!"); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/org/swizframework/core/IBeanFactory.as: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Swiz Framework Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.swizframework.core 18 | { 19 | import flash.utils.Dictionary; 20 | 21 | /** 22 | * Bean Factory Interface 23 | */ 24 | public interface IBeanFactory 25 | { 26 | function setUp( swiz:ISwiz ):void; 27 | function tearDown():void; 28 | 29 | function setUpBean( bean:Bean ):void; 30 | function addBean( bean:Bean, autoSetUpBean:Boolean = true ):Bean; 31 | function addBeanProvider( beanProvider:IBeanProvider, autoSetUpBeans:Boolean = true ):void; 32 | 33 | function tearDownBean( bean:Bean ):void; 34 | function removeBean( bean:Bean ):void; 35 | function removeBeanProvider( beanProvider:IBeanProvider ):void; 36 | 37 | function get beans():Array; 38 | function getBeanByName( name:String ):Bean; 39 | function getBeanByType( type:Class ):Bean; 40 | 41 | /** 42 | * Parent Swiz instance, for nesting and modules 43 | */ 44 | function get parentBeanFactory():IBeanFactory; 45 | function set parentBeanFactory( parentBeanFactory:IBeanFactory ):void; 46 | } 47 | } -------------------------------------------------------------------------------- /src/org/swizframework/core/IBeanFactoryAware.as: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Swiz Framework Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.swizframework.core 18 | { 19 | public interface IBeanFactoryAware extends ISwizInterface 20 | { 21 | function set beanFactory( beanFactory:IBeanFactory ):void; 22 | } 23 | } -------------------------------------------------------------------------------- /src/org/swizframework/core/IBeanProvider.as: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Swiz Framework Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.swizframework.core 18 | { 19 | import flash.events.IEventDispatcher; 20 | import flash.system.ApplicationDomain; 21 | 22 | public interface IBeanProvider 23 | { 24 | function get beans():Array; 25 | 26 | function addBean( bean:Bean ):void; 27 | function removeBean( bean:Bean ):void; 28 | function initialize( domain:ApplicationDomain ):void; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/org/swizframework/core/IDispatcherAware.as: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Swiz Framework Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.swizframework.core 18 | { 19 | import flash.events.IEventDispatcher; 20 | 21 | public interface IDispatcherAware extends ISwizInterface 22 | { 23 | function set dispatcher( dispatcher:IEventDispatcher ):void; 24 | } 25 | } -------------------------------------------------------------------------------- /src/org/swizframework/core/IDisposable.as: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Swiz Framework Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.swizframework.core 18 | { 19 | public interface IDisposable extends ISwizInterface 20 | { 21 | function destroy():void; 22 | } 23 | } -------------------------------------------------------------------------------- /src/org/swizframework/core/IInitializing.as: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Swiz Framework Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.swizframework.core 18 | { 19 | public interface IInitializing extends ISwizInterface 20 | { 21 | function afterPropertiesSet():void; 22 | } 23 | } -------------------------------------------------------------------------------- /src/org/swizframework/core/ISetUpValidator.as: -------------------------------------------------------------------------------- 1 | package org.swizframework.core 2 | { 3 | public interface ISetUpValidator 4 | { 5 | function allowSetUp():Boolean; 6 | } 7 | } -------------------------------------------------------------------------------- /src/org/swizframework/core/ISwiz.as: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Swiz Framework Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.swizframework.core 18 | { 19 | import flash.events.IEventDispatcher; 20 | import flash.system.ApplicationDomain; 21 | 22 | /** 23 | * Swiz Interface 24 | */ 25 | public interface ISwiz 26 | { 27 | // ======================================== 28 | // public properties 29 | // ======================================== 30 | 31 | function get catchViews():Boolean; 32 | function set catchViews( value:Boolean ):void; 33 | 34 | /** 35 | * Local Dispatcher 36 | */ 37 | function get dispatcher():IEventDispatcher; 38 | function set dispatcher( value:IEventDispatcher ):void; 39 | 40 | /** 41 | * Global Dispatcher 42 | */ 43 | function get globalDispatcher():IEventDispatcher; 44 | function set globalDispatcher( value:IEventDispatcher ):void; 45 | 46 | /** 47 | * Domain 48 | */ 49 | function get domain():ApplicationDomain; 50 | function set domain( value:ApplicationDomain ):void; 51 | 52 | /** 53 | * Config 54 | */ 55 | function get config():ISwizConfig; 56 | function set config( value:ISwizConfig ):void; 57 | 58 | [ArrayElementType( "org.swizframework.core.IBeanProvider" )] 59 | 60 | /** 61 | * Bean Providers 62 | */ 63 | function get beanProviders():Array; 64 | function set beanProviders( value:Array ):void; 65 | 66 | /** 67 | * Bean Factory 68 | */ 69 | function get beanFactory():IBeanFactory; 70 | function set beanFactory( value:IBeanFactory ):void; 71 | 72 | [ArrayElementType( "org.swizframework.processors.IProcessor" )] 73 | 74 | /** 75 | * Processors 76 | */ 77 | function get processors():Array; 78 | 79 | /** 80 | * Custom Processors 81 | */ 82 | function set customProcessors( value:Array ):void; 83 | 84 | /** 85 | * Parent Swiz instance, for nesting and modules 86 | */ 87 | function get parentSwiz():ISwiz; 88 | function set parentSwiz( parentSwiz:ISwiz ):void; 89 | 90 | [ArrayElementType( "org.swizframework.utils.logging.AbstractSwizLoggingTarget" )] 91 | 92 | /** 93 | * Logging targets 94 | */ 95 | function get loggingTargets():Array; 96 | function set loggingTargets( value:Array ):void; 97 | 98 | // ======================================== 99 | // public methods 100 | // ======================================== 101 | 102 | /** 103 | * Called once in initialize Swiz 104 | */ 105 | function init():void; 106 | 107 | /** 108 | * Clean up this Swiz instance 109 | */ 110 | function tearDown():void; 111 | 112 | /** 113 | * Register a new window with Swiz so that its metadata can be processed. 114 | */ 115 | function registerWindow( window:IEventDispatcher, windowSwiz:ISwiz = null ):void; 116 | } 117 | } -------------------------------------------------------------------------------- /src/org/swizframework/core/ISwizAware.as: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Swiz Framework Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.swizframework.core 18 | { 19 | public interface ISwizAware extends ISwizInterface 20 | { 21 | function set swiz( swiz:ISwiz ):void; 22 | } 23 | } -------------------------------------------------------------------------------- /src/org/swizframework/core/ISwizHost.as: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Swiz Framework Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.swizframework.core 18 | { 19 | /** 20 | * Interface that IEventDispatchers can optionally implement 21 | * when serving as the host for a Swiz instance. Useful if 22 | * direct access to the Swiz instance is desired or necessary. 23 | */ 24 | public interface ISwizHost 25 | { 26 | function get swizInstance():Swiz; 27 | function set swizInstance( value:Swiz ):void; 28 | } 29 | } -------------------------------------------------------------------------------- /src/org/swizframework/core/ISwizInterface.as: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Swiz Framework Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.swizframework.core 18 | { 19 | public interface ISwizInterface 20 | { 21 | 22 | } 23 | } -------------------------------------------------------------------------------- /src/org/swizframework/core/ITearDownValidator.as: -------------------------------------------------------------------------------- 1 | package org.swizframework.core 2 | { 3 | public interface ITearDownValidator 4 | { 5 | function allowTearDown():Boolean; 6 | } 7 | } -------------------------------------------------------------------------------- /src/org/swizframework/core/Prototype.as: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Swiz Framework Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.swizframework.core 18 | { 19 | public class Prototype extends Bean 20 | { 21 | public var constructorArguments:*; 22 | public var singleton:Boolean = false; 23 | 24 | /** 25 | * 26 | */ 27 | protected var _type:Class; 28 | 29 | override public function get type():* 30 | { 31 | return _type; 32 | } 33 | 34 | public function set type( clazz:Class ):void 35 | { 36 | _type = clazz; 37 | } 38 | 39 | override public function get source():* 40 | { 41 | return getObject(); 42 | } 43 | 44 | public function Prototype( type:Class = null ) 45 | { 46 | super(); 47 | 48 | this.type = type; 49 | } 50 | 51 | protected function getObject():* 52 | { 53 | var instance:* = _source; 54 | 55 | if( instance == null ) 56 | { 57 | // if source is null, create and initialize it (runs all processors) 58 | _source = instance = createInstance(); 59 | beanFactory.setUpBean( new Bean( _source, name, typeDescriptor ) ); 60 | 61 | // if this prototype is not a singleton, remove the source 62 | if( !singleton ) 63 | _source = null; 64 | else 65 | initialized = true; 66 | } 67 | 68 | return instance; 69 | } 70 | 71 | protected function createInstance():Object 72 | { 73 | if( type == null ) 74 | throw new Error( "Bean Creation exception! You must supply type to Prototype!" ); 75 | 76 | var instance:*; 77 | 78 | if( constructorArguments != null ) 79 | { 80 | var args:Array = constructorArguments is Array ? constructorArguments : [constructorArguments ]; 81 | 82 | switch( args.length ) 83 | { 84 | case 1: 85 | instance = new type( args[ 0 ] ); 86 | break; 87 | case 2: 88 | instance = new type( args[ 0 ], args[ 1 ] ); 89 | break; 90 | case 3: 91 | instance = new type( args[ 0 ], args[ 1 ], args[ 2 ] ); 92 | break; 93 | case 4: 94 | instance = new type( args[ 0 ], args[ 1 ], args[ 2 ], args[ 3 ] ); 95 | break; 96 | case 5: 97 | instance = new type( args[ 0 ], args[ 1 ], args[ 2 ], args[ 3 ], args[ 4 ] ); 98 | break; 99 | case 6: 100 | instance = new type( args[ 0 ], args[ 1 ], args[ 2 ], args[ 3 ], args[ 4 ], args[ 5 ] ); 101 | break; 102 | case 7: 103 | instance = new type( args[ 0 ], args[ 1 ], args[ 2 ], args[ 3 ], args[ 4 ], args[ 5 ], args[ 6 ] ); 104 | break; 105 | case 8: 106 | instance = new type( args[ 0 ], args[ 1 ], args[ 2 ], args[ 3 ], args[ 4 ], args[ 5 ], args[ 6 ], args[ 7 ] ); 107 | break; 108 | default: 109 | throw new Error( "No more than 8 constructor arguments are support by Prototype." ); 110 | } 111 | } 112 | else 113 | { 114 | instance = new type(); 115 | } 116 | 117 | return instance; 118 | } 119 | 120 | override public function toString():String 121 | { 122 | return "Prototype{ type: " + type + ", name: " + name + " }"; 123 | } 124 | } 125 | } -------------------------------------------------------------------------------- /src/org/swizframework/core/SwizManager.as: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Swiz Framework Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.swizframework.core 18 | { 19 | import flash.display.DisplayObject; 20 | import flash.display.DisplayObjectContainer; 21 | import flash.utils.Dictionary; 22 | 23 | import org.swizframework.processors.IMetadataProcessor; 24 | import org.swizframework.processors.IProcessor; 25 | 26 | public class SwizManager 27 | { 28 | public static var swizzes:Array = []; 29 | public static var wiredViews:Dictionary = new Dictionary( true ); 30 | public static var metadataNames:Array = []; 31 | 32 | public static function addSwiz( swiz:ISwiz ):void 33 | { 34 | swizzes.push( swiz ); 35 | 36 | for each( var p:IProcessor in swiz.processors ) 37 | if( p is IMetadataProcessor ) 38 | metadataNames = metadataNames.concat( IMetadataProcessor( p ).metadataNames ); 39 | } 40 | 41 | public static function removeSwiz( swiz:ISwiz ):void 42 | { 43 | swizzes.splice( swizzes.indexOf( swiz ), 1 ); 44 | } 45 | 46 | public static function setUp( view:DisplayObject ):void 47 | { 48 | // already wired 49 | if( wiredViews[ view ] != null ) 50 | return; 51 | 52 | for( var i:int = swizzes.length - 1; i > -1; i-- ) 53 | { 54 | var swiz:ISwiz = ISwiz( swizzes[ i ] ); 55 | 56 | if( DisplayObjectContainer( swiz.dispatcher ).contains( view ) ) 57 | { 58 | setUpView( view, swiz ); 59 | return; 60 | } 61 | } 62 | 63 | // pop ups not registered to a particular Swiz instance must be handled by the root instance 64 | setUpView( view, ISwiz( swizzes[ 0 ] ) ); 65 | } 66 | 67 | private static function setUpView( viewToWire:DisplayObject, swizInstance:ISwiz ):void 68 | { 69 | wiredViews[ viewToWire ] = swizInstance; 70 | swizInstance.beanFactory.setUpBean( BeanFactory.constructBean( viewToWire, null, swizInstance.domain ) ); 71 | } 72 | 73 | public static function tearDown( wiredView:DisplayObject ):void 74 | { 75 | // wasn't wired 76 | if( wiredViews[ wiredView ] == null ) 77 | return; 78 | 79 | for( var i:int = swizzes.length - 1; i > -1; i-- ) 80 | { 81 | var swiz:ISwiz = ISwiz( swizzes[ i ] ); 82 | 83 | // if this is the dispatcher for a swiz instance tear down swiz 84 | if( swiz.dispatcher == wiredView ) 85 | { 86 | swiz.tearDown(); 87 | return; 88 | } 89 | } 90 | 91 | // for tear down use the swiz instance that was associated at set up time 92 | tearDownWiredView( wiredView, wiredViews[ wiredView ] ); 93 | } 94 | 95 | public static function tearDownWiredView( wiredView:DisplayObject, swizInstance:ISwiz ):void 96 | { 97 | delete wiredViews[ wiredView ]; 98 | swizInstance.beanFactory.tearDownBean( BeanFactory.constructBean( wiredView, null, swizInstance.domain ) ); 99 | } 100 | 101 | public static function tearDownAllWiredViewsForSwizInstance( swizInstance:ISwiz ):void 102 | { 103 | for( var wiredView:* in wiredViews ) 104 | { 105 | // this will also tear down the swiz dispatcher itself 106 | if( wiredViews[ wiredView ] == swizInstance ) 107 | { 108 | tearDownWiredView( wiredView, swizInstance ); 109 | } 110 | } 111 | } 112 | } 113 | } -------------------------------------------------------------------------------- /src/org/swizframework/core/mxml/Swiz.as: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Swiz Framework Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.swizframework.core.mxml 18 | { 19 | import flash.events.Event; 20 | import flash.events.IEventDispatcher; 21 | 22 | import mx.core.IMXMLObject; 23 | import mx.events.FlexEvent; 24 | 25 | import org.swizframework.core.IBeanFactory; 26 | import org.swizframework.core.ISwizConfig; 27 | import org.swizframework.utils.DomainUtil; 28 | 29 | [DefaultProperty( "beanProviders" )] 30 | 31 | /** 32 | * Core framework class that serves as an IoC container rooted 33 | * at the IEventDispatcher passed into its constructor. 34 | */ 35 | public class Swiz extends org.swizframework.core.Swiz implements IMXMLObject 36 | { 37 | // ======================================== 38 | // constructor 39 | // ======================================== 40 | 41 | /** 42 | * Constructor 43 | */ 44 | public function Swiz( dispatcher:IEventDispatcher = null, config:ISwizConfig = null, beanFactory:IBeanFactory = null, beanProviders:Array = null, customProcessors:Array = null ) 45 | { 46 | super( dispatcher, config, beanFactory, beanProviders, customProcessors ); 47 | } 48 | 49 | // ======================================== 50 | // public methods 51 | // ======================================== 52 | 53 | /** 54 | * @see mx.core.IMXMLObject#initialized 55 | */ 56 | public function initialized( document:Object, id:String ):void 57 | { 58 | if( document is IEventDispatcher && dispatcher == null ) 59 | { 60 | dispatcher = IEventDispatcher( document ); 61 | dispatcher.addEventListener( FlexEvent.PREINITIALIZE, handleContainerPreinitialize ); 62 | } 63 | } 64 | 65 | /** 66 | * 67 | */ 68 | protected function handleContainerPreinitialize( event:Event ):void 69 | { 70 | dispatcher.removeEventListener( FlexEvent.PREINITIALIZE, handleContainerPreinitialize ); 71 | // set the current domain with DomainUtils, only if the dispatcher is a module. Will give a parent swiz instance a chance to set 72 | // in case of swiz instances nested down in the display list of a module. 73 | domain = DomainUtil.getModuleDomain( dispatcher ); 74 | // initialize 75 | init(); 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/org/swizframework/events/BeanEvent.as: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Swiz Framework Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.swizframework.events 18 | { 19 | import flash.events.Event; 20 | 21 | import org.swizframework.core.Bean; 22 | 23 | /** 24 | * Dispatched when a Bean is added to or removed from a 25 | * BeanProvider. 26 | * 27 | * @see org.swizframework.core.BeanProvider 28 | */ 29 | public class BeanEvent extends Event 30 | { 31 | // ======================================== 32 | // public static const 33 | // ======================================== 34 | 35 | public static const ADD_BEAN:String = "addBean"; 36 | 37 | public static const SET_UP_BEAN:String = "setUpBean"; 38 | 39 | public static const TEAR_DOWN_BEAN:String = "tearDownBean"; 40 | 41 | public static const REMOVE_BEAN:String = "removeBean"; 42 | 43 | // ======================================== 44 | // public properties 45 | // ======================================== 46 | 47 | public var source:*; 48 | 49 | public var beanName:String; 50 | 51 | // ======================================== 52 | // constructor 53 | // ======================================== 54 | 55 | /** 56 | * Constructor 57 | */ 58 | public function BeanEvent( type:String, source:* = null, beanName:String = null ) 59 | { 60 | super( type, true, true ); 61 | 62 | this.source = source; 63 | this.beanName = beanName; 64 | } 65 | 66 | // ======================================== 67 | // public methods 68 | // ======================================== 69 | 70 | /** 71 | * @return Copy of this event 72 | */ 73 | override public function clone():Event 74 | { 75 | return new BeanEvent( type, source ); 76 | } 77 | } 78 | } -------------------------------------------------------------------------------- /src/org/swizframework/events/ChainEvent.as: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Swiz Framework Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.swizframework.events 18 | { 19 | import flash.events.Event; 20 | 21 | public class ChainEvent extends Event 22 | { 23 | public static const CHAIN_START :String = "chainStart"; 24 | public static const CHAIN_STEP_COMPLETE :String = "chainStepComplete"; 25 | public static const CHAIN_STEP_ERROR :String = "chainStepError"; 26 | public static const CHAIN_COMPLETE :String = "chainComplete"; 27 | public static const CHAIN_FAIL :String = "chainFail"; 28 | 29 | public function ChainEvent( type:String, bubbles:Boolean = false, cancelable:Boolean = false ) 30 | { 31 | super( type, bubbles, cancelable ); 32 | } 33 | } 34 | } -------------------------------------------------------------------------------- /src/org/swizframework/events/SwizEvent.as: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Swiz Framework Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.swizframework.events 18 | { 19 | import flash.events.Event; 20 | 21 | import org.swizframework.core.ISwiz; 22 | 23 | /** 24 | * Dispatched when a Swiz instance is created or destroyed. 25 | */ 26 | public class SwizEvent extends Event 27 | { 28 | // ======================================== 29 | // public static const 30 | // ======================================== 31 | 32 | /** 33 | * The SwizEvent.CREATED constant defines the value of the type property 34 | * of a swizCreated event object. 35 | */ 36 | public static const CREATED:String = "swizCreated"; 37 | 38 | /** 39 | * The SwizEvent.LOAD_COMPLETE constant defines the value of the type property 40 | * of an initial load complete event object. 41 | */ 42 | public static const LOAD_COMPLETE:String = "loadComplete"; 43 | 44 | /** 45 | * The SwizEvent.DESTROYED constant defines the value of the type property 46 | * of a swizDestroyed event object. 47 | */ 48 | public static const DESTROYED:String = "swizDestroyed"; 49 | 50 | // ======================================== 51 | // public properties 52 | // ======================================== 53 | 54 | /** 55 | * The ISwiz instance that was created or destroyed. 56 | */ 57 | public var swiz:ISwiz; 58 | 59 | // ======================================== 60 | // constructor 61 | // ======================================== 62 | 63 | /** 64 | * Constructor 65 | */ 66 | public function SwizEvent( type:String, swiz:ISwiz = null ) 67 | { 68 | super( type, true, true ); 69 | this.swiz = swiz; 70 | } 71 | 72 | // ======================================== 73 | // public methods 74 | // ======================================== 75 | 76 | /** 77 | * @return Copy of this event 78 | */ 79 | override public function clone():Event 80 | { 81 | return new SwizEvent( type, swiz ); 82 | } 83 | } 84 | } -------------------------------------------------------------------------------- /src/org/swizframework/factories/MetadataHostFactory.as: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Swiz Framework Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.swizframework.factories 18 | { 19 | import flash.system.ApplicationDomain; 20 | 21 | import org.swizframework.reflection.IMetadataHost; 22 | import org.swizframework.reflection.MetadataHostClass; 23 | import org.swizframework.reflection.MetadataHostMethod; 24 | import org.swizframework.reflection.MetadataHostProperty; 25 | import org.swizframework.reflection.MethodParameter; 26 | 27 | /** 28 | * Simple factory to create the different kinds of metadata 29 | * hosts and to encapsulate the logic for determining which type 30 | * should be created. 31 | */ 32 | public class MetadataHostFactory 33 | { 34 | public function MetadataHostFactory() 35 | { 36 | 37 | } 38 | 39 | /** 40 | * Returns an IMetadataHost instance representing a property, 41 | * method or class that is decorated with metadata. 42 | * 43 | * @param hostNode XML node representing a property, method or class 44 | * @return IMetadataHost instance 45 | * 46 | * @see org.swizframework.reflection.MetadataHostClass 47 | * @see org.swizframework.reflection.MetadataHostMethod 48 | * @see org.swizframework.reflection.MetadataHostProperty 49 | */ 50 | public static function getMetadataHost( hostNode:XML, domain:ApplicationDomain ):IMetadataHost 51 | { 52 | var host:IMetadataHost; 53 | 54 | // property, method or class? 55 | var hostKind:String = hostNode.name(); 56 | 57 | if( hostKind == "type" || hostKind == "factory" ) 58 | { 59 | host = new MetadataHostClass(); 60 | if( hostKind == "type" ) 61 | host.type = domain.getDefinition( hostNode.@name.toString() ) as Class; 62 | else 63 | host.type = domain.getDefinition( hostNode.@type.toString() ) as Class; 64 | } 65 | else if( hostKind == "method" ) 66 | { 67 | host = new MetadataHostMethod(); 68 | 69 | if( hostNode.@returnType != "void" && hostNode.@returnType != "*" ) 70 | { 71 | MetadataHostMethod( host ).returnType = Class( domain.getDefinition( hostNode.@returnType ) ); 72 | } 73 | 74 | for each( var pNode:XML in hostNode.parameter ) 75 | { 76 | var pType:Class = pNode.@type == "*" ? Object : Class( domain.getDefinition( pNode.@type ) ); 77 | MetadataHostMethod( host ).parameters.push( new MethodParameter( int( pNode.@index ), pType, pNode.@optional == "true" ) ); 78 | } 79 | } 80 | else 81 | { 82 | host = new MetadataHostProperty(); 83 | host.type = hostNode.@type == "*" ? Object : Class( domain.getDefinition( hostNode.@type ) ); 84 | } 85 | 86 | host.name = ( hostNode.@uri == undefined ) ? String( hostNode.@name[ 0 ] ) : new QName( hostNode.@uri, hostNode.@name ); 87 | 88 | return host; 89 | } 90 | } 91 | } -------------------------------------------------------------------------------- /src/org/swizframework/metadata/EventTypeExpression.as: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Swiz Framework Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.swizframework.metadata 18 | { 19 | import org.swizframework.core.ISwiz; 20 | import org.swizframework.reflection.ClassConstant; 21 | import org.swizframework.reflection.Constant; 22 | import org.swizframework.reflection.TypeCache; 23 | import org.swizframework.reflection.TypeDescriptor; 24 | 25 | public class EventTypeExpression 26 | { 27 | // ======================================== 28 | // protected properties 29 | // ======================================== 30 | 31 | /** 32 | * Swiz instance. 33 | */ 34 | protected var swiz:ISwiz; 35 | 36 | /** 37 | * Event type expression. 38 | */ 39 | protected var expression:String; 40 | 41 | /** 42 | * Backing variable for eventClass property. 43 | */ 44 | protected var _eventClass:Class; 45 | 46 | [ArrayElementType("String")] 47 | /** 48 | * Backing variable for eventTypes property. 49 | */ 50 | protected var _eventTypes:Array; 51 | 52 | // ======================================== 53 | // public properties 54 | // ======================================== 55 | 56 | /** 57 | * Event Class associated for this Event type expression (if applicable). 58 | */ 59 | public function get eventClass():Class 60 | { 61 | return _eventClass; 62 | } 63 | 64 | [ArrayElementType("String")] 65 | /** 66 | * Event types for this Event type expression. 67 | */ 68 | public function get eventTypes():Array 69 | { 70 | return _eventTypes; 71 | } 72 | 73 | // ======================================== 74 | // constructor 75 | // ======================================== 76 | 77 | /** 78 | * Constructor 79 | */ 80 | public function EventTypeExpression( expression:String, swiz:ISwiz ) 81 | { 82 | this.swiz = swiz; 83 | this.expression = expression; 84 | 85 | parse(); 86 | } 87 | 88 | // ======================================== 89 | // protected methods 90 | // ======================================== 91 | 92 | /** 93 | * Parse event type expression. 94 | * 95 | * Processes an event type expression into an event class and type. Accepts a String specifying either the event type 96 | * (ex. 'type') or a class constant reference (ex. 'SomeEvent.TYPE'). If a class constant reference is specified, 97 | * it will be evaluated to obtain its String value. If a ".*" wildcard is specified, all constants will evaluated. 98 | * 99 | * Class constant references are only supported in 'strict' mode. 100 | */ 101 | protected function parse():void 102 | { 103 | if( swiz.config.strict && ClassConstant.isClassConstant( expression ) ) 104 | { 105 | _eventClass = ClassConstant.getClass( swiz.domain, expression, swiz.config.eventPackages ); 106 | 107 | if( expression.substr( -2 ) == ".*" ) 108 | { 109 | var td:TypeDescriptor = TypeCache.getTypeDescriptor( _eventClass, swiz.domain ); 110 | _eventTypes = new Array(); 111 | for each( var constant:Constant in td.constants ) 112 | _eventTypes.push( constant.value ); 113 | } 114 | else 115 | { 116 | _eventTypes = [ ClassConstant.getConstantValue( swiz.domain, _eventClass, ClassConstant.getConstantName( expression ) ) ]; 117 | } 118 | } 119 | else 120 | { 121 | _eventClass = null; 122 | _eventTypes = [ expression ]; 123 | } 124 | } 125 | } 126 | } -------------------------------------------------------------------------------- /src/org/swizframework/metadata/InjectMetadataTag.as: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Swiz Framework Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.swizframework.metadata 18 | { 19 | import org.swizframework.reflection.BaseMetadataTag; 20 | import org.swizframework.reflection.IMetadataTag; 21 | import org.swizframework.utils.logging.SwizLogger; 22 | 23 | /** 24 | * Class to represent [Inject] metadata tags. 25 | */ 26 | public class InjectMetadataTag extends BaseMetadataTag 27 | { 28 | // ======================================== 29 | // protected properties 30 | // ======================================== 31 | 32 | protected var logger:SwizLogger = SwizLogger.getLogger( this ); 33 | 34 | /** 35 | * Backing variable for read-only source property. 36 | */ 37 | protected var _source:String; 38 | 39 | /** 40 | * Backing variable for read-only destination property. 41 | */ 42 | protected var _destination:String; 43 | 44 | /** 45 | * Backing variable for read-only twoWay property. 46 | */ 47 | protected var _twoWay:Boolean = false; 48 | 49 | /** 50 | * Backing variable for read-only bind property. 51 | */ 52 | protected var _bind:Boolean = false; 53 | 54 | /** 55 | * Backing variable for read-only required property. 56 | */ 57 | protected var _required:Boolean = true; 58 | 59 | // ======================================== 60 | // public properties 61 | // ======================================== 62 | 63 | /** 64 | * Returns source attribute of [Inject] tag. 65 | * Refers to the source to be used for injection. 66 | * Is the default attribute, meaning [Inject( "someModel" )] is 67 | * equivalent to [Inject( source="someModel" )]. 68 | */ 69 | public function get source():String 70 | { 71 | return _source; 72 | } 73 | 74 | public function set source( value:String ):void 75 | { 76 | _source = value; 77 | } 78 | 79 | /** 80 | * Returns destination attribute of [Inject] tag. 81 | * Refers to the injection target. 82 | */ 83 | public function get destination():String 84 | { 85 | return _destination; 86 | } 87 | 88 | /** 89 | * Returns twoWay attribute of [Inject] tag as a Boolean value. 90 | * If true will cause a two way binding to be established. 91 | * 92 | * @default false 93 | */ 94 | public function get twoWay():Boolean 95 | { 96 | return _twoWay; 97 | } 98 | 99 | /** 100 | * Returns bind attribute of [Inject] tag as a Boolean value. 101 | * If true will cause a binding to be established. 102 | * 103 | * @default false 104 | */ 105 | public function get bind():Boolean 106 | { 107 | return _bind; 108 | } 109 | 110 | /** 111 | * Returns required attribute of [Inject] tag as a Boolean value. 112 | * If true Swiz will throw an error if it fails to fill this dependency. 113 | * 114 | * @default true 115 | */ 116 | public function get required():Boolean 117 | { 118 | return _required; 119 | } 120 | 121 | // ======================================== 122 | // constructor 123 | // ======================================== 124 | 125 | /** 126 | * Constructor sets defaultArgName. 127 | */ 128 | public function InjectMetadataTag() 129 | { 130 | defaultArgName = "source"; 131 | } 132 | 133 | // ======================================== 134 | // public methods 135 | // ======================================== 136 | 137 | override public function copyFrom( metadataTag:IMetadataTag ):void 138 | { 139 | super.copyFrom( metadataTag ); 140 | 141 | if( hasArg( "bean" ) && hasArg( "source" ) ) 142 | throw new Error( "Your metadata tag defines both a bean and source attribute. source has replaced bean, please update accordingly." ); 143 | 144 | if( hasArg( "bean" ) ) 145 | { 146 | logger.warn( "The bean attribute has been deprecated in favor of the source attribute. Please update your code accordingly. Found in {0}", metadataTag.asTag ); 147 | _source = getArg( "bean" ).value; 148 | } 149 | 150 | // source is the default attribute 151 | // [Inject( "someModel" )] == [Inject( source="someModel" )] 152 | if( hasArg( "source" ) ) 153 | _source = getArg( "source" ).value; 154 | 155 | if( hasArg( "property" ) ) 156 | { 157 | logger.warn( "The property attribute has been deprecated. Please use dot notation in your source attribute instead. Found in {0}", metadataTag.asTag ); 158 | _source += "." + getArg( "property" ).value; 159 | } 160 | 161 | if( hasArg( "destination" ) ) 162 | _destination = getArg( "destination" ).value; 163 | 164 | if( hasArg( "twoWay" ) ) 165 | _twoWay = getArg( "twoWay" ).value == "true"; 166 | 167 | if( hasArg( "bind" ) ) 168 | _bind = getArg( "bind" ).value == "true"; 169 | 170 | if( hasArg( "required" ) ) 171 | _required = getArg( "required" ).value == "true"; 172 | } 173 | } 174 | } -------------------------------------------------------------------------------- /src/org/swizframework/metadata/PostConstructMetadataTag.as: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Swiz Framework Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.swizframework.metadata 18 | { 19 | import org.swizframework.reflection.BaseMetadataTag; 20 | import org.swizframework.reflection.IMetadataTag; 21 | 22 | /** 23 | * Class to represent [PostConstruct] metadata tags. 24 | */ 25 | public class PostConstructMetadataTag extends BaseMetadataTag 26 | { 27 | // ======================================== 28 | // protected properties 29 | // ======================================== 30 | 31 | /** 32 | * Backing variable for read-only order property. 33 | */ 34 | protected var _order:int = 1; 35 | 36 | // ======================================== 37 | // public properties 38 | // ======================================== 39 | 40 | /** 41 | * Returns order attribute of [PostConstruct] tag. 42 | * Refers to the order in which the decorated methods will be executed. 43 | * Is the default attribute, meaning [PostConstruct( 2 )] is 44 | * equivalent to [PostConstruct( order="2" )]. 45 | */ 46 | public function get order():int 47 | { 48 | return _order; 49 | } 50 | 51 | // ======================================== 52 | // constructor 53 | // ======================================== 54 | 55 | /** 56 | * Constructor sets defaultArgName. 57 | */ 58 | public function PostConstructMetadataTag() 59 | { 60 | defaultArgName = "order"; 61 | } 62 | 63 | // ======================================== 64 | // public methods 65 | // ======================================== 66 | 67 | override public function copyFrom( metadataTag:IMetadataTag ):void 68 | { 69 | super.copyFrom( metadataTag ); 70 | 71 | if( hasArg( "order" ) ) 72 | _order = int( getArg( "order" ).value ); 73 | } 74 | } 75 | } -------------------------------------------------------------------------------- /src/org/swizframework/metadata/PreDestroyMetadataTag.as: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Swiz Framework Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.swizframework.metadata 18 | { 19 | import org.swizframework.reflection.BaseMetadataTag; 20 | import org.swizframework.reflection.IMetadataTag; 21 | 22 | /** 23 | * Class to represent [PreDestroy] metadata tags. 24 | */ 25 | public class PreDestroyMetadataTag extends BaseMetadataTag 26 | { 27 | // ======================================== 28 | // protected properties 29 | // ======================================== 30 | 31 | /** 32 | * Backing variable for read-only order property. 33 | */ 34 | protected var _order:int = 1; 35 | 36 | // ======================================== 37 | // public properties 38 | // ======================================== 39 | 40 | /** 41 | * Returns order attribute of [PreDestroy] tag. 42 | * Refers to the order in which the decorated methods will be executed. 43 | * Is the default attribute, meaning [PreDestroy( 2 )] is 44 | * equivalent to [PreDestroy( order="2" )]. 45 | */ 46 | public function get order():int 47 | { 48 | return _order; 49 | } 50 | 51 | // ======================================== 52 | // constructor 53 | // ======================================== 54 | 55 | /** 56 | * Constructor sets defaultArgName. 57 | */ 58 | public function PreDestroyMetadataTag() 59 | { 60 | defaultArgName = "order"; 61 | } 62 | 63 | // ======================================== 64 | // public methods 65 | // ======================================== 66 | 67 | override public function copyFrom( metadataTag:IMetadataTag ):void 68 | { 69 | super.copyFrom( metadataTag ); 70 | 71 | if( hasArg( "order" ) ) 72 | _order = int( getArg( "order" ).value ); 73 | } 74 | } 75 | } -------------------------------------------------------------------------------- /src/org/swizframework/processors/BaseMetadataProcessor.as: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Swiz Framework Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.swizframework.processors 18 | { 19 | import flash.events.EventDispatcher; 20 | 21 | import org.swizframework.core.Bean; 22 | import org.swizframework.core.IBeanFactory; 23 | import org.swizframework.core.ISwiz; 24 | import org.swizframework.reflection.IMetadataTag; 25 | 26 | /** 27 | * Metadata Processor 28 | */ 29 | public class BaseMetadataProcessor extends EventDispatcher implements IMetadataProcessor 30 | { 31 | // ======================================== 32 | // protected properties 33 | // ======================================== 34 | 35 | protected var swiz:ISwiz; 36 | protected var beanFactory:IBeanFactory; 37 | 38 | protected var _metadataNames:Array; 39 | protected var _metadataClass:Class; 40 | 41 | // ======================================== 42 | // public properties 43 | // ======================================== 44 | 45 | /** 46 | * @inheritDoc 47 | */ 48 | public function get metadataNames():Array 49 | { 50 | return _metadataNames; 51 | } 52 | 53 | /** 54 | * @inheritDoc 55 | */ 56 | public function get metadataClass():Class 57 | { 58 | return _metadataClass; 59 | } 60 | 61 | /** 62 | * 63 | */ 64 | public function get priority():int 65 | { 66 | return ProcessorPriority.DEFAULT; 67 | } 68 | 69 | // ======================================== 70 | // constructor 71 | // ======================================== 72 | 73 | /** 74 | * Constructor 75 | */ 76 | public function BaseMetadataProcessor( metadataNames:Array, metadataClass:Class = null ) 77 | { 78 | super(); 79 | 80 | this._metadataNames = metadataNames; 81 | this._metadataClass = metadataClass; 82 | } 83 | 84 | // ======================================== 85 | // public methods 86 | // ======================================== 87 | 88 | /** 89 | * @inheritDoc 90 | */ 91 | public function init( swiz:ISwiz ):void 92 | { 93 | this.swiz = swiz; 94 | this.beanFactory = swiz.beanFactory; 95 | } 96 | 97 | /** 98 | * @inheritDoc 99 | */ 100 | public function setUpMetadataTags( metadataTags:Array, bean:Bean ):void 101 | { 102 | var metadataTag:IMetadataTag; 103 | 104 | if( metadataClass != null ) 105 | { 106 | for( var i:int = 0; i < metadataTags.length; i++ ) 107 | { 108 | metadataTag = metadataTags[ i ] as IMetadataTag; 109 | metadataTags.splice( i, 1, createMetadataTag( metadataTag ) ); 110 | } 111 | } 112 | 113 | for each( metadataTag in metadataTags ) 114 | { 115 | setUpMetadataTag( metadataTag, bean ); 116 | } 117 | } 118 | 119 | public function setUpMetadataTag( metadataTag:IMetadataTag, bean:Bean ):void 120 | { 121 | // empty, subclasses should override 122 | } 123 | 124 | /** 125 | * @inheritDoc 126 | */ 127 | public function tearDownMetadataTags( metadataTags:Array, bean:Bean ):void 128 | { 129 | var metadataTag:IMetadataTag; 130 | 131 | if( metadataClass != null ) 132 | { 133 | for( var i:int = 0; i < metadataTags.length; i++ ) 134 | { 135 | metadataTag = metadataTags[ i ] as IMetadataTag; 136 | metadataTags.splice( i, 1, createMetadataTag( metadataTag ) ); 137 | } 138 | } 139 | 140 | for each( metadataTag in metadataTags ) 141 | { 142 | tearDownMetadataTag( metadataTag, bean ); 143 | } 144 | } 145 | 146 | public function tearDownMetadataTag( metadataTag:IMetadataTag, bean:Bean ):void 147 | { 148 | // empty, subclasses should override 149 | } 150 | 151 | protected function createMetadataTag( metadataTag:IMetadataTag ):IMetadataTag 152 | { 153 | var tag:IMetadataTag = new metadataClass(); 154 | tag.copyFrom( metadataTag ); 155 | return tag; 156 | } 157 | } 158 | } -------------------------------------------------------------------------------- /src/org/swizframework/processors/DispatcherProcessor.as: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Swiz Framework Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.swizframework.processors 18 | { 19 | import flash.events.IEventDispatcher; 20 | 21 | import org.swizframework.core.Bean; 22 | import org.swizframework.core.SwizConfig; 23 | import org.swizframework.reflection.IMetadataTag; 24 | import org.swizframework.reflection.MetadataArg; 25 | 26 | /** 27 | * Dispatcher Processor 28 | */ 29 | public class DispatcherProcessor extends BaseMetadataProcessor 30 | { 31 | // ======================================== 32 | // protected static constants 33 | // ======================================== 34 | 35 | protected static const DISPATCHER:String = "Dispatcher"; 36 | 37 | // ======================================== 38 | // public properties 39 | // ======================================== 40 | 41 | /** 42 | * 43 | */ 44 | override public function get priority():int 45 | { 46 | return ProcessorPriority.DISPATCHER; 47 | } 48 | 49 | // ======================================== 50 | // constructor 51 | // ======================================== 52 | 53 | /** 54 | * Constructor 55 | */ 56 | public function DispatcherProcessor( metadataNames:Array = null ) 57 | { 58 | super( ( metadataNames == null ) ? [ DISPATCHER ] : metadataNames ); 59 | } 60 | 61 | // ======================================== 62 | // public methods 63 | // ======================================== 64 | 65 | /** 66 | * @inheritDoc 67 | */ 68 | override public function setUpMetadataTag( metadataTag:IMetadataTag, bean:Bean ):void 69 | { 70 | var scope:String; 71 | 72 | if( metadataTag.hasArg( "scope" ) ) 73 | scope = metadataTag.getArg( "scope" ).value; 74 | else if( metadataTag.args.length > 0 && MetadataArg(metadataTag.args[0]).key == "" ) 75 | scope = MetadataArg(metadataTag.args[0]).value; 76 | 77 | var dispatcher:IEventDispatcher = null; 78 | 79 | // if the mediate tag defines a scope, set proper dispatcher, else use defaults 80 | if( scope == SwizConfig.GLOBAL_DISPATCHER ) 81 | dispatcher = swiz.globalDispatcher; 82 | else if( scope == SwizConfig.LOCAL_DISPATCHER ) 83 | dispatcher = swiz.dispatcher; 84 | else 85 | dispatcher = swiz.config.defaultDispatcher == SwizConfig.LOCAL_DISPATCHER ? swiz.dispatcher : swiz.globalDispatcher; 86 | 87 | bean.source[ metadataTag.host.name ] = dispatcher; 88 | } 89 | 90 | /** 91 | * @inheritDoc 92 | */ 93 | override public function tearDownMetadataTag( metadataTag:IMetadataTag, bean:Bean ):void 94 | { 95 | bean.source[ metadataTag.host.name ] = null; 96 | } 97 | } 98 | } -------------------------------------------------------------------------------- /src/org/swizframework/processors/IBeanProcessor.as: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Swiz Framework Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.swizframework.processors 18 | { 19 | import org.swizframework.core.Bean; 20 | 21 | public interface IBeanProcessor extends IProcessor 22 | { 23 | function setUpBean( bean:Bean ):void; 24 | 25 | function tearDownBean( bean:Bean ):void; 26 | } 27 | } -------------------------------------------------------------------------------- /src/org/swizframework/processors/IFactoryProcessor.as: -------------------------------------------------------------------------------- 1 | package org.swizframework.processors 2 | { 3 | import org.swizframework.core.IBeanFactory; 4 | 5 | public interface IFactoryProcessor extends IProcessor 6 | { 7 | // ======================================== 8 | // public methods 9 | // ======================================== 10 | 11 | /** 12 | * Process the swin bean factory itself. Executes after all beans are loded but NOT yet set up. 13 | * 14 | * @param factory: the IBeanFactory instance to process 15 | */ 16 | function setUpFactory( factory:IBeanFactory ):void; 17 | } 18 | } -------------------------------------------------------------------------------- /src/org/swizframework/processors/IMetadataProcessor.as: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Swiz Framework Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.swizframework.processors 18 | { 19 | import org.swizframework.core.Bean; 20 | 21 | public interface IMetadataProcessor extends IProcessor 22 | { 23 | // ======================================== 24 | // public properties 25 | // ======================================== 26 | 27 | /** 28 | * Name of metadata tags in which this processor is interested. 29 | */ 30 | function get metadataNames():Array; 31 | 32 | // ======================================== 33 | // public methods 34 | // ======================================== 35 | 36 | /** 37 | * Process the metadata tags for the provided Bean 38 | * so they are ready to use. 39 | * 40 | * @param metadataTags Array of tags culled from this Bean's TypeDescriptor 41 | * @param bean Bean instance to process 42 | */ 43 | function setUpMetadataTags( metadataTags:Array, bean:Bean ):void; 44 | 45 | /** 46 | * Process the metadata tags for the provided Bean 47 | * so they are ready to be cleaned up. 48 | * 49 | * @param metadataTags Array of tags culled from this Bean's TypeDescriptor 50 | * @param bean Bean instance to process 51 | */ 52 | function tearDownMetadataTags( metadataTags:Array, bean:Bean ):void; 53 | } 54 | } -------------------------------------------------------------------------------- /src/org/swizframework/processors/IProcessor.as: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Swiz Framework Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.swizframework.processors 18 | { 19 | import org.swizframework.core.ISwiz; 20 | 21 | /** 22 | * Base interface that ensures all implementers have a reference to the containing 23 | * instance of Swiz and a priority to determine 24 | * their place in line. 25 | */ 26 | public interface IProcessor 27 | { 28 | /** 29 | * Method used to set reference to parent Swiz instance. 30 | */ 31 | function init( swiz:ISwiz ):void; 32 | 33 | /** 34 | * Read-only property used to specify this processor's priority in the list of processors. 35 | */ 36 | function get priority():int; 37 | } 38 | } -------------------------------------------------------------------------------- /src/org/swizframework/processors/PostConstructProcessor.as: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Swiz Framework Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.swizframework.processors 18 | { 19 | import org.swizframework.core.Bean; 20 | import org.swizframework.metadata.PostConstructMetadataTag; 21 | import org.swizframework.reflection.IMetadataTag; 22 | 23 | /** 24 | * PostConstruct Processor 25 | */ 26 | public class PostConstructProcessor extends BaseMetadataProcessor 27 | { 28 | // ======================================== 29 | // protected static constants 30 | // ======================================== 31 | 32 | protected static const POST_CONSTRUCT : String = "PostConstruct"; 33 | 34 | // ======================================== 35 | // public properties 36 | // ======================================== 37 | 38 | /** 39 | * 40 | */ 41 | override public function get priority() : int 42 | { 43 | return ProcessorPriority.POST_CONSTRUCT; 44 | } 45 | 46 | // ======================================== 47 | // constructor 48 | // ======================================== 49 | 50 | /** 51 | * Constructor 52 | */ 53 | public function PostConstructProcessor( metadataNames : Array = null ) 54 | { 55 | super( ( metadataNames == null ) ? [ POST_CONSTRUCT ] : metadataNames, PostConstructMetadataTag ); 56 | } 57 | 58 | // ======================================== 59 | // public methods 60 | // ======================================== 61 | 62 | /** 63 | * @inheritDoc 64 | */ 65 | override public function setUpMetadataTags( metadataTags : Array, bean : Bean ) : void 66 | { 67 | super.setUpMetadataTags( metadataTags, bean ); 68 | 69 | metadataTags.sortOn( "order", Array.NUMERIC ); 70 | 71 | for each ( var metadataTag : IMetadataTag in metadataTags ) 72 | { 73 | var f : Function = bean.source[ metadataTag.host.name ]; 74 | f.apply(); 75 | } 76 | } 77 | } 78 | } -------------------------------------------------------------------------------- /src/org/swizframework/processors/PreDestroyProcessor.as: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Swiz Framework Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.swizframework.processors 18 | { 19 | import org.swizframework.core.Bean; 20 | import org.swizframework.metadata.PreDestroyMetadataTag; 21 | import org.swizframework.reflection.IMetadataTag; 22 | 23 | /** 24 | * PreDestroy Processor 25 | */ 26 | public class PreDestroyProcessor extends BaseMetadataProcessor 27 | { 28 | // ======================================== 29 | // protected static constants 30 | // ======================================== 31 | 32 | protected static const PRE_DESTROY:String = "PreDestroy"; 33 | 34 | // ======================================== 35 | // public properties 36 | // ======================================== 37 | 38 | /** 39 | * 40 | */ 41 | override public function get priority():int 42 | { 43 | return ProcessorPriority.PRE_DESTROY; 44 | } 45 | 46 | // ======================================== 47 | // constructor 48 | // ======================================== 49 | 50 | /** 51 | * Constructor 52 | */ 53 | public function PreDestroyProcessor( metadataNames:Array = null ) 54 | { 55 | super( ( metadataNames == null ) ? [ PRE_DESTROY ] : metadataNames, PreDestroyMetadataTag ); 56 | } 57 | 58 | // ======================================== 59 | // public methods 60 | // ======================================== 61 | 62 | /** 63 | * @inheritDoc 64 | */ 65 | override public function tearDownMetadataTags( metadataTags:Array, bean:Bean ):void 66 | { 67 | super.tearDownMetadataTags( metadataTags, bean ); 68 | 69 | metadataTags.sortOn( "order", Array.NUMERIC ); 70 | 71 | for each( var metadataTag:IMetadataTag in metadataTags ) 72 | { 73 | var f:Function = bean.source[ metadataTag.host.name ]; 74 | f.apply(); 75 | } 76 | } 77 | } 78 | } -------------------------------------------------------------------------------- /src/org/swizframework/processors/ProcessorPriority.as: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Swiz Framework Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.swizframework.processors 18 | { 19 | /** 20 | * The ProcessorPriority class defines constant values for the priority property of IProcessor instances. 21 | * 22 | *

The higher the number, the higher the priority of the processor. All processors with priority N will be executed before 23 | * processors with priority N - 1. If two or more processors share the same priority, they are processed in the order in 24 | * which they were added.

25 | * 26 | *

Priorities can be positive, 0, or negative. The default priority is 500.

27 | * 28 | *

You should not write code that depends on the numeric values of these constants. They are subject to change in future versions of Swiz.

29 | */ 30 | public final class ProcessorPriority 31 | { 32 | 33 | /** 34 | * Built-in AutoProxyProcessor runs before any bean setup (as an IFactoryProcessor). 35 | * 36 | * @see org.swizframework.processors.AutoProxyProcessor 37 | */ 38 | public static const AUTO_PROXY :int = 900; 39 | 40 | /** 41 | * Built-in PreDestroyProcessor runs during tear down to allow components to do any 42 | * necessary cleanup to ensure proper disposal. 43 | * 44 | * @see org.swizframework.processors.PreDestroyProcessor 45 | */ 46 | public static const PRE_DESTROY :int = 800; 47 | 48 | /** 49 | * Built-in InjectProcessor is the second native processor run to 50 | * satisfy declared dependencies in any beans/components provided to Swiz. 51 | * 52 | * @see org.swizframework.processors.InjectProcessor 53 | */ 54 | public static const INJECT :int = 700; 55 | 56 | /** 57 | * Built-in EventHandlerProcessor uses this priority. 58 | * 59 | * @see org.swizframework.processors.EventHandlerProcessor 60 | */ 61 | public static const EVENT_HANDLER :int = 600; 62 | 63 | /** 64 | * Built-in DispatcherProcessor uses this priority. 65 | * 66 | * @see org.swizframework.processors.DispatcherProcessor 67 | */ 68 | public static const DISPATCHER :int = 500; 69 | 70 | /** 71 | * Default priority used by BaseMetadataProcessor. 72 | * 73 | * @see org.swizframework.processors.BaseMetadataProcessor 74 | */ 75 | public static const DEFAULT :int = 400; 76 | 77 | /** 78 | * Built-in SwizInterfaceProcessor runs after DefaultProcessors 79 | * to allow components to do any necessary initialization based on internal swiz interfaces. 80 | * 81 | * @see org.swizframework.processors.PostConstructProcessor 82 | */ 83 | public static const SWIZ_INTERFACE :int = 300; 84 | 85 | /** 86 | * Built-in PostConstructProcessor runs after InjectProcessor 87 | * to allow components to do any necessary initialization once their dependencies have been satisfied. 88 | * 89 | * @see org.swizframework.processors.PostConstructProcessor 90 | */ 91 | public static const POST_CONSTRUCT :int = 200; 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /src/org/swizframework/processors/SwizInterfaceProcessor.as: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Swiz Framework Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.swizframework.processors 18 | { 19 | import org.swizframework.core.Bean; 20 | import org.swizframework.core.IBeanFactoryAware; 21 | import org.swizframework.core.IDispatcherAware; 22 | import org.swizframework.core.IDisposable; 23 | import org.swizframework.core.IInitializing; 24 | import org.swizframework.core.ISwiz; 25 | import org.swizframework.core.ISwizAware; 26 | 27 | public class SwizInterfaceProcessor implements IBeanProcessor 28 | { 29 | private var swiz:ISwiz; 30 | 31 | public function SwizInterfaceProcessor() 32 | { 33 | } 34 | 35 | public function setUpBean( bean:Bean ):void 36 | { 37 | var obj:* = bean.type; 38 | 39 | if( obj is ISwizAware ) 40 | ISwizAware( obj ).swiz = swiz; 41 | if( obj is IBeanFactoryAware ) 42 | IBeanFactoryAware( obj ).beanFactory = swiz.beanFactory; 43 | if( obj is IDispatcherAware ) 44 | IDispatcherAware( obj ).dispatcher = swiz.dispatcher; 45 | if( obj is IInitializing ) 46 | IInitializing( obj ).afterPropertiesSet(); 47 | } 48 | 49 | public function tearDownBean( bean:Bean ):void 50 | { 51 | var obj:* = bean.type; 52 | 53 | if( obj is ISwizAware ) 54 | ISwizAware( obj ).swiz = null; 55 | if( obj is IBeanFactoryAware ) 56 | IBeanFactoryAware( obj ).beanFactory = null; 57 | if( obj is IDispatcherAware ) 58 | IDispatcherAware( obj ).dispatcher = null; 59 | if( obj is IDisposable ) 60 | IDisposable( obj ).destroy(); 61 | } 62 | 63 | public function init( swiz:ISwiz ):void 64 | { 65 | this.swiz = swiz; 66 | } 67 | 68 | public function get priority():int 69 | { 70 | return ProcessorPriority.SWIZ_INTERFACE; 71 | } 72 | } 73 | } -------------------------------------------------------------------------------- /src/org/swizframework/reflection/BaseMetadataHost.as: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Swiz Framework Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.swizframework.reflection 18 | { 19 | /** 20 | * Base implementation of the IMetadataHost interface. 21 | * Implements getters and setters and initializes metadataTags Array. 22 | * 23 | * @see org.swizframework.reflection.IMetadataHost 24 | * @see org.swizframework.reflection.MetadataHostClass 25 | * @see org.swizframework.reflection.MetadataHostMethod 26 | * @see org.swizframework.reflection.MetadataHostProperty 27 | */ 28 | public class BaseMetadataHost implements IMetadataHost 29 | { 30 | // ======================================== 31 | // protected properties 32 | // ======================================== 33 | 34 | /** 35 | * Backing variable for name getter/setter. 36 | */ 37 | protected var _name:*; 38 | 39 | /** 40 | * Backing variable for type getter/setter. 41 | */ 42 | protected var _type:Class; 43 | 44 | /** 45 | * Backing variable for metadataTags getter/setter. 46 | */ 47 | protected var _metadataTags:Array; 48 | 49 | // ======================================== 50 | // public properties 51 | // ======================================== 52 | 53 | /** 54 | * @inheritDoc 55 | */ 56 | public function get name():* 57 | { 58 | return _name; 59 | } 60 | 61 | public function set name( value:* ):void 62 | { 63 | _name = value; 64 | } 65 | 66 | /** 67 | * @inheritDoc 68 | */ 69 | public function get type():Class 70 | { 71 | return _type; 72 | } 73 | 74 | public function set type( value:Class ):void 75 | { 76 | _type = value; 77 | } 78 | 79 | [ArrayElementType( "org.swizframework.reflection.IMetadataTag" )] 80 | 81 | /** 82 | * @inheritDoc 83 | */ 84 | public function get metadataTags():Array 85 | { 86 | return _metadataTags; 87 | } 88 | 89 | public function set metadataTags( value:Array ):void 90 | { 91 | _metadataTags = value; 92 | } 93 | 94 | public function getMetadataTagByName( name:String ):IMetadataTag 95 | { 96 | for each ( var metadataTag:IMetadataTag in metadataTags ) 97 | { 98 | if ( metadataTag.name == name ) 99 | { 100 | return metadataTag; 101 | } 102 | } 103 | return null; 104 | } 105 | 106 | public function hasMetadataTagByName( name:String ):Boolean 107 | { 108 | return getMetadataTagByName( name ) != null; 109 | } 110 | 111 | // ======================================== 112 | // constructor 113 | // ======================================== 114 | 115 | /** 116 | * Constructor initializes metadataTags Array. 117 | */ 118 | public function BaseMetadataHost() 119 | { 120 | metadataTags = []; 121 | } 122 | } 123 | } -------------------------------------------------------------------------------- /src/org/swizframework/reflection/BaseMetadataTag.as: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Swiz Framework Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.swizframework.reflection 18 | { 19 | /** 20 | * Base implementation of the IMetadataTag interface. 21 | * Implements getters and setters, hasArg and getArg 22 | * methods. Also adds defaultArgName support and defines 23 | * asString method for reconstructing the tag as it 24 | * looks in the source code (mostly for debugging purposes). 25 | */ 26 | public class BaseMetadataTag implements IMetadataTag 27 | { 28 | // ======================================== 29 | // protected properties 30 | // ======================================== 31 | 32 | /** 33 | * Backing variable for name property. 34 | */ 35 | protected var _name:String; 36 | 37 | /** 38 | * Backing variable for args property. 39 | */ 40 | protected var _args:Array; 41 | 42 | /** 43 | * Backing variable for host property. 44 | */ 45 | protected var _host:IMetadataHost; 46 | 47 | /** 48 | * Backing variable for defaultArgName property. 49 | */ 50 | protected var _defaultArgName:String; 51 | 52 | // ======================================== 53 | // public properties 54 | // ======================================== 55 | 56 | /** 57 | * @inheritDoc 58 | */ 59 | public function get name():String 60 | { 61 | return _name; 62 | } 63 | 64 | public function set name( value:String ):void 65 | { 66 | _name = value; 67 | } 68 | 69 | [ArrayElementType( "org.swizframework.reflection.MetadataArg" )] 70 | 71 | /** 72 | * @inheritDoc 73 | */ 74 | public function get args():Array 75 | { 76 | return _args; 77 | } 78 | 79 | public function set args( value:Array ):void 80 | { 81 | _args = value; 82 | } 83 | 84 | /** 85 | * @inheritDoc 86 | */ 87 | public function get host():IMetadataHost 88 | { 89 | return _host; 90 | } 91 | 92 | public function set host( value:IMetadataHost ):void 93 | { 94 | _host = value; 95 | } 96 | 97 | /** 98 | * Name that will be assumed/used when a default argument value is provided, 99 | * e.g. [Inject( "someModel" )] 100 | */ 101 | public function get defaultArgName():String 102 | { 103 | return _defaultArgName; 104 | } 105 | 106 | public function set defaultArgName( value:String ):void 107 | { 108 | _defaultArgName = value; 109 | } 110 | 111 | /** 112 | * String showing what this tag looks like in code. Useful for debugging and log messages. 113 | */ 114 | public function get asTag():String 115 | { 116 | return toString(); 117 | } 118 | 119 | // ======================================== 120 | // constructor 121 | // ======================================== 122 | 123 | /** 124 | * Constructor 125 | */ 126 | public function BaseMetadataTag() 127 | { 128 | 129 | } 130 | 131 | // ======================================== 132 | // public methods 133 | // ======================================== 134 | 135 | /** 136 | * @inheritDoc 137 | */ 138 | public function hasArg( argName:String ):Boolean 139 | { 140 | for each( var arg:MetadataArg in args ) 141 | { 142 | if( arg.key == argName || ( arg.key == "" && argName == defaultArgName ) ) 143 | return true; 144 | } 145 | 146 | return false; 147 | } 148 | 149 | /** 150 | * @inheritDoc 151 | */ 152 | public function getArg( argName:String ):MetadataArg 153 | { 154 | for each( var arg:MetadataArg in args ) 155 | { 156 | if( arg.key == argName || ( arg.key == "" && argName == defaultArgName ) ) 157 | return arg; 158 | } 159 | 160 | // TODO: throw error 161 | return null; 162 | } 163 | 164 | public function copyFrom( metadataTag:IMetadataTag ):void 165 | { 166 | name = metadataTag.name; 167 | args = metadataTag.args; 168 | host = metadataTag.host; 169 | } 170 | 171 | /** 172 | * Utility method useful for development and debugging 173 | * that returns string showing what this tag looked like defined in code. 174 | * 175 | * @return String representation of this tag as it looks in code. 176 | */ 177 | public function toString():String 178 | { 179 | var str:String = "[" + name; 180 | 181 | if( args != null && args.length > 0 ) 182 | { 183 | str += "( "; 184 | for( var i:int = 0; i < args.length; i++ ) 185 | { 186 | var arg:MetadataArg = args[ i ]; 187 | 188 | if( arg.key != "" ) 189 | str += arg.key + "="; 190 | 191 | str += "\"" + arg.value + "\"" 192 | 193 | if( i + 1 < args.length ) 194 | str += ", "; 195 | } 196 | str += " )"; 197 | } 198 | 199 | str += "]"; 200 | return str; 201 | } 202 | } 203 | } -------------------------------------------------------------------------------- /src/org/swizframework/reflection/BindableMetadataHost.as: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Swiz Framework Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.swizframework.reflection 18 | { 19 | /** 20 | * Representation of a property that has been decorated with metadata. 21 | */ 22 | public class BindableMetadataHost extends BaseMetadataHost 23 | { 24 | // ======================================== 25 | // public properties 26 | // ======================================== 27 | 28 | /** 29 | * @return Flag indicating whether or not this property has been made bindable. 30 | */ 31 | public function get isBindable():Boolean 32 | { 33 | for each( var tag:IMetadataTag in metadataTags ) 34 | { 35 | if( tag.name == "Bindable" ) 36 | return true; 37 | } 38 | 39 | return false; 40 | } 41 | 42 | // ======================================== 43 | // constructor 44 | // ======================================== 45 | 46 | public function BindableMetadataHost() 47 | { 48 | super(); 49 | } 50 | } 51 | } -------------------------------------------------------------------------------- /src/org/swizframework/reflection/Constant.as: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Swiz Framework Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.swizframework.reflection 18 | { 19 | public class Constant 20 | { 21 | /** 22 | * 23 | */ 24 | public var name:String; 25 | 26 | /** 27 | * 28 | */ 29 | public var value:String; 30 | 31 | public function Constant( name:String, value:String ) 32 | { 33 | this.name = name; 34 | this.value = value; 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /src/org/swizframework/reflection/IMetadataHost.as: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Swiz Framework Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.swizframework.reflection 18 | { 19 | /** 20 | * The IMetadataHost interface is a representation of a public property, method 21 | * or class that is decorated with metadata. 22 | */ 23 | public interface IMetadataHost 24 | { 25 | /** 26 | * Name of the property/method/class. 27 | */ 28 | function get name():*; 29 | function set name( value:* ):void; 30 | 31 | /** 32 | * Type of the property/method/class. 33 | */ 34 | function get type():Class; 35 | function set type( value:Class ):void; 36 | 37 | [ArrayElementType( "org.swizframework.reflection.IMetadataTag" )] 38 | /** 39 | * Array of metadata tags that decorate the property/method/class. 40 | */ 41 | function get metadataTags():Array; 42 | function set metadataTags( value:Array ):void; 43 | 44 | /** 45 | * Get metadata tag by name 46 | */ 47 | function getMetadataTagByName( name:String ):IMetadataTag; 48 |   49 | /** 50 |  * Has metadata tag by name 51 |  */ 52 | function hasMetadataTagByName( name:String ):Boolean; 53 | } 54 | } -------------------------------------------------------------------------------- /src/org/swizframework/reflection/IMetadataTag.as: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Swiz Framework Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.swizframework.reflection 18 | { 19 | /** 20 | * The IMetadataTag interface is a representation of a metadata tag 21 | * that has been defined in source code. 22 | */ 23 | public interface IMetadataTag 24 | { 25 | /** 26 | * Name of the tag, e.g. "Bindable" from [Bindable]. 27 | */ 28 | function get name():String; 29 | function set name( value:String ):void; 30 | 31 | [ArrayElementType( "org.swizframework.reflection.MetadataArg" )] 32 | /** 33 | * Array of arguments defined in the tag. 34 | * 35 | * @see org.swizframework.reflection.MetadataArg 36 | */ 37 | function get args():Array; 38 | function set args( value:Array ):void; 39 | 40 | /** 41 | * Element (class, method or property) on which the metadata tag is defined. 42 | */ 43 | function get host():IMetadataHost; 44 | function set host( value:IMetadataHost ):void; 45 | 46 | /** 47 | * String showing what this tag looks like in code. Useful for debugging and log messages. 48 | */ 49 | function get asTag():String; 50 | 51 | /** 52 | * @param argName Name of argument whose existence on this tag will be checked. 53 | * @return Flag indicating whether or not this tag contains an argument for the given name. 54 | */ 55 | function hasArg( argName:String ):Boolean; 56 | 57 | /** 58 | * @param argName Name of argument to retrieve. 59 | * @return Argument for the given name. 60 | */ 61 | function getArg( argName:String ):MetadataArg; 62 | 63 | function copyFrom( metadataTag:IMetadataTag ):void; 64 | 65 | function toString():String; 66 | } 67 | } -------------------------------------------------------------------------------- /src/org/swizframework/reflection/MetadataArg.as: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Swiz Framework Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.swizframework.reflection 18 | { 19 | /** 20 | * Simple key/value representation of a metadata tag argument. 21 | */ 22 | public class MetadataArg 23 | { 24 | // ======================================== 25 | // public properties 26 | // ======================================== 27 | 28 | /** 29 | * Name of metadata tag argument, e.g. "source" for [Inject( source="someModel" )] 30 | */ 31 | public var key:String; 32 | 33 | /** 34 | * Value of metadata tag argument, e.g. "someModel" for [Inject( source="someModel" )] 35 | */ 36 | public var value:String; 37 | 38 | // ======================================== 39 | // constructor 40 | // ======================================== 41 | 42 | /** 43 | * Constructor sets initial values of required parameters. 44 | * 45 | * @param key 46 | * @param value 47 | */ 48 | public function MetadataArg( key:String, value:String ) 49 | { 50 | this.key = key; 51 | this.value = value; 52 | } 53 | 54 | // ======================================== 55 | // public methods 56 | // ======================================== 57 | 58 | /** 59 | * @return String representation of this metadata tag argument. 60 | */ 61 | public function toString():String 62 | { 63 | var str:String = "MetadataArg: "; 64 | 65 | str += key + " = " + value + "\n"; 66 | 67 | return str; 68 | } 69 | } 70 | } -------------------------------------------------------------------------------- /src/org/swizframework/reflection/MetadataHostClass.as: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Swiz Framework Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.swizframework.reflection 18 | { 19 | /** 20 | * Representation of a class that has been decorated with class level metadata. 21 | */ 22 | public class MetadataHostClass extends BindableMetadataHost 23 | { 24 | // ======================================== 25 | // constructor 26 | // ======================================== 27 | 28 | public function MetadataHostClass() 29 | { 30 | super(); 31 | } 32 | } 33 | } -------------------------------------------------------------------------------- /src/org/swizframework/reflection/MetadataHostMethod.as: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Swiz Framework Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.swizframework.reflection 18 | { 19 | /** 20 | * Representation of a method that has been decorated with metadata. 21 | */ 22 | public class MetadataHostMethod extends BaseMetadataHost 23 | { 24 | // ======================================== 25 | // protected properties 26 | // ======================================== 27 | 28 | /** 29 | * Backing variable for returnType getter/setter. 30 | */ 31 | protected var _returnType:Class; 32 | 33 | /** 34 | * Backing variable for parameters getter/setter. 35 | */ 36 | protected var _parameters:Array = []; 37 | 38 | // ======================================== 39 | // public properties 40 | // ======================================== 41 | 42 | /** 43 | * @return Reference to type returned by this method. Will be null if return type is void or * . 44 | */ 45 | public function get returnType():Class 46 | { 47 | return _returnType; 48 | } 49 | 50 | public function set returnType( value:Class ):void 51 | { 52 | _returnType = value; 53 | } 54 | 55 | [ArrayElementType( "org.swizframework.reflection.MethodParameter" )] 56 | 57 | /** 58 | * @return Array of MethodParameter instances representing this method's parameters. 59 | */ 60 | public function get parameters():Array 61 | { 62 | return _parameters; 63 | } 64 | 65 | /** 66 | * @return The total number of parameters for the method. 67 | */ 68 | public function get parameterCount():int 69 | { 70 | return parameters.length; 71 | } 72 | 73 | /** 74 | * @returns The number of required parameters for the method. 75 | */ 76 | public function get requiredParameterCount():int 77 | { 78 | var requiredParameterCount:int = 0; 79 | 80 | for each( var parameter:MethodParameter in parameters ) 81 | { 82 | if( !parameter.optional ) 83 | requiredParameterCount++; 84 | } 85 | 86 | return requiredParameterCount; 87 | } 88 | 89 | // ======================================== 90 | // constructor 91 | // ======================================== 92 | 93 | /** 94 | * Constructor sets returnType property based on value found in hostNode XML node, 95 | * as long as return type is not void or * . Also populates parameters 96 | * property from information found in hostNode XML node. 97 | * 98 | * @param hostNode XML node from describeType output that represents this method. 99 | */ 100 | public function MetadataHostMethod() 101 | { 102 | super(); 103 | } 104 | } 105 | } -------------------------------------------------------------------------------- /src/org/swizframework/reflection/MetadataHostProperty.as: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Swiz Framework Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.swizframework.reflection 18 | { 19 | /** 20 | * Representation of a property that has been decorated with metadata. 21 | */ 22 | public class MetadataHostProperty extends BindableMetadataHost 23 | { 24 | // ======================================== 25 | // constructor 26 | // ======================================== 27 | 28 | public function MetadataHostProperty() 29 | { 30 | super(); 31 | } 32 | } 33 | } -------------------------------------------------------------------------------- /src/org/swizframework/reflection/MethodParameter.as: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Swiz Framework Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.swizframework.reflection 18 | { 19 | /** 20 | * Representation of a method parameter. 21 | */ 22 | public class MethodParameter 23 | { 24 | // ======================================== 25 | // public properties 26 | // ======================================== 27 | 28 | /** 29 | * Index of this parameter in method signature. 30 | */ 31 | public var index:int; 32 | 33 | /** 34 | * Type of this parameter. Null if typed as * . 35 | */ 36 | public var type:Class; 37 | 38 | /** 39 | * Flag indicating whether or not this parameter is optional. 40 | */ 41 | public var optional:Boolean; 42 | 43 | // ======================================== 44 | // constructor 45 | // ======================================== 46 | 47 | /** 48 | * Constructor sets initial values of required parameters. 49 | * 50 | * @param index 51 | * @param type 52 | * @param optional 53 | */ 54 | public function MethodParameter( index:int, type:Class, optional:Boolean ) 55 | { 56 | this.index = index; 57 | this.type = type; 58 | this.optional = optional; 59 | } 60 | } 61 | } -------------------------------------------------------------------------------- /src/org/swizframework/reflection/TypeCache.as: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Swiz Framework Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.swizframework.reflection 18 | { 19 | import flash.system.ApplicationDomain; 20 | import flash.utils.Dictionary; 21 | import flash.utils.describeType; 22 | import flash.utils.getQualifiedClassName; 23 | 24 | /** 25 | * Static class used to ensure each type is only inspected via describeType 26 | * a single time. 27 | */ 28 | public class TypeCache 29 | { 30 | /** 31 | * Dictionary of previously inspected types. 32 | */ 33 | protected static var typeDescriptors:Dictionary; 34 | 35 | /** 36 | * Will return TypeDescriptor instance either retrieved from cache or freshly 37 | * constructed from describeType call. 38 | * 39 | * @param target Object whose type is to be inspected and returned. 40 | * @param domain to associate the typeDescriptors with 41 | * 42 | * @return TypeDescriptor instance representing the type of the object that was passed in. 43 | */ 44 | public static function getTypeDescriptor( target:Object, domain:ApplicationDomain ):TypeDescriptor 45 | { 46 | // make sure our Dictionary has been initialized 47 | typeDescriptors ||= new Dictionary(); 48 | 49 | // check for this type in Dictionary and return it if it already exists 50 | var className:String = getQualifiedClassName( target ); 51 | if( typeDescriptors[ className ] != null ) 52 | return typeDescriptors[ className ]; 53 | 54 | // type not found in cache so create, store and return it here 55 | return typeDescriptors[ className ] = new TypeDescriptor().fromXML( describeType( domain.getDefinition( className ) ), domain ); 56 | } 57 | 58 | /** 59 | * Flushes all TypeDescriptors associated to a Domain 60 | */ 61 | public static function flushDomain( domain:ApplicationDomain ) :void 62 | { 63 | for( var key:Object in typeDescriptors ) 64 | { 65 | if( TypeDescriptor( typeDescriptors[ key ] ).domain == domain ) 66 | delete typeDescriptors[ key ]; 67 | } 68 | } 69 | } 70 | } -------------------------------------------------------------------------------- /src/org/swizframework/storage/ISharedObjectBean.as: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Swiz Framework Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.swizframework.storage 18 | { 19 | public interface ISharedObjectBean 20 | { 21 | /** 22 | * 23 | * @param path SharedObject localPath value. default is "/" 24 | * 25 | */ 26 | function set localPath( path : String ):void; 27 | 28 | /** 29 | * 30 | * @param name SharedObject name value. 31 | * 32 | */ 33 | function set name( name : String ):void; 34 | 35 | /** 36 | * 37 | * @return Size of the SharedObject 38 | * 39 | */ 40 | function get size():Number; 41 | 42 | /** 43 | * clears the SharedObject data 44 | */ 45 | function clear():void; 46 | 47 | /** 48 | * 49 | * @param name Name of the value 50 | * @return True if the value already exists. False if the value does not exist. 51 | * 52 | */ 53 | function hasValue( name : String ):Boolean; 54 | 55 | /** 56 | * 57 | * @param name Value name 58 | * @param initValue Optional initial value. Default is null. 59 | * @return Untyped value 60 | * 61 | */ 62 | function getValue( name : String, initValue : * = null ):*; 63 | 64 | /** 65 | * 66 | * @param name Value name 67 | * @param value String value 68 | * 69 | */ 70 | function setValue( name : String, value : * ):void; 71 | 72 | /** 73 | * 74 | * @param name Value name 75 | * @param initValue Optional initial value. Default is null. 76 | * @return String value 77 | * 78 | */ 79 | function getString( name : String, initValue : String = null ):String; 80 | 81 | /** 82 | * 83 | * @param name Value name 84 | * @param value String value 85 | * 86 | */ 87 | function setString( name : String, value : String ):void; 88 | 89 | /** 90 | * 91 | * @param name Value name 92 | * @param initValue Optional initial value. Default is false. 93 | * @return Boolean value 94 | * 95 | */ 96 | function getBoolean( name : String, initValue : Boolean = false ):Boolean; 97 | 98 | /** 99 | * 100 | * @param name Value name 101 | * @param value Boolean value 102 | * 103 | */ 104 | function setBoolean( name : String, value : Boolean ):void; 105 | 106 | /** 107 | * 108 | * @param name Value name 109 | * @param initValue Optional initial value. Default is NaN. 110 | * @return Number value 111 | * 112 | */ 113 | function getNumber( name : String, initValue : Number = NaN ):Number; 114 | 115 | /** 116 | * 117 | * @param name Value name 118 | * @param value Number value 119 | * 120 | */ 121 | function setNumber( name : String, value : Number ):void; 122 | 123 | /** 124 | * 125 | * @param name Value name 126 | * @param initValue Optional initial value. Default is -1. 127 | * @return Integer value 128 | * 129 | */ 130 | function getInt( name : String, initValue : int = -1 ):int; 131 | 132 | /** 133 | * 134 | * @param name Value name 135 | * @param value Integer value 136 | * 137 | */ 138 | function setInt( name : String, value : int ):void; 139 | } 140 | } -------------------------------------------------------------------------------- /src/org/swizframework/storage/SharedObjectBean.as: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Swiz Framework Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.swizframework.storage 18 | { 19 | import flash.events.Event; 20 | import flash.events.EventDispatcher; 21 | import flash.net.SharedObject; 22 | 23 | import org.swizframework.utils.logging.SwizLogger; 24 | 25 | public class SharedObjectBean extends EventDispatcher implements ISharedObjectBean 26 | { 27 | protected var logger:SwizLogger = SwizLogger.getLogger( this ); 28 | 29 | private var so:SharedObject; 30 | 31 | private var _path:String = "/"; 32 | private var _name:String = "swizSharedObject"; 33 | 34 | /** 35 | * @inheritDoc 36 | */ 37 | public function set localPath( path:String ):void 38 | { 39 | _path = path; 40 | invalidate(); 41 | } 42 | 43 | /** 44 | * @inheritDoc 45 | */ 46 | public function set name( name:String ):void 47 | { 48 | _name = name; 49 | invalidate(); 50 | } 51 | 52 | /** 53 | * @inheritDoc 54 | */ 55 | public function get size():Number 56 | { 57 | if( so != null ) 58 | { 59 | return so.size 60 | } 61 | return NaN; 62 | } 63 | 64 | public function SharedObjectBean() 65 | { 66 | super(); 67 | invalidate(); 68 | } 69 | 70 | protected function invalidate():void 71 | { 72 | so = SharedObject.getLocal( _name, _path ); 73 | } 74 | 75 | /** 76 | * @inheritDoc 77 | */ 78 | public function clear():void 79 | { 80 | so.clear(); 81 | } 82 | 83 | /** 84 | * @inheritDoc 85 | */ 86 | public function hasValue( name:String ):Boolean 87 | { 88 | return so.data[name] != undefined; 89 | } 90 | 91 | /** 92 | * @inheritDoc 93 | */ 94 | public function getValue( name:String, initValue:* = null ):* 95 | { 96 | var o:Object = so.data; 97 | if( o[name] == null && initValue != null ) 98 | { 99 | o[name] = initValue; 100 | so.flush(); 101 | } 102 | 103 | return o[name]; 104 | } 105 | 106 | /** 107 | * @inheritDoc 108 | */ 109 | public function setValue( name:String, value:* ):void 110 | { 111 | var o:Object = so.data; 112 | o[name] = value; 113 | so.flush(); 114 | } 115 | 116 | /** 117 | * @inheritDoc 118 | */ 119 | public function getString( name:String, initValue:String = null ):String 120 | { 121 | var o:Object = so.data; 122 | if( o[name] == null && initValue != null ) 123 | { 124 | o[name] = initValue; 125 | so.flush(); 126 | } 127 | 128 | return o[name]; 129 | } 130 | 131 | /** 132 | * @inheritDoc 133 | */ 134 | public function setString( name:String, value:String ):void 135 | { 136 | var o:Object = so.data; 137 | o[name] = value; 138 | so.flush(); 139 | } 140 | 141 | /** 142 | * @inheritDoc 143 | */ 144 | public function getBoolean( name:String, initValue:Boolean = false ):Boolean 145 | { 146 | var o:Object = so.data; 147 | if( o[name] == null ) 148 | { 149 | o[name] = initValue; 150 | so.flush(); 151 | } 152 | 153 | return o[name]; 154 | } 155 | 156 | /** 157 | * @inheritDoc 158 | */ 159 | public function setBoolean( name:String, value:Boolean ):void 160 | { 161 | var o:Object = so.data; 162 | o[name] = value; 163 | so.flush(); 164 | } 165 | 166 | /** 167 | * @inheritDoc 168 | */ 169 | public function getNumber( name:String, initValue:Number = NaN ):Number 170 | { 171 | var o:Object = so.data; 172 | if( o[name] == null ) 173 | { 174 | o[name] = initValue; 175 | so.flush(); 176 | } 177 | 178 | return o[name]; 179 | } 180 | 181 | /** 182 | * @inheritDoc 183 | */ 184 | public function setNumber( name:String, value:Number ):void 185 | { 186 | var o:Object = so.data; 187 | o[name] = value; 188 | so.flush(); 189 | } 190 | 191 | /** 192 | * @inheritDoc 193 | */ 194 | public function getInt( name:String, initValue:int = -1 ):int 195 | { 196 | var o:Object = so.data; 197 | if( o[name] == null ) 198 | { 199 | o[name] = initValue; 200 | so.flush(); 201 | } 202 | 203 | return o[name]; 204 | } 205 | 206 | /** 207 | * @inheritDoc 208 | */ 209 | public function setInt( name:String, value:int ):void 210 | { 211 | var o:Object = so.data; 212 | o[name] = value; 213 | so.flush(); 214 | dispatchEvent( new Event( "intChange" ) ); 215 | } 216 | } 217 | } -------------------------------------------------------------------------------- /src/org/swizframework/utils/DomainUtil.as: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Swiz Framework Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.swizframework.utils 18 | { 19 | import flash.system.ApplicationDomain; 20 | 21 | import mx.modules.ModuleManager; 22 | 23 | public class DomainUtil 24 | { 25 | /** 26 | * Returns the domain used to load an object. Because of significant 27 | * issues in the Flex Framework, we will either use the ModuleManager or fall 28 | * back on ApplicationDomain.currentDomain. This is because an object's loaderInfo 29 | * may very well not have the correct domain associated with it when Swiz initializes. 30 | */ 31 | public static function getDomain( object:Object ):ApplicationDomain 32 | { 33 | var domain:ApplicationDomain = getModuleDomain( object ); 34 | 35 | if( domain == null ) 36 | domain = ApplicationDomain.currentDomain; 37 | 38 | return domain; 39 | } 40 | 41 | /** 42 | * Returns the domain used to load an a module, only if the object supplied is a module. 43 | * Uses the ModuleManager to find the ApplicationDomain in the associated factory, which is a loader. 44 | * Unfortunately this appears to be the only trustable method for finding a module's domain. 45 | */ 46 | public static function getModuleDomain( object:Object ):ApplicationDomain 47 | { 48 | if( object is ModuleTypeUtil.MODULE_TYPE ) 49 | { 50 | var moduleInfo:Object = ModuleManager.getAssociatedFactory( object ).info(); 51 | return moduleInfo.currentDomain; 52 | } 53 | 54 | return null; 55 | } 56 | } 57 | } -------------------------------------------------------------------------------- /src/org/swizframework/utils/ModuleTypeUtil.as: -------------------------------------------------------------------------------- 1 | package org.swizframework.utils 2 | { 3 | CONFIG::flex4 4 | { 5 | import mx.modules.IModule; 6 | } 7 | 8 | CONFIG::flex3 9 | { 10 | import mx.modules.Module; 11 | } 12 | 13 | public class ModuleTypeUtil 14 | { 15 | CONFIG::flex4 16 | { 17 | public static const MODULE_TYPE:Class = IModule 18 | } 19 | 20 | CONFIG::flex3 21 | { 22 | public static const MODULE_TYPE:Class = Module; 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /src/org/swizframework/utils/async/AbstractAsynchronousDispatcherOperation.as: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Swiz Framework Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.swizframework.utils.async 18 | { 19 | import flash.events.Event; 20 | import flash.events.IEventDispatcher; 21 | 22 | public class AbstractAsynchronousDispatcherOperation extends AbstractAsynchronousOperation implements IAsynchronousOperation 23 | { 24 | // ======================================== 25 | // constructor 26 | // ======================================== 27 | 28 | /** 29 | * Constructor. 30 | */ 31 | public function AbstractAsynchronousDispatcherOperation( dispatcher:IEventDispatcher ) 32 | { 33 | super(); 34 | 35 | addEventListeners( dispatcher ); 36 | } 37 | 38 | // ======================================== 39 | // protected methods 40 | // ======================================== 41 | 42 | /** 43 | * Add Event listeners to the specified dispatcher. 44 | */ 45 | protected function addEventListeners( dispatcher:IEventDispatcher ):void 46 | { 47 | // Subclasses should override this method and add listeners for relevant Event(s). 48 | } 49 | 50 | /** 51 | * Remove Event listeners from the specified dispatcher. 52 | */ 53 | protected function removeEventListeners( dispatcher:IEventDispatcher ):void 54 | { 55 | // Subclasses should override this method and remove any Event listeners added in addEventListener(). 56 | } 57 | 58 | /** 59 | * Handle an Event that results in completion. 60 | */ 61 | protected function completeHandler( event:Event ):void 62 | { 63 | removeEventListeners( event.target as IEventDispatcher ); 64 | 65 | complete( event ); 66 | } 67 | 68 | /** 69 | * Handle an Event that results in failure. 70 | */ 71 | protected function failHandler( event:Event ):void 72 | { 73 | removeEventListeners( event.target as IEventDispatcher ); 74 | 75 | fail( event ); 76 | } 77 | } 78 | } -------------------------------------------------------------------------------- /src/org/swizframework/utils/async/AbstractAsynchronousOperation.as: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Swiz Framework Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.swizframework.utils.async 18 | { 19 | import mx.rpc.IResponder; 20 | 21 | public class AbstractAsynchronousOperation 22 | { 23 | // ======================================== 24 | // protected properties 25 | // ======================================== 26 | 27 | /** 28 | * Indicates whether this operation has concluded. 29 | */ 30 | protected var concluded:Boolean = false; 31 | 32 | [ArrayElementType("mx.rpc.IResponder")] 33 | /** 34 | * Subscribed responders. 35 | */ 36 | protected var responders:Array = []; 37 | 38 | // ======================================== 39 | // constructor 40 | // ======================================== 41 | 42 | /** 43 | * Constructor. 44 | */ 45 | public function AbstractAsynchronousOperation() 46 | { 47 | super(); 48 | } 49 | 50 | // ======================================== 51 | // public methods 52 | // ======================================== 53 | 54 | /** 55 | * @inheritDoc 56 | */ 57 | public function addResponder( responder:IResponder ):void 58 | { 59 | responders.push( responder ); 60 | } 61 | 62 | /** 63 | * @inheritDoc 64 | */ 65 | public function complete( data:Object ):void 66 | { 67 | if ( ! concluded ) 68 | { 69 | for each ( var responder:IResponder in responders ) 70 | { 71 | responder.result( data ); 72 | } 73 | 74 | concluded = true; 75 | } 76 | else 77 | { 78 | // TODO: Issue warning. 79 | } 80 | } 81 | 82 | /** 83 | * @inheritDoc 84 | */ 85 | public function fail( info:Object ):void 86 | { 87 | if ( ! concluded ) 88 | { 89 | for each ( var responder:IResponder in responders ) 90 | { 91 | responder.fault( info ); 92 | } 93 | 94 | concluded = true; 95 | } 96 | else 97 | { 98 | // TODO: Issue warning. 99 | } 100 | } 101 | } 102 | } -------------------------------------------------------------------------------- /src/org/swizframework/utils/async/AsyncTokenOperation.as: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Swiz Framework Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.swizframework.utils.async 18 | { 19 | import mx.rpc.AsyncToken; 20 | 21 | import org.swizframework.utils.services.SwizResponder; 22 | 23 | public class AsyncTokenOperation extends AbstractAsynchronousOperation implements IAsynchronousOperation 24 | { 25 | // ======================================== 26 | // constructor 27 | // ======================================== 28 | 29 | /** 30 | * Constructor. 31 | */ 32 | public function AsyncTokenOperation( token:AsyncToken ) 33 | { 34 | super(); 35 | 36 | token.addResponder( new SwizResponder( resultHandler, faultHandler ) ); 37 | } 38 | 39 | // ======================================== 40 | // protected methods 41 | // ======================================== 42 | 43 | /** 44 | * AsyncToken result handler. 45 | */ 46 | protected function resultHandler( data:Object ):void 47 | { 48 | complete( data ); 49 | } 50 | 51 | /** 52 | * AsyncToken fault handler. 53 | */ 54 | protected function faultHandler( info:Object ):void 55 | { 56 | fail( info ); 57 | } 58 | } 59 | } -------------------------------------------------------------------------------- /src/org/swizframework/utils/async/AsynchronousChainOperation.as: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Swiz Framework Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.swizframework.utils.async 18 | { 19 | import mx.rpc.IResponder; 20 | 21 | import org.swizframework.events.ChainEvent; 22 | import org.swizframework.utils.chain.IChain; 23 | 24 | public class AsynchronousChainOperation extends AbstractAsynchronousOperation implements IAsynchronousOperation 25 | { 26 | // ======================================== 27 | // constructor 28 | // ======================================== 29 | 30 | /** 31 | * Constructor. 32 | */ 33 | public function AsynchronousChainOperation( chain:IChain ) 34 | { 35 | super(); 36 | 37 | addEventListeners( chain ); 38 | } 39 | 40 | // ======================================== 41 | // protected methods 42 | // ======================================== 43 | 44 | /** 45 | * Add ChainEvent listeners to the specified chain. 46 | */ 47 | protected function addEventListeners( chain:IChain ):void 48 | { 49 | chain.addEventListener( ChainEvent.CHAIN_COMPLETE, chainCompleteHandler ); 50 | chain.addEventListener( ChainEvent.CHAIN_FAIL, chainFailHandler ); 51 | } 52 | 53 | /** 54 | * Remove ChainEvent listeners from the specified chain. 55 | */ 56 | protected function removeEventListeners( chain:IChain ):void 57 | { 58 | chain.removeEventListener( ChainEvent.CHAIN_COMPLETE, chainCompleteHandler ); 59 | chain.removeEventListener( ChainEvent.CHAIN_FAIL, chainFailHandler ); 60 | } 61 | 62 | /** 63 | * Handle ChainEvent.CHAIN_COMPLETE. 64 | */ 65 | protected function chainCompleteHandler( event:ChainEvent ):void 66 | { 67 | var chain:IChain = event.target as IChain; 68 | 69 | removeEventListeners( chain ); 70 | 71 | complete( chain ); 72 | } 73 | 74 | /** 75 | * Handle ChainEvent.CHAIN_FAIL. 76 | */ 77 | protected function chainFailHandler( event:ChainEvent ):void 78 | { 79 | var chain:IChain = event.target as IChain; 80 | 81 | removeEventListeners( chain ); 82 | 83 | fail( chain ); 84 | } 85 | } 86 | } -------------------------------------------------------------------------------- /src/org/swizframework/utils/async/AsynchronousEvent.as: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Swiz Framework Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.swizframework.utils.async 18 | { 19 | import flash.events.Event; 20 | import org.swizframework.utils.chain.IAsyncChainStep; 21 | 22 | public class AsynchronousEvent extends Event implements IAsynchronousEvent 23 | { 24 | // ======================================== 25 | // protected properties 26 | // ======================================== 27 | 28 | /** 29 | * Backing variable for step property. 30 | */ 31 | protected var _step:IAsyncChainStep; 32 | 33 | // ======================================== 34 | // public properties 35 | // ======================================== 36 | 37 | /** 38 | * @inheritDoc 39 | */ 40 | public function get step():IAsyncChainStep 41 | { 42 | return _step; 43 | } 44 | 45 | public function set step( value:IAsyncChainStep ):void 46 | { 47 | _step = value; 48 | } 49 | 50 | // ======================================== 51 | // constructor 52 | // ======================================== 53 | 54 | /** 55 | * Constructor. 56 | */ 57 | public function AsynchronousEvent( type:String, bubbles:Boolean = false, cancelable:Boolean = false ) 58 | { 59 | super( type, bubbles, cancelable ); 60 | } 61 | 62 | // ======================================== 63 | // public methods 64 | // ======================================== 65 | 66 | /** 67 | * @inheritDoc 68 | */ 69 | override public function clone():Event 70 | { 71 | var clone:AsynchronousEvent = new AsynchronousEvent( type, bubbles, cancelable ); 72 | 73 | clone.step = step; 74 | 75 | return clone; 76 | } 77 | } 78 | } -------------------------------------------------------------------------------- /src/org/swizframework/utils/async/AsynchronousIOOperation.as: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Swiz Framework Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.swizframework.utils.async 18 | { 19 | import flash.events.Event; 20 | import flash.events.IEventDispatcher; 21 | import flash.events.IOErrorEvent; 22 | import flash.events.SecurityErrorEvent; 23 | 24 | import mx.rpc.IResponder; 25 | 26 | public class AsynchronousIOOperation extends AbstractAsynchronousDispatcherOperation implements IAsynchronousOperation 27 | { 28 | // ======================================== 29 | // constructor 30 | // ======================================== 31 | 32 | /** 33 | * Constructor. 34 | */ 35 | public function AsynchronousIOOperation( dispatcher:IEventDispatcher ):void 36 | { 37 | super( dispatcher ); 38 | } 39 | 40 | // ======================================== 41 | // protected methods 42 | // ======================================== 43 | 44 | /** 45 | * Add Event listeners to the specified dispatcher. 46 | */ 47 | override protected function addEventListeners( dispatcher:IEventDispatcher ):void 48 | { 49 | dispatcher.addEventListener(Event.CANCEL, failHandler); 50 | dispatcher.addEventListener(Event.COMPLETE, completeHandler); 51 | dispatcher.addEventListener(IOErrorEvent.IO_ERROR, failHandler); 52 | dispatcher.addEventListener(SecurityErrorEvent.SECURITY_ERROR, failHandler); 53 | } 54 | 55 | /** 56 | * Remove Event listeners from the specified dispatcher. 57 | */ 58 | override protected function removeEventListeners( dispatcher:IEventDispatcher ):void 59 | { 60 | dispatcher.removeEventListener(Event.CANCEL, failHandler); 61 | dispatcher.removeEventListener(Event.COMPLETE, completeHandler); 62 | dispatcher.removeEventListener(IOErrorEvent.IO_ERROR, failHandler); 63 | dispatcher.removeEventListener(SecurityErrorEvent.SECURITY_ERROR, failHandler); 64 | } 65 | } 66 | } -------------------------------------------------------------------------------- /src/org/swizframework/utils/async/IAsynchronousEvent.as: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Swiz Framework Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.swizframework.utils.async 18 | { 19 | import org.swizframework.utils.chain.IAsyncChainStep; 20 | 21 | public interface IAsynchronousEvent 22 | { 23 | /** 24 | * Corresponding asynchronous chain step. 25 | */ 26 | function get step():IAsyncChainStep; 27 | function set step( value:IAsyncChainStep ):void; 28 | } 29 | } -------------------------------------------------------------------------------- /src/org/swizframework/utils/async/IAsynchronousOperation.as: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Swiz Framework Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.swizframework.utils.async 18 | { 19 | import mx.rpc.IResponder; 20 | 21 | public interface IAsynchronousOperation 22 | { 23 | /** 24 | * Add a responder to be notified of operation completion or failure. 25 | */ 26 | function addResponder( responder:IResponder ):void; 27 | 28 | /** 29 | * Notify registered responders that this operation is complete. 30 | */ 31 | function complete( data:Object ):void; 32 | 33 | /** 34 | * Notify registered responders that this operation has failed. 35 | */ 36 | function fail( info:Object ):void; 37 | } 38 | } -------------------------------------------------------------------------------- /src/org/swizframework/utils/chain/AsyncCommandChainStep.as: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Swiz Framework Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.swizframework.utils.chain 18 | { 19 | import mx.rpc.AsyncToken; 20 | import mx.rpc.IResponder; 21 | 22 | public class AsyncCommandChainStep extends CommandChainStep implements IResponder 23 | { 24 | // ======================================== 25 | // protected properties 26 | // ======================================== 27 | 28 | /** 29 | * 30 | */ 31 | protected var asyncMethod:Function; 32 | 33 | /** 34 | * 35 | */ 36 | protected var asyncMethodArgs:Array; 37 | 38 | /** 39 | * 40 | */ 41 | protected var resultHandler:Function; 42 | 43 | /** 44 | * 45 | */ 46 | protected var faultHandler:Function; 47 | 48 | /** 49 | * 50 | */ 51 | protected var handlerArgs:Array; 52 | 53 | // ======================================== 54 | // constructor 55 | // ======================================== 56 | 57 | public function AsyncCommandChainStep( asyncMethod:Function, asyncMethodArgs:Array = null, 58 | resultHandler:Function = null, faultHandler:Function = null, 59 | handlerArgs:Array = null ) 60 | { 61 | this.asyncMethodArgs = asyncMethodArgs; 62 | this.asyncMethod = asyncMethod; 63 | this.resultHandler = resultHandler; 64 | this.faultHandler = faultHandler; 65 | this.handlerArgs = handlerArgs; 66 | } 67 | 68 | override public function execute():void 69 | { 70 | var token:AsyncToken; 71 | 72 | if( asyncMethodArgs != null ) 73 | token = asyncMethod.apply( null, asyncMethodArgs ); 74 | else 75 | token = asyncMethod(); 76 | 77 | token.addResponder( this ); 78 | } 79 | 80 | override public function doProceed():void 81 | { 82 | execute(); 83 | } 84 | 85 | /** 86 | * 87 | */ 88 | public function result( data:Object ):void 89 | { 90 | if( resultHandler != null ) 91 | { 92 | if( handlerArgs == null ) 93 | { 94 | resultHandler( data ); 95 | } 96 | else 97 | { 98 | resultHandler.apply( this, [ data ].concat( handlerArgs ) ); 99 | } 100 | } 101 | 102 | complete(); 103 | } 104 | 105 | /** 106 | * 107 | */ 108 | public function fault( info:Object ):void 109 | { 110 | if( faultHandler != null ) 111 | { 112 | if( handlerArgs == null ) 113 | { 114 | faultHandler( info ); 115 | } 116 | else 117 | { 118 | try 119 | { 120 | faultHandler( info ); 121 | } 122 | catch( e:Error ) 123 | { 124 | faultHandler.apply( null, [ info ].concat( handlerArgs ) ); 125 | } 126 | } 127 | } 128 | 129 | error(); 130 | } 131 | } 132 | } -------------------------------------------------------------------------------- /src/org/swizframework/utils/chain/BaseChainStep.as: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Swiz Framework Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.swizframework.utils.chain 18 | { 19 | public class BaseChainStep implements IChainStep 20 | { 21 | /** 22 | * Backing variable for chain getter/setter. 23 | */ 24 | protected var _chain:IChain; 25 | 26 | /** 27 | * 28 | */ 29 | public function get chain():IChain 30 | { 31 | return _chain; 32 | } 33 | 34 | public function set chain( value:IChain ):void 35 | { 36 | _chain = value; 37 | } 38 | 39 | /** 40 | * Backing variable for failed property. 41 | */ 42 | protected var _failed:Boolean = false; 43 | 44 | /** 45 | * Indicates whether this step failed. 46 | */ 47 | public function get failed():Boolean 48 | { 49 | return _failed; 50 | } 51 | 52 | /** 53 | * Backing variable for isComplete property. 54 | */ 55 | protected var _isComplete:Boolean = false; 56 | 57 | public function get isComplete():Boolean 58 | { 59 | return _isComplete; 60 | } 61 | 62 | public function BaseChainStep() 63 | { 64 | 65 | } 66 | 67 | /** 68 | * 69 | */ 70 | public function complete():void 71 | { 72 | // before calling complete(), check if the chain step has been marked as error 73 | if( !_failed) 74 | { 75 | _isComplete = true; 76 | 77 | if( chain != null ) 78 | chain.stepComplete(); 79 | } 80 | } 81 | 82 | /** 83 | * 84 | */ 85 | public function error():void 86 | { 87 | _failed = true; 88 | _isComplete = true; 89 | 90 | if( chain != null ) 91 | chain.stepError(); 92 | } 93 | } 94 | } -------------------------------------------------------------------------------- /src/org/swizframework/utils/chain/BaseCompositeChain.as: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Swiz Framework Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.swizframework.utils.chain 18 | { 19 | public class BaseCompositeChain extends AbstractChain implements IChain 20 | { 21 | // ======================================== 22 | // constructor 23 | // ======================================== 24 | 25 | /** 26 | * Constructor. 27 | */ 28 | public function BaseCompositeChain( mode:String = ChainType.SEQUENCE, stopOnError:Boolean = true ) 29 | { 30 | super( mode, stopOnError ); 31 | } 32 | 33 | // ======================================== 34 | // public methods 35 | // ======================================== 36 | 37 | /** 38 | * @inheritDoc 39 | */ 40 | public function doProceed():void 41 | { 42 | if( currentStep is IAutonomousChainStep ) 43 | IAutonomousChainStep( currentStep ).doProceed(); 44 | else if( currentStep is IChain ) 45 | IChain( currentStep ).start(); 46 | } 47 | } 48 | } -------------------------------------------------------------------------------- /src/org/swizframework/utils/chain/ChainType.as: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Swiz Framework Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.swizframework.utils.chain 18 | { 19 | public final class ChainType 20 | { 21 | public static const SEQUENCE:String = "sequence"; 22 | public static const PARALLEL:String = "parallel"; 23 | } 24 | } -------------------------------------------------------------------------------- /src/org/swizframework/utils/chain/ChainUtil.as: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Swiz Framework Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.swizframework.utils.chain 18 | { 19 | import flash.events.IEventDispatcher; 20 | 21 | import org.swizframework.core.IDispatcherAware; 22 | 23 | public class ChainUtil implements IDispatcherAware 24 | { 25 | private var _dispatcher:IEventDispatcher; 26 | 27 | public function ChainUtil() 28 | { 29 | } 30 | 31 | /** IDispatcherAware implementation */ 32 | public function set dispatcher( dispatcher:IEventDispatcher ):void 33 | { 34 | _dispatcher = dispatcher; 35 | } 36 | 37 | /** Constructs a dynamic command */ 38 | public function createCommand( delayedCall:Function, args:Array, resultHandler:Function, 39 | faultHandler:Function = null, resultHandlerArgs:Array = null ):AsyncCommandChainStep 40 | { 41 | return new AsyncCommandChainStep( delayedCall, args, resultHandler, faultHandler, resultHandlerArgs ); 42 | } 43 | 44 | /** Constructs a dynamic command */ 45 | public function createChain( mode:String = ChainType.SEQUENCE ):CommandChain 46 | { 47 | return new CommandChain( mode ); 48 | } 49 | } 50 | } -------------------------------------------------------------------------------- /src/org/swizframework/utils/chain/CommandChain.as: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Swiz Framework Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.swizframework.utils.chain 18 | { 19 | public class CommandChain extends BaseCompositeChain 20 | { 21 | // ======================================== 22 | // constructor 23 | // ======================================== 24 | 25 | /** 26 | * Constructor. 27 | */ 28 | public function CommandChain( mode:String = ChainType.SEQUENCE, stopOnError:Boolean = true ) 29 | { 30 | super( mode, stopOnError ); 31 | } 32 | 33 | // ======================================== 34 | // public methods 35 | // ======================================== 36 | 37 | /** 38 | * Add an CommandChainStep to this EventChain. 39 | */ 40 | public function addCommand( command:CommandChainStep ):CommandChain 41 | { 42 | addStep( command ); 43 | return this; 44 | } 45 | 46 | /** 47 | * @inheritDoc 48 | */ 49 | override public function doProceed():void 50 | { 51 | if( currentStep is CommandChainStep ) 52 | CommandChainStep( currentStep ).doProceed(); 53 | else 54 | super.doProceed(); 55 | } 56 | } 57 | } -------------------------------------------------------------------------------- /src/org/swizframework/utils/chain/CommandChainStep.as: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Swiz Framework Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.swizframework.utils.chain 18 | { 19 | public class CommandChainStep extends BaseChainStep implements IAutonomousChainStep 20 | { 21 | /** 22 | * 23 | */ 24 | public function execute():void 25 | { 26 | 27 | } 28 | 29 | public function doProceed():void 30 | { 31 | execute(); 32 | 33 | complete(); 34 | } 35 | } 36 | } -------------------------------------------------------------------------------- /src/org/swizframework/utils/chain/EventChain.as: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Swiz Framework Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.swizframework.utils.chain 18 | { 19 | import flash.events.IEventDispatcher; 20 | 21 | public class EventChain extends BaseCompositeChain 22 | { 23 | // ======================================== 24 | // protected properties 25 | // ======================================== 26 | 27 | /** 28 | * Backing variable for dispatcher getter/setter. 29 | */ 30 | protected var _dispatcher:IEventDispatcher; 31 | 32 | // ======================================== 33 | // public properties 34 | // ======================================== 35 | 36 | /** 37 | * Target Event dispatcher. 38 | */ 39 | public function get dispatcher():IEventDispatcher 40 | { 41 | return _dispatcher; 42 | } 43 | 44 | public function set dispatcher( value:IEventDispatcher ):void 45 | { 46 | _dispatcher = value; 47 | } 48 | 49 | // ======================================== 50 | // constructor 51 | // ======================================== 52 | 53 | /** 54 | * Constructor. 55 | */ 56 | public function EventChain( dispatcher:IEventDispatcher, mode:String = ChainType.SEQUENCE, stopOnError:Boolean = true ) 57 | { 58 | super( mode, stopOnError ); 59 | 60 | this.dispatcher = dispatcher; 61 | } 62 | 63 | // ======================================== 64 | // public methods 65 | // ======================================== 66 | 67 | /** 68 | * Add an EventChainStep to this EventChain. 69 | */ 70 | public function addEvent( event:EventChainStep ):EventChain 71 | { 72 | addStep( event ); 73 | return this; 74 | } 75 | 76 | /** 77 | * @inheritDoc 78 | */ 79 | override public function doProceed():void 80 | { 81 | if( currentStep is EventChainStep ) 82 | EventChainStep( currentStep ).dispatcher ||= dispatcher; 83 | 84 | super.doProceed(); 85 | } 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /src/org/swizframework/utils/chain/EventChainStep.as: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Swiz Framework Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.swizframework.utils.chain 18 | { 19 | import flash.events.Event; 20 | import flash.events.IEventDispatcher; 21 | 22 | import org.swizframework.utils.async.IAsynchronousEvent; 23 | import org.swizframework.utils.async.IAsynchronousOperation; 24 | import org.swizframework.utils.services.SwizResponder; 25 | 26 | public class EventChainStep extends BaseChainStep implements IAutonomousChainStep, IAsyncChainStep 27 | { 28 | // ======================================== 29 | // protected properties 30 | // ======================================== 31 | 32 | /** 33 | * Backing variable for dispatcher getter/setter. 34 | */ 35 | protected var _dispatcher:IEventDispatcher; 36 | 37 | /** 38 | * Backing variable for event property. 39 | */ 40 | protected var _event:Event; 41 | 42 | /** 43 | * Backing variable for pendingCount property. 44 | */ 45 | protected var _pendingCount:int = 0; 46 | 47 | // ======================================== 48 | // public properties 49 | // ======================================== 50 | 51 | /** 52 | * Target Event dispatcher. 53 | */ 54 | public function get dispatcher():IEventDispatcher 55 | { 56 | return _dispatcher; 57 | } 58 | 59 | public function set dispatcher( value:IEventDispatcher ):void 60 | { 61 | _dispatcher = value; 62 | } 63 | 64 | /** 65 | * Event dispatched for this EventChainStep. 66 | */ 67 | public function get event():Event 68 | { 69 | return _event; 70 | } 71 | 72 | /** 73 | * Count of pending asynchronous operations for this step. 74 | */ 75 | public function get pendingCount():int 76 | { 77 | return _pendingCount; 78 | } 79 | 80 | // ======================================== 81 | // constructor 82 | // ======================================== 83 | 84 | /** 85 | * Constructor. 86 | */ 87 | public function EventChainStep( event:Event, dispatcher:IEventDispatcher = null ) 88 | { 89 | super(); 90 | 91 | _dispatcher = dispatcher; 92 | _event = event; 93 | if ( _event is IAsynchronousEvent ) 94 | IAsynchronousEvent( _event ).step = this; 95 | } 96 | 97 | // ======================================== 98 | // public methods 99 | // ======================================== 100 | 101 | /** 102 | * @inheritDoc 103 | */ 104 | public function doProceed():void 105 | { 106 | _failed = false; 107 | _pendingCount = 0; 108 | 109 | dispatcher.dispatchEvent( event ); 110 | 111 | if ( ( pendingCount == 0 ) && ( ! isComplete ) ) 112 | complete(); 113 | } 114 | 115 | /** 116 | * @inheritDoc 117 | */ 118 | override public function complete():void 119 | { 120 | _pendingCount = 0; 121 | 122 | super.complete(); 123 | } 124 | 125 | /** 126 | * @inheritDoc 127 | */ 128 | override public function error():void 129 | { 130 | _failed = true; 131 | 132 | super.error(); 133 | } 134 | 135 | /** 136 | * @inheritDoc 137 | */ 138 | public function addAsynchronousOperation( operation:IAsynchronousOperation ):void 139 | { 140 | operation.addResponder( new SwizResponder( resultHandler, faultHandler ) ); 141 | 142 | _pendingCount++; 143 | } 144 | 145 | // ======================================== 146 | // public methods 147 | // ======================================== 148 | 149 | /** 150 | * Result handler for an associated pending asynchronous operation. 151 | */ 152 | protected function resultHandler( data:Object ):void 153 | { 154 | if ( _pendingCount > 0 ) 155 | _pendingCount--; 156 | 157 | if ( !_failed ) 158 | { 159 | if ( _pendingCount == 0 ) 160 | complete(); 161 | } 162 | } 163 | 164 | /** 165 | * Fault handler for an associated pending asynchronous operation. 166 | */ 167 | protected function faultHandler( info:Object ):void 168 | { 169 | if ( _pendingCount > 0 ) 170 | _pendingCount--; 171 | 172 | error(); 173 | } 174 | } 175 | } -------------------------------------------------------------------------------- /src/org/swizframework/utils/chain/FunctionChainStep.as: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Swiz Framework Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.swizframework.utils.chain 18 | { 19 | public class FunctionChainStep extends BaseChainStep implements IAutonomousChainStep 20 | { 21 | public var functionRef:Function; 22 | public var functionArgArray:Array; 23 | public var functionThisArg:*; 24 | public var returnValue:*; 25 | 26 | public function FunctionChainStep( functionRef:Function, functionArgArray:Array = null, functionThisArg:* = null ) 27 | { 28 | this.functionRef = functionRef; 29 | this.functionArgArray = functionArgArray; 30 | this.functionThisArg = functionThisArg; 31 | } 32 | 33 | public function doProceed():void 34 | { 35 | returnValue = functionRef.apply( functionThisArg, functionArgArray ); 36 | 37 | complete(); 38 | } 39 | } 40 | } -------------------------------------------------------------------------------- /src/org/swizframework/utils/chain/IAsyncChainStep.as: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Swiz Framework Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.swizframework.utils.chain 18 | { 19 | import org.swizframework.utils.async.IAsynchronousOperation; 20 | 21 | public interface IAsyncChainStep extends IChainStep 22 | { 23 | /** 24 | * Add a pending asynchronous operation to this chain step. 25 | */ 26 | function addAsynchronousOperation( operation:IAsynchronousOperation ):void; 27 | } 28 | } -------------------------------------------------------------------------------- /src/org/swizframework/utils/chain/IAutonomousChainStep.as: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Swiz Framework Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.swizframework.utils.chain 18 | { 19 | public interface IAutonomousChainStep extends IChainStep 20 | { 21 | /** 22 | * Proceed with execution of this chain step. 23 | */ 24 | function doProceed():void; 25 | } 26 | } -------------------------------------------------------------------------------- /src/org/swizframework/utils/chain/IChain.as: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Swiz Framework Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.swizframework.utils.chain 18 | { 19 | import flash.events.IEventDispatcher; 20 | 21 | [Event(name="chainStart", type="org.swizframework.events.ChainEvent")] 22 | [Event(name="chainStepComplete", type="org.swizframework.events.ChainEvent")] 23 | [Event(name="chainStepError", type="org.swizframework.events.ChainEvent")] 24 | [Event(name="chainComplete", type="org.swizframework.events.ChainEvent")] 25 | [Event(name="chainFail", type="org.swizframework.events.ChainEvent")] 26 | 27 | public interface IChain extends IEventDispatcher 28 | { 29 | function get position():int; 30 | function set position( value:int ):void; 31 | 32 | function get isComplete():Boolean; 33 | 34 | function get stopOnError():Boolean; 35 | function set stopOnError( value:Boolean ):void; 36 | 37 | function hasNext():Boolean; 38 | function stepComplete():void; 39 | function stepError():void; 40 | 41 | function addStep( step:IChainStep ):IChain; 42 | 43 | function start():void; 44 | function doProceed():void; 45 | } 46 | } -------------------------------------------------------------------------------- /src/org/swizframework/utils/chain/IChainStep.as: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Swiz Framework Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.swizframework.utils.chain 18 | { 19 | public interface IChainStep 20 | { 21 | function get chain():IChain; 22 | function set chain( value:IChain ):void; 23 | 24 | function get isComplete():Boolean; 25 | 26 | function complete():void; 27 | function error():void; 28 | } 29 | } -------------------------------------------------------------------------------- /src/org/swizframework/utils/commands/ICommand.as: -------------------------------------------------------------------------------- 1 | package org.swizframework.utils.commands 2 | { 3 | /** 4 | * Base interface that must be implemented in order to be mapped to an event in a CommandMap. 5 | * 6 | * @see org.swizframework.utils.commands.CommandMap 7 | */ 8 | public interface ICommand 9 | { 10 | function execute():void; 11 | } 12 | } -------------------------------------------------------------------------------- /src/org/swizframework/utils/commands/IEventAwareCommand.as: -------------------------------------------------------------------------------- 1 | package org.swizframework.utils.commands 2 | { 3 | import flash.events.Event; 4 | 5 | /** 6 | * Interface that instructs a Swiz CommandMap to supply a reference to the event 7 | * which triggered this command's execution. 8 | * 9 | * @see org.swizframework.utils.commands.CommandMap 10 | */ 11 | public interface IEventAwareCommand extends ICommand 12 | { 13 | function set event( value:Event ):void; 14 | } 15 | } -------------------------------------------------------------------------------- /src/org/swizframework/utils/logging/AbstractSwizLoggingTarget.as: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Swiz Framework Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.swizframework.utils.logging 18 | { 19 | import org.swizframework.utils.logging.SwizLogger; 20 | 21 | public class AbstractSwizLoggingTarget 22 | { 23 | private var _filters:Array = [ "*" ]; 24 | private var _level:int = SwizLogEventLevel.ALL; 25 | 26 | public function AbstractSwizLoggingTarget() 27 | { 28 | } 29 | 30 | public function get filters():Array 31 | { 32 | return _filters; 33 | } 34 | 35 | public function set filters( value:Array ):void 36 | { 37 | _filters = value; 38 | } 39 | 40 | public function get level():int 41 | { 42 | return _level; 43 | } 44 | 45 | public function set level( value:int ):void 46 | { 47 | // A change of level may impact the target level for Log. 48 | _level = value; 49 | } 50 | 51 | public function addLogger( logger:SwizLogger ):void 52 | { 53 | if( logger ) 54 | { 55 | logger.addEventListener( SwizLogEvent.LOG_EVENT, logHandler ); 56 | } 57 | } 58 | 59 | public function removeLogger( logger:SwizLogger ):void 60 | { 61 | if( logger ) 62 | { 63 | logger.removeEventListener( SwizLogEvent.LOG_EVENT, logHandler ); 64 | } 65 | } 66 | 67 | /** subclasses must override! */ 68 | protected function logEvent( event:SwizLogEvent ):void 69 | { 70 | 71 | } 72 | 73 | protected function logHandler( event:SwizLogEvent ):void 74 | { 75 | if( event.level >= level ) 76 | logEvent( event ); 77 | } 78 | } 79 | } -------------------------------------------------------------------------------- /src/org/swizframework/utils/logging/SwizLogEvent.as: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Swiz Framework Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.swizframework.utils.logging 18 | { 19 | import flash.events.Event; 20 | 21 | public class SwizLogEvent extends Event 22 | { 23 | // ======================================== 24 | // public static const 25 | // ======================================== 26 | 27 | public static const LOG_EVENT:String = "log"; 28 | 29 | // ======================================== 30 | // public properties 31 | // ======================================== 32 | 33 | public var message:String; 34 | public var level:int; 35 | 36 | public function SwizLogEvent( message:String, level:int ) 37 | { 38 | super( LOG_EVENT, true, true ); 39 | this.message = message; 40 | this.level = level; 41 | } 42 | 43 | // ======================================== 44 | // clone method 45 | // ======================================== 46 | 47 | override public function clone():Event 48 | { 49 | return new SwizLogEvent( message, level ); 50 | } 51 | } 52 | } -------------------------------------------------------------------------------- /src/org/swizframework/utils/logging/SwizLogEventLevel.as: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Swiz Framework Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.swizframework.utils.logging 18 | { 19 | public class SwizLogEventLevel 20 | { 21 | 22 | // ======================================== 23 | // public static const. these are all the 24 | // standard flex logging event levels 25 | // ======================================== 26 | 27 | public static const FATAL:int = 1000; 28 | public static const ERROR:int = 8; 29 | public static const WARN:int = 6; 30 | public static const INFO:int = 4; 31 | public static const DEBUG:int = 2; 32 | public static const ALL:int = 0; 33 | 34 | public function SwizLogEventLevel() 35 | { 36 | } 37 | } 38 | } -------------------------------------------------------------------------------- /src/org/swizframework/utils/logging/SwizTraceTarget.as: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Swiz Framework Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.swizframework.utils.logging 18 | { 19 | public class SwizTraceTarget extends AbstractSwizLoggingTarget 20 | { 21 | override protected function logEvent( event:SwizLogEvent ):void 22 | { 23 | traceMessage( event.message ); 24 | } 25 | 26 | private function traceMessage( message:String ):void 27 | { 28 | trace( message ); 29 | } 30 | } 31 | } -------------------------------------------------------------------------------- /src/org/swizframework/utils/services/AMFUtil.as: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Swiz Framework Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.swizframework.utils.services 18 | { 19 | import flash.net.ObjectEncoding; 20 | 21 | import mx.core.ByteArrayAsset; 22 | import mx.messaging.messages.AcknowledgeMessage; 23 | 24 | public class AMFUtil 25 | { 26 | /** 27 | * Retrieves actual AMF payload data from saved binary. 28 | * 29 | * @param clazz AMF data 30 | * @return Actual AMF payload contents 31 | */ 32 | public static function getAMF3Data( clazz:Class ):Object 33 | { 34 | var mockData:ByteArrayAsset = ByteArrayAsset( new clazz() ); 35 | mockData.objectEncoding = ObjectEncoding.AMF3; 36 | 37 | while( mockData.readByte() != 0x0A ) 38 | { 39 | // Nothing to do 40 | // readByte() will auto-advance position and read the new value every iteration 41 | } 42 | mockData.position--; 43 | 44 | return AcknowledgeMessage( mockData.readObject() ).body; 45 | } 46 | } 47 | } -------------------------------------------------------------------------------- /src/org/swizframework/utils/services/ChannelSetHelper.as: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Swiz Framework Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.swizframework.utils.services 18 | { 19 | import mx.messaging.Channel; 20 | import mx.messaging.ChannelSet; 21 | import mx.messaging.channels.AMFChannel; 22 | import mx.messaging.channels.SecureAMFChannel; 23 | 24 | import org.swizframework.core.IInitializing; 25 | 26 | public class ChannelSetHelper extends ChannelSet implements IInitializing 27 | { 28 | // Flash remoting config issues 29 | private static const DEFAULT_CHANNEL_ID : String = "orca-amf"; 30 | private static const DEFAULT_PROTOCOL : String = "http"; 31 | private static const DEFAULT_SERVER_NAME : String = "localhost"; 32 | private static const DEFAULT_SERVER_PORT : int = 8080; 33 | private static const DEFAULT_CONTEXT_ROOT : String = "/"; 34 | private static const DEFAULT_ENDPOINT_NAME : String = "messagebroker/amf"; 35 | 36 | public var channelId:String; 37 | public var protocol:String; 38 | public var serverName:String; 39 | public var serverPort:int; 40 | public var contextRoot:String; 41 | public var endPointName:String; 42 | 43 | public var parameterSource:Object; 44 | public var parameterName:String; 45 | 46 | private var url:String; 47 | private var channelCreated : Boolean = false; 48 | 49 | public function ChannelSetHelper(channelIds:Array=null, clusteredWithURLLoadBalancing:Boolean=false) 50 | { 51 | super(channelIds, clusteredWithURLLoadBalancing); 52 | } 53 | 54 | public function afterPropertiesSet() : void { 55 | if (!channelCreated) { 56 | checkParameters(); 57 | createChannel(); 58 | } 59 | } 60 | 61 | private function checkParameters():void 62 | { 63 | if( parameterSource != null && parameterName != null ) 64 | url = parameterSource.parameters[ parameterName ]; 65 | } 66 | 67 | /** 68 | * Constructs the AMF Channel and adds to the channel set 69 | */ 70 | private function createChannel():void 71 | { 72 | if (!channelCreated) { 73 | 74 | var amfChannel:Channel; 75 | // create a new AMF Channel with our configuration 76 | if( PROTOCOL == "https" || AMF_ENDPOINT.indexOf("https") > -1 ) 77 | amfChannel = new SecureAMFChannel(CHANNEL_ID, AMF_ENDPOINT); 78 | else 79 | amfChannel = new AMFChannel(CHANNEL_ID, AMF_ENDPOINT); 80 | addChannel(amfChannel); 81 | channelCreated = true; 82 | } 83 | } 84 | 85 | /** 86 | * Creates a proper AMF Endpoint with configured parameters. Location depends on how 87 | * the application is accessed (http:// or file://) 88 | **/ 89 | private function get AMF_ENDPOINT() : String 90 | { 91 | if( url != null && url.length) 92 | return url; 93 | else 94 | return PROTOCOL+"://" + SERVER_NAME + ":" + SERVER_PORT + CONTEXT_ROOT +"/" + ENDPOINT_NAME; 95 | } 96 | 97 | /** 98 | * returns either default or configured channel id 99 | **/ 100 | private function get CHANNEL_ID() : String { 101 | return channelId != null ? channelId : DEFAULT_CHANNEL_ID; 102 | } 103 | 104 | /** 105 | * returns either default or configured server name 106 | **/ 107 | private function get PROTOCOL() : String { 108 | return protocol != null ? protocol : DEFAULT_PROTOCOL; 109 | } 110 | 111 | /** 112 | * returns either default or configured server name 113 | **/ 114 | private function get SERVER_NAME() : String { 115 | return serverName != null ? serverName : DEFAULT_SERVER_NAME; 116 | } 117 | 118 | /** 119 | * returns either default or configured server port 120 | **/ 121 | private function get SERVER_PORT() : int { 122 | return serverPort != 0 ? serverPort : DEFAULT_SERVER_PORT; 123 | } 124 | 125 | /** 126 | * returns either default or configured context root 127 | **/ 128 | private function get CONTEXT_ROOT() : String { 129 | return contextRoot != null ? contextRoot : DEFAULT_CONTEXT_ROOT; 130 | } 131 | 132 | private function get ENDPOINT_NAME() : String { 133 | return endPointName != null ? endPointName : DEFAULT_ENDPOINT_NAME; 134 | } 135 | 136 | } 137 | } -------------------------------------------------------------------------------- /src/org/swizframework/utils/services/IServiceHelper.as: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Swiz Framework Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.swizframework.utils.services 18 | { 19 | import mx.rpc.AsyncToken; 20 | 21 | public interface IServiceHelper 22 | { 23 | function executeServiceCall( call:AsyncToken, resultHandler:Function, faultHandler:Function = null, handlerArgs:Array = null ):AsyncToken; 24 | } 25 | } -------------------------------------------------------------------------------- /src/org/swizframework/utils/services/IURLRequestHelper.as: -------------------------------------------------------------------------------- 1 | package org.swizframework.utils.services 2 | { 3 | import flash.net.URLLoader; 4 | import flash.net.URLRequest; 5 | 6 | public interface IURLRequestHelper 7 | { 8 | function executeURLRequest( request:URLRequest, resultHandler:Function, faultHandler:Function = null, 9 | progressHandler:Function = null, httpStatusHandler:Function = null, 10 | handlerArgs:Array = null ):URLLoader 11 | } 12 | } -------------------------------------------------------------------------------- /src/org/swizframework/utils/services/MockDelegateHelper.as: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Swiz Framework Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.swizframework.utils.services 18 | { 19 | import flash.events.TimerEvent; 20 | import flash.utils.Dictionary; 21 | import flash.utils.Timer; 22 | 23 | import mx.core.mx_internal; 24 | import mx.managers.CursorManager; 25 | import mx.rpc.AsyncToken; 26 | import mx.rpc.Fault; 27 | import mx.rpc.IResponder; 28 | import mx.rpc.events.FaultEvent; 29 | import mx.rpc.events.ResultEvent; 30 | 31 | public class MockDelegateHelper 32 | { 33 | public var calls:Dictionary; 34 | public var fault:Fault; 35 | 36 | /** 37 | * If true, a busy cursor is displayed while the mock service is 38 | * executing. The default value is false. 39 | */ 40 | public var showBusyCursor:Boolean; 41 | 42 | public function MockDelegateHelper( showBusyCursor:Boolean = false ) 43 | { 44 | this.showBusyCursor = showBusyCursor; 45 | calls = new Dictionary(); 46 | } 47 | 48 | public function createMockResult( mockData:Object, delay:int = 10 ):AsyncToken 49 | { 50 | var token:AsyncToken = new AsyncToken(); 51 | token.data = mockData; 52 | 53 | var timer:Timer = new Timer( delay, 1 ); 54 | timer.addEventListener( TimerEvent.TIMER, sendMockResult ); 55 | timer.start(); 56 | 57 | calls[ timer ] = token; 58 | 59 | if( showBusyCursor ) 60 | { 61 | CursorManager.setBusyCursor(); 62 | } 63 | 64 | return token; 65 | } 66 | 67 | protected function sendMockResult( event:TimerEvent ):void 68 | { 69 | if( showBusyCursor ) 70 | { 71 | CursorManager.removeBusyCursor(); 72 | } 73 | 74 | var timer:Timer = Timer( event.target ); 75 | timer.removeEventListener( TimerEvent.TIMER, sendMockResult ); 76 | 77 | if( calls[ timer ] is AsyncToken ) 78 | { 79 | var token:AsyncToken = AsyncToken( calls[ timer ] ); 80 | delete calls[ timer ]; 81 | 82 | var mockData:Object = ( token.data ) ? token.data : new Object(); 83 | token.mx_internal::applyResult(ResultEvent.createEvent(mockData, token)); 84 | } 85 | 86 | timer = null; 87 | } 88 | 89 | public function createMockFault( fault:Fault = null, delay:int = 10 ):AsyncToken 90 | { 91 | var token:AsyncToken = new AsyncToken(); 92 | token.data = fault; 93 | 94 | var timer:Timer = new Timer( delay, 1 ); 95 | timer.addEventListener( TimerEvent.TIMER, sendMockFault ); 96 | timer.start(); 97 | 98 | calls[ timer ] = token; 99 | 100 | if( showBusyCursor ) 101 | { 102 | CursorManager.setBusyCursor(); 103 | } 104 | 105 | return token; 106 | } 107 | 108 | protected function sendMockFault( event:TimerEvent ):void 109 | { 110 | if( showBusyCursor ) 111 | { 112 | CursorManager.removeBusyCursor(); 113 | } 114 | 115 | var timer:Timer = Timer( event.target ); 116 | timer.removeEventListener( TimerEvent.TIMER, sendMockFault ); 117 | 118 | if( calls[ timer ] is AsyncToken ) 119 | { 120 | var token:AsyncToken = calls[ timer ]; 121 | delete calls[ timer ]; 122 | 123 | var fault:Fault = ( token.data ) ? token.data : null; 124 | token.mx_internal::applyFault( FaultEvent.createEvent( fault, token ) ); 125 | } 126 | 127 | timer = null; 128 | } 129 | } 130 | } -------------------------------------------------------------------------------- /src/org/swizframework/utils/services/ServiceHelper.as: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Swiz Framework Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.swizframework.utils.services 18 | { 19 | import mx.rpc.AsyncToken; 20 | 21 | import org.swizframework.core.ISwiz; 22 | import org.swizframework.core.ISwizAware; 23 | 24 | public class ServiceHelper implements IServiceHelper, ISwizAware 25 | { 26 | protected var _swiz:ISwiz; 27 | 28 | public function set swiz( swiz:ISwiz ):void 29 | { 30 | _swiz = swiz; 31 | } 32 | 33 | public function executeServiceCall( call:AsyncToken, resultHandler:Function, faultHandler:Function = null, handlerArgs:Array = null ):AsyncToken 34 | { 35 | // use default fault handler defined for swiz instance if not provided 36 | // check if swiz is set which is not the case if ServiceHelper is used in a testing environment 37 | if( faultHandler == null && _swiz != null && _swiz.config.defaultFaultHandler != null ) 38 | faultHandler = _swiz.config.defaultFaultHandler; 39 | 40 | call.addResponder( new SwizResponder( resultHandler, faultHandler, handlerArgs ) ); 41 | 42 | return call; 43 | } 44 | } 45 | } -------------------------------------------------------------------------------- /src/org/swizframework/utils/services/SwizResponder.as: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Swiz Framework Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.swizframework.utils.services 18 | { 19 | import mx.rpc.IResponder; 20 | 21 | public class SwizResponder implements IResponder 22 | { 23 | private var resultHandler:Function; 24 | private var faultHandler:Function; 25 | private var handlerArgs:Array; 26 | 27 | public function SwizResponder( resultHandler:Function, faultHandler:Function = null, handlerArgs:Array = null ) 28 | { 29 | this.resultHandler = resultHandler; 30 | this.faultHandler = faultHandler; 31 | this.handlerArgs = handlerArgs; 32 | } 33 | 34 | public function result( data:Object ):void 35 | { 36 | if( handlerArgs == null ) 37 | { 38 | resultHandler( data ); 39 | } 40 | else 41 | { 42 | resultHandler.apply( null, [ data ].concat( handlerArgs ) ); 43 | } 44 | } 45 | 46 | public function fault( info:Object ):void 47 | { 48 | if( faultHandler != null ) 49 | { 50 | if( handlerArgs == null ) 51 | { 52 | faultHandler( info ); 53 | } 54 | else 55 | { 56 | try 57 | { 58 | faultHandler( info ); 59 | } 60 | catch( e:Error ) 61 | { 62 | faultHandler.apply( null, [ info ].concat( handlerArgs ) ); 63 | } 64 | } 65 | } 66 | else 67 | { 68 | // todo: what if there is no fault handler applied to dynamic responder 69 | // ben says fails silently, maybe logging is smarter... 70 | } 71 | } 72 | } 73 | } -------------------------------------------------------------------------------- /src/org/swizframework/utils/services/SwizURLRequest.as: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Swiz Framework Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.swizframework.utils.services 18 | { 19 | import flash.events.Event; 20 | import flash.events.HTTPStatusEvent; 21 | import flash.events.IOErrorEvent; 22 | import flash.events.ProgressEvent; 23 | import flash.events.SecurityErrorEvent; 24 | import flash.net.URLLoader; 25 | import flash.net.URLRequest; 26 | 27 | /** 28 | * 29 | * SwizURLRequest can be used to wrap URLLoader calles. 30 | * The faultHandler function will be used for IOErrors and SecurityErrors 31 | * so you should type the argument Event and check/cast the specific type 32 | * in the method body. 33 | * 34 | * When used implicitly from Swiz.executeUrlRequest or AbstractController.executeUrlRequest 35 | * the generic fault handler will be applied if available. Otherwise in an error case 36 | * the Swiz internal generic fault shows up. 37 | * 38 | */ 39 | public class SwizURLRequest 40 | { 41 | public var loader:URLLoader; 42 | 43 | /** 44 | * 45 | * @param request 46 | * @param resultHandler The resultHandler function must expect the an event. event.currentTarget.data should contain the result. Signature can be extended with additional handlerArgs 47 | * @param faultHandler The faultHandler function will be called for IOErrors and SecurityErrors with the specific error event. 48 | * @param progressHandler 49 | * @param httpStatusHandler 50 | * @param handlerArgs The handlerArgs will be applied to the signature of the resultHandler function. 51 | * 52 | */ 53 | public function SwizURLRequest( request:URLRequest, resultHandler:Function, 54 | faultHandler:Function = null, progressHandler:Function = null, 55 | httpStatusHandler:Function = null, handlerArgs:Array = null ) 56 | { 57 | loader = new URLLoader(); 58 | 59 | loader.addEventListener( Event.COMPLETE, function( e:Event ):void 60 | { 61 | // we could apply the result directly but from the current knowledge applying the event itself 62 | // seems more flexible. This may change in the future if we don't see any necessity for this. 63 | 64 | if( handlerArgs == null ) 65 | { 66 | resultHandler( e ); 67 | } 68 | else 69 | { 70 | resultHandler.apply( null, [ e ].concat( handlerArgs ) ); 71 | } 72 | } ); 73 | 74 | if( faultHandler != null ) 75 | { 76 | loader.addEventListener( IOErrorEvent.IO_ERROR, function( e:IOErrorEvent ):void 77 | { 78 | if( handlerArgs == null ) 79 | { 80 | faultHandler( e ); 81 | } 82 | else 83 | { 84 | faultHandler.apply( null, [ e ].concat( handlerArgs ) ); 85 | } 86 | } ); 87 | 88 | loader.addEventListener( SecurityErrorEvent.SECURITY_ERROR, function( e:SecurityErrorEvent ):void 89 | { 90 | if( handlerArgs == null ) 91 | { 92 | faultHandler( e ); 93 | } 94 | else 95 | { 96 | faultHandler.apply( null, [ e ].concat( handlerArgs ) ); 97 | } 98 | } ); 99 | } 100 | 101 | if( progressHandler != null ) 102 | { 103 | loader.addEventListener( ProgressEvent.PROGRESS, function( e:ProgressEvent ):void 104 | { 105 | if( handlerArgs == null ) 106 | { 107 | progressHandler( e ); 108 | } 109 | else 110 | { 111 | progressHandler.apply( null, [ e ].concat( handlerArgs ) ); 112 | } 113 | } ); 114 | } 115 | 116 | if( httpStatusHandler != null ) 117 | { 118 | loader.addEventListener( HTTPStatusEvent.HTTP_STATUS, function( e:HTTPStatusEvent ):void 119 | { 120 | if( handlerArgs == null ) 121 | { 122 | httpStatusHandler( e ); 123 | } 124 | else 125 | { 126 | httpStatusHandler.apply( null, [ e ].concat( handlerArgs ) ); 127 | } 128 | } ); 129 | } 130 | 131 | loader.load( request ); 132 | } 133 | } 134 | } -------------------------------------------------------------------------------- /src/org/swizframework/utils/services/URLRequestHelper.as: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Swiz Framework Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.swizframework.utils.services 18 | { 19 | import flash.net.URLLoader; 20 | import flash.net.URLRequest; 21 | 22 | import org.swizframework.core.ISwiz; 23 | import org.swizframework.core.ISwizAware; 24 | 25 | public class URLRequestHelper implements IURLRequestHelper, ISwizAware 26 | { 27 | protected var _swiz:ISwiz; 28 | 29 | public function set swiz( swiz:ISwiz ):void 30 | { 31 | _swiz = swiz; 32 | } 33 | 34 | /** Delegates execute url request call to Swiz */ 35 | public function executeURLRequest( request:URLRequest, resultHandler:Function, faultHandler:Function = null, 36 | progressHandler:Function = null, httpStatusHandler:Function = null, 37 | handlerArgs:Array = null ):URLLoader 38 | { 39 | // use default fault handler defined for swiz instance if not provided 40 | if( faultHandler == null && _swiz.config.defaultFaultHandler != null ) 41 | faultHandler = _swiz.config.defaultFaultHandler; 42 | 43 | return new SwizURLRequest( request, resultHandler, faultHandler, progressHandler, httpStatusHandler, handlerArgs ).loader; 44 | } 45 | } 46 | } -------------------------------------------------------------------------------- /src/org/swizframework/utils/test/AutowiredTestCase.as: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Swiz Framework Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.swizframework.utils.test 18 | { 19 | import flash.events.EventDispatcher; 20 | import flash.events.IEventDispatcher; 21 | 22 | import org.swizframework.core.Bean; 23 | import org.swizframework.core.Swiz; 24 | import org.swizframework.core.SwizConfig; 25 | import org.swizframework.reflection.TypeCache; 26 | 27 | /** 28 | * AutowiredTestCase provides a base class for unit testing that provides autowiring. 29 | * A child test case should set the beanProvider and swizConfig properties in it's constructor. A new 30 | * Swiz Context will be created in the test's [Before] method. 31 | */ 32 | public class AutowiredTestCase extends EventDispatcher 33 | { 34 | /** 35 | * Backing variable for beanProvider getter/setter. 36 | */ 37 | private var _beanProviders:Array; 38 | 39 | /** 40 | * Backing variable for swizConfig getter/setter. 41 | */ 42 | private var _swizConfig:SwizConfig; 43 | 44 | /** 45 | * Backing variable for swiz getter/setter. 46 | */ 47 | private var _swiz:Swiz; 48 | 49 | public function AutowiredTestCase(target:IEventDispatcher=null) 50 | { 51 | super(target); 52 | } 53 | 54 | /** 55 | * Setter for beanProvider property. 56 | */ 57 | public function set beanProviders(beanProviders:Array):void 58 | { 59 | _beanProviders = beanProviders; 60 | } 61 | 62 | 63 | /** 64 | * Getter for beanProvider property. 65 | */ 66 | public function get beanProviders():Array 67 | { 68 | return _beanProviders; 69 | } 70 | 71 | /** 72 | * Setter for swizConfig property. 73 | */ 74 | public function set swizConfig(swizConfig:SwizConfig):void 75 | { 76 | _swizConfig = swizConfig; 77 | } 78 | 79 | 80 | /** 81 | * Getter for swizConfig property. 82 | */ 83 | public function get swizConfig():SwizConfig 84 | { 85 | return _swizConfig; 86 | } 87 | 88 | /** 89 | * Getter for local Swiz instance. 90 | */ 91 | public function get swiz():Swiz 92 | { 93 | return _swiz; 94 | } 95 | 96 | /** 97 | * 98 | */ 99 | // [Before("order=1"] 100 | [Before] 101 | public function constructSwizContext():void 102 | { 103 | 104 | trace("constructSwizContext() called"); 105 | 106 | // initialize bean factory with configurec bean provider 107 | if( _swiz == null && _beanProviders != null ) 108 | { 109 | _swiz = new Swiz(null, _swizConfig, null, _beanProviders); 110 | _swiz.init(); 111 | 112 | // wrap the unit test in a Bean definition 113 | var bean:Bean = new Bean(); 114 | bean.source = this; 115 | bean.typeDescriptor = TypeCache.getTypeDescriptor( bean.type, _swiz.domain ); 116 | 117 | // autowire test case with bean factory 118 | _swiz.beanFactory.setUpBean( bean ); 119 | } 120 | } 121 | 122 | } 123 | } -------------------------------------------------------------------------------- /test/SwizTestRunner.mxml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 11 | 45 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /test/org/swizframework/reflection/TypeCacheTests.as: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Swiz Framework Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.swizframework.reflection 18 | { 19 | import flash.display.Sprite; 20 | import flash.system.ApplicationDomain; 21 | 22 | import flexunit.framework.Assert; 23 | 24 | public class TypeCacheTests 25 | { 26 | 27 | [Test] 28 | public function typeDescriptorsAreCached():void 29 | { 30 | var td1:TypeDescriptor = TypeCache.getTypeDescriptor( new Sprite(), ApplicationDomain.currentDomain ); 31 | var td2:TypeDescriptor = TypeCache.getTypeDescriptor( new Sprite(), ApplicationDomain.currentDomain ); 32 | 33 | Assert.assertStrictlyEquals( td1, td2 ); 34 | } 35 | } 36 | } -------------------------------------------------------------------------------- /test/org/swizframework/storage/SharedObjectBeanTest.as: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Swiz Framework Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package org.swizframework.storage 18 | { 19 | import org.flexunit.asserts.assertEquals; 20 | import org.flexunit.asserts.assertFalse; 21 | import org.flexunit.asserts.assertNull; 22 | import org.flexunit.asserts.assertTrue; 23 | import org.swizframework.storage.ISharedObjectBean; 24 | import org.swizframework.storage.SharedObjectBean; 25 | 26 | public class SharedObjectBeanTest 27 | { 28 | private var _soBean:ISharedObjectBean; 29 | 30 | [Before] 31 | public function setUp():void 32 | { 33 | _soBean = new SharedObjectBean(); 34 | _soBean.name = "SwizTest"; 35 | _soBean.clear(); 36 | } 37 | 38 | [Test] 39 | public function testClear():void 40 | { 41 | _soBean.setValue("Foo", "Bar"); 42 | _soBean.clear(); 43 | assertEquals(null, _soBean.getValue("Foo")); 44 | } 45 | 46 | [Test] 47 | public function testHasValue():void 48 | { 49 | assertEquals(false, _soBean.hasValue("Foo")); 50 | _soBean.setValue("Foo", "Bar"); 51 | assertEquals(true, _soBean.hasValue("Foo")); 52 | } 53 | 54 | [Test] 55 | public function testSize():void 56 | { 57 | assertEquals(0, _soBean.size); 58 | _soBean.setValue("Foo", "Bar"); 59 | assertFalse(0 == _soBean.size); 60 | } 61 | 62 | [Test] 63 | public function testValue():void 64 | { 65 | assertEquals(null, _soBean.getValue("Foo")); 66 | _soBean.clear(); 67 | assertEquals("Bar", _soBean.getValue("Foo", "Bar")); 68 | _soBean.setValue("Foo", "Bar2"); 69 | assertEquals("Bar2", _soBean.getValue("Foo")); 70 | } 71 | 72 | [Test] 73 | public function testString():void 74 | { 75 | assertEquals(null, _soBean.getString("Foo")); 76 | assertEquals("Bar", _soBean.getString("Foo", "Bar")); 77 | _soBean.setString("Foo", "Bar2"); 78 | assertEquals("Bar2", _soBean.getString("Foo")); 79 | } 80 | 81 | [Test] 82 | public function testBoolean():void 83 | { 84 | assertEquals(false, _soBean.getBoolean("Foo")); 85 | _soBean.clear(); 86 | assertEquals(true, _soBean.getBoolean("Foo", true)); 87 | _soBean.setBoolean("Foo", true); 88 | assertEquals(true, _soBean.getBoolean("Foo")); 89 | } 90 | 91 | [Test] 92 | public function testNumber():void 93 | { 94 | assertTrue(isNaN(_soBean.getNumber("Foo"))); 95 | _soBean.clear(); 96 | assertEquals(1.5, _soBean.getNumber("Foo", 1.5)); 97 | _soBean.setNumber("Foo", 2.5); 98 | assertEquals(2.5, _soBean.getNumber("Foo")); 99 | } 100 | 101 | [Test] 102 | public function testInt():void 103 | { 104 | assertEquals(-1, _soBean.getInt("Foo")); 105 | _soBean.clear(); 106 | assertEquals(1, _soBean.getNumber("Foo", 1)); 107 | _soBean.setNumber("Foo", 2); 108 | assertEquals(2, _soBean.getNumber("Foo")); 109 | } 110 | 111 | } 112 | } -------------------------------------------------------------------------------- /test/testSuites/ReflectionTestsSuite.as: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Swiz Framework Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package testSuites 18 | { 19 | import org.swizframework.reflection.ClassConstantTest; 20 | import org.swizframework.reflection.TypeCacheTests; 21 | 22 | [Suite] 23 | [RunWith( "org.flexunit.runners.Suite" )] 24 | public class ReflectionTestsSuite 25 | { 26 | //public var typeCacheTests:TypeCacheTests; 27 | public var classConstantTests:ClassConstantTest; 28 | } 29 | } -------------------------------------------------------------------------------- /test/testSuites/StorageTestSuite.as: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010 Swiz Framework Contributors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | package testSuites 18 | { 19 | import org.swizframework.storage.SharedObjectBeanTest; 20 | 21 | [Suite] 22 | [RunWith( "org.flexunit.runners.Suite" )] 23 | public class StorageTestSuite 24 | { 25 | public var _soTest:SharedObjectBeanTest; 26 | } 27 | } --------------------------------------------------------------------------------