Permalink
Browse files

Merge branch 'release-v1.3.0'

  • Loading branch information...
2 parents 7a207b1 + f45a1e3 commit 05c79810e4aaae27d4b88daf594f5a50d046afa9 @bclinkinbeard bclinkinbeard committed Aug 23, 2011
View
2 build/build.properties
@@ -1,5 +1,5 @@
# Versioning
-swiz.version = v1.2.0
+swiz.version = v1.3.0
swiz.name = swiz-framework-${swiz.version}
swiz.name.flex3 = ${swiz.name}-flex3
swiz.namespace = http://swiz.swizframework.org
View
2 build/build.xml
@@ -82,6 +82,7 @@
<include-namespaces uri="${swiz.namespace}" />
<include-file name="metadata.xml" path="${src.loc}/metadata.xml" />
+ <include-file name="design.xml" path="${src.loc}/design.xml" />
<!-- add flex3/flex4 compiler arg -->
<compiler.define name="CONFIG::flex3" value="false" />
@@ -116,6 +117,7 @@
<include-namespaces uri="${swiz.namespace}" />
<include-file name="metadata.xml" path="${src.loc}/metadata.xml" />
+ <include-file name="design.xml" path="${src.loc}/design.xml" />
<!-- add flex3/flex4 compiler arg -->
<compiler.define name="CONFIG::flex3" value="true" />
View
25 src/design.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0"?>
+<design version="2">
+
+ <namespaces>
+ <namespace prefix="swiz" uri="http://swiz.swizframework.org" />
+ </namespaces>
+
+ <categories>
+ <category id="Swiz" label="Swiz Framework" defaultExpand="true" />
+ </categories>
+
+ <components>
+ <component name="Swiz" displayName="Swiz" namespace="swiz" category="Swiz" />
+ <component name="SwizConfig" displayName="SwizConfig" namespace="swiz" category="Swiz" />
+ <component name="Bean" displayName="Bean" namespace="swiz" category="Swiz" />
+ <component name="BeanProvider" displayName="BeanProvider" namespace="swiz" category="Swiz" />
+ <component name="Prototype" displayName="Prototype" namespace="swiz" category="Swiz" />
+ <component name="SwizTraceTarget" displayName="SwizTraceTarget" namespace="swiz" category="Swiz" />
+ <component name="ServiceHelper" displayName="ServiceHelper" namespace="swiz" category="Swiz" />
+ <component name="ChannelSetHelper" displayName="ChannelSetHelper" namespace="swiz" category="Swiz" />
+ <component name="MockDelegateHelper" displayName="MockDelegateHelper" namespace="swiz" category="Swiz" />
+ <component name="URLRequestHelper" displayName="URLRequestHelper" namespace="swiz" category="Swiz" />
+ </components>
+
+</design>
View
34 src/manifest.xml
@@ -1,28 +1,16 @@
<?xml version="1.0"?>
<componentPackage>
- <component class="org.swizframework.core.mxml.Swiz" />
-
- <!-- core package -->
- <component class="org.swizframework.core.SwizConfig" />
- <component class="org.swizframework.core.Bean" />
- <component class="org.swizframework.core.BeanFactory" />
- <component class="org.swizframework.core.BeanProvider" />
- <component class="org.swizframework.core.BeanLoader" />
- <component class="org.swizframework.core.Prototype" />
-
- <!-- events package -->
- <component class="org.swizframework.events.BeanEvent" />
-
- <!-- factories package -->
- <component class="org.swizframework.factories.MetadataHostFactory" />
-
- <!-- utils package -->
- <component class="org.swizframework.utils.logging.SwizLogger" />
- <component class="org.swizframework.utils.logging.SwizTraceTarget" />
- <component class="org.swizframework.utils.services.ServiceHelper" />
- <component class="org.swizframework.utils.services.ChannelSetHelper" />
- <component class="org.swizframework.utils.services.MockDelegateHelper" />
- <component class="org.swizframework.utils.services.URLRequestHelper" />
+ <component id="Bean" class="org.swizframework.core.Bean" />
+ <component id="BeanProvider" class="org.swizframework.core.BeanProvider" />
+ <component id="ChannelSetHelper" class="org.swizframework.utils.services.ChannelSetHelper" />
+ <component id="MockDelegateHelper" class="org.swizframework.utils.services.MockDelegateHelper" />
+ <component id="Prototype" class="org.swizframework.core.Prototype" />
+ <component id="ServiceHelper" class="org.swizframework.utils.services.ServiceHelper" />
+ <component id="SharedObjectBean" class="org.swizframework.storage.SharedObjectBean" />
+ <component id="Swiz" class="org.swizframework.core.mxml.Swiz" />
+ <component id="SwizConfig" class="org.swizframework.core.SwizConfig" />
+ <component id="SwizTraceTarget" class="org.swizframework.utils.logging.SwizTraceTarget" />
+ <component id="URLRequestHelper" class="org.swizframework.utils.services.URLRequestHelper" />
</componentPackage>
View
6 src/metadata.xml
@@ -132,4 +132,10 @@
<context name="setter" />
<context name="method" />
</metadata>
+
+ <metadata name="ViewNavigator" description="Passes in the ViewNavigator instance in a Flex mobile app">
+ <context name="variable" />
+ <context name="setter" />
+ <context name="method" />
+ </metadata>
</annotations>
View
19 src/org/swizframework/core/BeanFactory.as
@@ -47,6 +47,8 @@ package org.swizframework.core
protected const ignoredClasses:RegExp = /^mx\.|^spark\.|^flash\.|^fl\.|__/;
+ protected const viewNavigatorClassName:String = "spark.components::ViewNavigator";
+
protected var swiz:ISwiz;
/**
@@ -114,7 +116,8 @@ package org.swizframework.core
public function completeBeanFactorySetup():void
{
- if( waitForSetup ) return;
+ if( waitForSetup )
+ return;
logger.info( "BeanFactory completing setup" );
@@ -249,7 +252,7 @@ package org.swizframework.core
{
if( beans.indexOf( bean ) > -1 )
beans.splice( beans.indexOf( bean ), 1 );
-
+
tearDownBean( bean );
bean.beanFactory = null;
bean.typeDescriptor = null;
@@ -468,6 +471,11 @@ package org.swizframework.core
{
return false;
}
+ // exception to support ViewAdded/Removed for spark.components.ViewNavigator (in mobile apps)
+ else if( className == viewNavigatorClassName )
+ {
+ return true;
+ }
else if( swiz.config.viewPackages.length > 0 )
{
for each( var viewPackage:String in swiz.config.viewPackages )
@@ -534,14 +542,9 @@ package org.swizframework.core
if( event.target is ITearDownValidator && !( ITearDownValidator( event.target ).allowTearDown() ) )
return;
- if( !isPotentialInjectionTarget( event.target ) )
- return;
-
+ // only views previously processed can be torn down
if( SwizManager.wiredViews[ event.target ] )
addRemovedDisplayObject( DisplayObject( event.target ) );
-
- if( event.target is ModuleTypeUtil.MODULE_TYPE )
- addRemovedDisplayObject( DisplayObject( event.target ) );
}
protected function addRemovedDisplayObject( displayObject:DisplayObject ):void
View
3 src/org/swizframework/core/Swiz.as
@@ -425,10 +425,11 @@ package org.swizframework.core
{
if( event.swiz != null && event.swiz.parentSwiz == null )
{
+ event.stopImmediatePropagation();
event.swiz.parentSwiz = this;
}
- logger.info( "Received SwizCreationEvent, set self to parent." );
+ logger.info( "Received SwizEvent.CREATED, set self to parent." );
}
}
}
View
10 src/org/swizframework/events/SwizEvent.as
@@ -30,20 +30,20 @@ package org.swizframework.events
// ========================================
/**
- * The BeanEvent.ADDED constant defines the value of the type property
- * of a beanAdded event object.
+ * The SwizEvent.CREATED constant defines the value of the type property
+ * of a swizCreated event object.
*/
public static const CREATED:String = "swizCreated";
/**
- * The BeanEvent.LOAD_COMPLETE constant defines the value of the type property
+ * The SwizEvent.LOAD_COMPLETE constant defines the value of the type property
* of an initial load complete event object.
*/
public static const LOAD_COMPLETE:String = "loadComplete";
/**
- * The BeanEvent.REMOVED constant defines the value of the type property
- * of a beanRemoved event object.
+ * The SwizEvent.DESTROYED constant defines the value of the type property
+ * of a swizDestroyed event object.
*/
public static const DESTROYED:String = "swizDestroyed";
View
14 src/org/swizframework/processors/InjectProcessor.as
@@ -127,7 +127,7 @@ package org.swizframework.processors
var destPropName:* = getDestinationPropertyName( injectTag );
var chain:String = injectTag.source.substr( injectTag.source.indexOf( "." ) + 1 );
- var bind:Boolean = injectTag.bind && ChangeWatcher.canWatch( namedBean.source, chain ) && !( destPropName is QName );
+ var bind:Boolean = injectTag.bind && !( destPropName is QName );
// if injecting by name simply assign the bean's current value
// as there is no context to create a binding
@@ -387,16 +387,8 @@ package org.swizframework.processors
// the last token of the source attribute is the actual property name
var sourcePropName:String = sourcePropertyChain[ 0 ];
- // create the reverse binding where the view/new bean is the source
- if( ChangeWatcher.canWatch( destObject, destPropName ) )
- {
- // if a destination was provided we can use it as the host chain value
- injectByProperty[ uid ].push( BindingUtils.bindProperty( sourceObject, sourcePropName, destObject, destPropName ) );
- }
- else
- {
- logger.error( "Cannot create twoWay binding for {0} property on {1} because it is not bindable.", destPropName, destObject );
- }
+ // create the reverse binding where the view/new bean (or its property) is the source
+ injectByProperty[ uid ].push( BindingUtils.bindProperty( sourceObject, sourcePropName, destObject, destPropName ) );
}
}
View
21 src/org/swizframework/processors/ViewProcessor.as
@@ -34,6 +34,7 @@ package org.swizframework.processors
protected static const VIEW_ADDED:String = "ViewAdded";
protected static const VIEW_REMOVED:String = "ViewRemoved";
+ protected static const VIEW_NAVIGATOR:String = "ViewNavigator";
// ========================================
// protected properties
@@ -62,22 +63,22 @@ package org.swizframework.processors
*/
public function ViewProcessor( metadataNames:Array = null )
{
- super( ( metadataNames == null ) ? [ VIEW_ADDED, VIEW_REMOVED ] : metadataNames );
+ super( ( metadataNames == null ) ? [ VIEW_ADDED, VIEW_REMOVED, VIEW_NAVIGATOR ] : metadataNames );
}
// ========================================
// public methods
// ========================================
/**
- * This method is called whenever a bean is added that contains [ViewAdded]
- * and/or [ViewRemoved] tags. These will/should be regular beans defined
+ * This method is called whenever a bean is added that contains [ViewAdded],
+ * [ViewRemoved] and/or [ViewNavigator] tags. These will/should be regular beans defined
* in a BeanProvider that want to be notified when a particular type of view
* is set up or torn down, respectively.
*/
override public function setUpMetadataTags( metadataTags:Array, bean:Bean ):void
{
- // parse any [ViewAdded] and [ViewRemoved] tags found
+ // parse any [ViewAdded], [ViewRemoved] or [ViewNavigator] tags found
for each ( var tag:IMetadataTag in metadataTags )
{
var viewType:Class;
@@ -97,13 +98,13 @@ package org.swizframework.processors
}
/**
- * This method is called whenever a bean that contains [ViewAdded]
- * and/or [ViewRemoved] tags is torn down. This would likely only
+ * This method is called whenever a bean that contains [ViewAdded],
+ * [ViewRemoved] and/or [ViewNavigator] tags is torn down. This would likely only
* happen if the bean (mediator) was part of a module that was torn down.
*/
override public function tearDownMetadataTags( metadataTags:Array, bean:Bean ):void
{
- // parse any [ViewAdded] and [ViewRemoved] tags found
+ // parse any [ViewAdded], [ViewRemoved] or [ViewNavigator] tags found
for each ( var tag:IMetadataTag in metadataTags )
{
var viewType:Class;
@@ -157,16 +158,16 @@ package org.swizframework.processors
for each( var ref:ViewRef in refs )
{
- if( ref.tag.name != tagName )
+ if( ref.tag.name != tagName && ref.tag.name != VIEW_NAVIGATOR )
continue;
- // if [ViewAdded] was declared on a method we pass the view in as the only argument
+ // if tag was declared on a method we pass the view in as the only argument
if( ref.tag.host is MetadataHostMethod )
{
var f:Function = ref.mediator[ ref.tag.host.name ] as Function;
f.apply( null, [ bean.source ] );
}
- else // if [ViewAdded] was declared on a property do a simple assignment
+ else // if tag was declared on a property do a simple assignment
{
ref.mediator[ ref.tag.host.name ] = bean.source;
}
View
24 src/org/swizframework/reflection/MetadataHostMethod.as
@@ -62,6 +62,30 @@ package org.swizframework.reflection
return _parameters;
}
+ /**
+ * @return The total number of parameters for the method.
+ */
+ public function get parameterCount():int
+ {
+ return parameters.length;
+ }
+
+ /**
+ * @returns The number of required parameters for the method.
+ */
+ public function get requiredParameterCount():int
+ {
+ var requiredParameterCount:int = 0;
+
+ for each( var parameter:MethodParameter in parameters )
+ {
+ if( !parameter.optional )
+ requiredParameterCount++;
+ }
+
+ return requiredParameterCount;
+ }
+
// ========================================
// constructor
// ========================================
View
29 src/org/swizframework/utils/commands/CommandMap.as
@@ -39,9 +39,17 @@ package org.swizframework.utils.commands
*/
public function set swiz( swiz:ISwiz ):void
{
- _swiz = swiz;
-
- mapCommands();
+ // if swiz is null, we are being torn down
+ if( swiz )
+ {
+ _swiz = swiz;
+ mapCommands();
+ }
+ else
+ {
+ unmapCommands();
+ _swiz = swiz;
+ }
}
// ========================================
@@ -104,7 +112,8 @@ package org.swizframework.utils.commands
mappings.splice( indexesToClear[ j ], 1 );
}
- if( indexesToClear.length == 0 )
+ // if no more commands are mapped to this event type, remove from map
+ if( mappings.length == 0 )
delete map[ event.type ];
}
}
@@ -155,6 +164,18 @@ package org.swizframework.utils.commands
// listen for event that will trigger this command
_swiz.dispatcher.addEventListener( eventType, handleCommandEvent, false, 0, true );
}
+
+ protected function unmapCommands():void
+ {
+ for( var eventType:* in map )
+ {
+ _swiz.dispatcher.removeEventListener( eventType, handleCommandEvent );
+
+ delete map[ eventType ];
+ }
+
+ map = null;
+ }
}
}
import flash.events.Event;
View
105 src/org/swizframework/utils/event/EventHandler.as
@@ -52,6 +52,11 @@ package org.swizframework.utils.event
*/
protected var _eventClass:Class;
+ /**
+ * Strongly typed reference to metadataTag.host
+ */
+ protected var hostMethod:MetadataHostMethod;
+
// ========================================
// public properties
// ========================================
@@ -92,6 +97,8 @@ package org.swizframework.utils.event
_metadataTag = metadataTag;
_method = method;
_eventClass = eventClass;
+
+ verifyTag();
}
// ========================================
@@ -106,27 +113,23 @@ package org.swizframework.utils.event
public function handleEvent( event:Event ):void
{
// ignore if the event types do not match
- if( ( eventClass != null ) && ! ( event is eventClass ) )
+ if( ( eventClass != null ) && !( event is eventClass ) )
return;
var result:* = null;
if( metadataTag.properties != null )
{
- if( validateEvent( event, metadataTag.properties ) )
+ if( validateEvent( event, metadataTag ) )
result = method.apply( null, getEventArgs( event, metadataTag.properties ) );
}
- else if( getRequiredParameterCount() <= 1 )
+ else if( hostMethod.requiredParameterCount <= 1 )
{
- if( ( getParameterCount() > 0 ) && ( event is getParameterType( 0 ) ) )
+ if( hostMethod.parameterCount > 0 && event is getParameterType( 0 ) )
result = method.apply( null, [ event ] );
else
result = method.apply();
}
- else
- {
- throw new Error( "Unable to handle event: " + metadataTag.host.name + "() requires " + getRequiredParameterCount() + " parameters, and no properties were specified." );
- }
if( event is IAsynchronousEvent && IAsynchronousEvent( event ).step != null )
{
@@ -143,6 +146,21 @@ package org.swizframework.utils.event
event.stopImmediatePropagation();
}
+ // ========================================
+ // protected methods
+ // ========================================
+
+ protected function verifyTag():void
+ {
+ hostMethod = MetadataHostMethod( metadataTag.host );
+
+ if( metadataTag.properties == null && hostMethod.requiredParameterCount > 0 && !( getParameterType( 0 ) == eventClass ) )
+ throw new Error( metadataTag.asTag + " is invalid. If you do not specify a properties attribute your method must accept no arguments or the event itself." );
+
+ if( metadataTag.properties != null && ( metadataTag.properties.length < hostMethod.requiredParameterCount || metadataTag.properties.length > hostMethod.parameterCount ) )
+ throw new Error( "The properties attribute of " + metadataTag.asTag + " is not compatible with the method signature of " + hostMethod.name + "()." );
+ }
+
/**
* Validate Event
*
@@ -152,12 +170,28 @@ package org.swizframework.utils.event
* @param properties The required properties specified in the [EventHandler] tag.
* @returns A Boolean value indicating whether the event has all of the required properties specified in the [EventHandler] tag.
*/
- protected function validateEvent( event:Event, properties:Array ):Boolean
+ protected function validateEvent( event:Event, metadataTag:EventHandlerMetadataTag ):Boolean
{
- for each( var property:String in properties )
+ for each( var property:String in metadataTag.properties )
{
- if( ! ( property in event ) )
- throw new Error( "Unable to handle event: " + property + " does not exist as a property of " + getQualifiedClassName( event ) + "." );
+ if( property.indexOf( "." ) < 0 && !( property in event ) )
+ {
+ throw new Error( "Unable to handle event: " + property + " does not exist as a property of " + getQualifiedClassName( event ) + "." );
+ }
+ else
+ {
+ var chain:Array = property.split( "." );
+ var o:Object = event;
+ while( chain.length > 0 )
+ {
+ var prop:String = chain.shift();
+
+ if( prop in o )
+ o = o[ prop ];
+ else
+ throw new Error( "Unable to handle event: " + prop + " does not exist as a property of " + getQualifiedClassName( o ) + " as defined in " + metadataTag.asTag + "." );
+ }
+ }
}
return true;
@@ -175,52 +209,33 @@ package org.swizframework.utils.event
for each( var property:String in properties )
{
- args[ args.length ] = event[ property ];
+ if( property.indexOf( "." ) < 0 )
+ {
+ args[ args.length ] = event[ property ];
+ }
+ else
+ {
+ var chain:Array = property.split( "." );
+ var o:Object = event;
+ while( chain.length > 1 )
+ o = o[ chain.shift() ];
+
+ args[ args.length ] = o[ chain.shift() ];
+ }
}
return args;
}
/**
- * Get Parameter Count
- *
- * @returns The number of parameters for the event handler method.
- */
- protected function getParameterCount():int
- {
- return ( metadataTag.host as MetadataHostMethod ).parameters.length;
- }
-
- /**
- * Get Required Parameter Count
- *
- * @returns The number of required parameters for the event handler method.
- */
- protected function getRequiredParameterCount():int
- {
- var requiredParameterCount:int = 0;
-
- var parameters:Array = ( metadataTag.host as MetadataHostMethod ).parameters;
- for each( var parameter:MethodParameter in parameters )
- {
- if( parameter.optional )
- break;
-
- requiredParameterCount++;
- }
-
- return requiredParameterCount;
- }
-
- /**
* Get Parameter Type
*
* @param parameterIndex The index of parameter of the event handler method.
* @returns The type for the specified parameter.
*/
protected function getParameterType( parameterIndex:int ):Class
{
- var parameters:Array = ( metadataTag.host as MetadataHostMethod ).parameters;
+ var parameters:Array = hostMethod.parameters;
if( parameterIndex < parameters.length )
return ( parameters[ parameterIndex ] as MethodParameter ).type;

0 comments on commit 05c7981

Please sign in to comment.