+ }
+
+ DUMP_PARSE_TREE(parser); // This macro only writes out if DEBUG is enabled and the "DUMP_TREE" constant is defined in the stylesheet.
+ DUMP_TEST_MAPPINGS(parser);
+
+ DALI_ASSERT_ALWAYS(mParser.GetRoot() && "Cannot parse JSON");
+}
+
+void Builder::AddConstants( const Property::Map& map )
+{
+ mReplacementMap.Merge( map );
+}
+
+void Builder::AddConstant( const std::string& key, const Property::Value& value )
+{
+ mReplacementMap[key] = value;
+}
+
+const Property::Map& Builder::GetConstants() const
+{
+ return mReplacementMap;
+}
+
+const Property::Value& Builder::GetConstant( const std::string& key ) const
+{
+ Property::Value* match = mReplacementMap.Find( key );
+ if( match )
+ {
+ return (*match);
+ }
+ else
+ {
+ static Property::Value invalid;
+ return invalid;
+ }
+}
+
+Animation Builder::CreateAnimation( const std::string& animationName, const Property::Map& map, Dali::Actor sourceActor )
+{
+ Replacement replacement(map, mReplacementMap);
+ return CreateAnimation( animationName, replacement, sourceActor);
+}
+
+Animation Builder::CreateAnimation( const std::string& animationName, const Property::Map& map )
+{
+ Replacement replacement(map, mReplacementMap);
+ return CreateAnimation( animationName, replacement, Stage::GetCurrent().GetRootLayer() );
+}
+
+Animation Builder::CreateAnimation( const std::string& animationName, Dali::Actor sourceActor )
+{
+ Replacement replacement( mReplacementMap );
+
+ return CreateAnimation( animationName, replacement, sourceActor );
+}
+
+Animation Builder::CreateAnimation( const std::string& animationName )
+{
+ Replacement replacement( mReplacementMap );
+
+ return CreateAnimation( animationName, replacement, Dali::Stage::GetCurrent().GetRootLayer() );
+}
+
+BaseHandle Builder::Create( const std::string& templateName )
+{
+ Replacement replacement( mReplacementMap );
+ return Create( templateName, replacement );
+}
+
+BaseHandle Builder::Create( const std::string& templateName, const Property::Map& map )
+{
+ Replacement replacement( map, mReplacementMap );
+ return Create( templateName, replacement );
+}
+
+BaseHandle Builder::CreateFromJson( const std::string& json )
+{
+ BaseHandle ret;
+
+ // merge in new template, hoping no one else has one named '@temp@'
+ std::string newTemplate =
+ std::string("{\"templates\":{\"@temp@\":") + \
+ json + \
+ std::string("}}");
+
+ if( mParser.Parse(newTemplate) )
+ {
+ Replacement replacement( mReplacementMap );
+ ret = Create( "@temp@", replacement );
+ }
+
+ return ret;
+}
+
+bool Builder::ApplyFromJson( Handle& handle, const std::string& json )
+{
+ bool ret = false;
+
+ // merge new style, hoping no one else has one named '@temp@'
+ std::string newStyle =
+ std::string("{\"styles\":{\"@temp@\":") + \
+ json + \
+ std::string("}}");
+
+ if( mParser.Parse(newStyle) )
+ {
+ Replacement replacement( mReplacementMap );
+ ret = ApplyStyle( "@temp@", handle, replacement );
+ }
+
+ return ret;
+}
+
+bool Builder::ApplyStyle( const std::string& styleName, Handle& handle )
+{
+ Replacement replacer( mReplacementMap );
+ return ApplyStyle( styleName, handle, replacer );
+}
+
+bool Builder::LookupStyleName( const std::string& styleName )
+{
+ DALI_ASSERT_ALWAYS(mParser.GetRoot() && "Builder script not loaded");
+
+ OptionalChild styles = IsChild( *mParser.GetRoot(), KEYNAME_STYLES );
+ OptionalChild style = IsChildIgnoreCase( *styles, styleName );
+
+ if( styles && style )
+ {
+ return true;
+ }
+ return false;
+}
+
+const StylePtr Builder::GetStyle( const std::string& styleName )
+{
+ const StylePtr* style = mStyles.FindConst( styleName );
+
+ if( style==NULL )
+ {
+ return StylePtr(NULL);
+ }
+ else
+ {
+ return *style;
+ }
+}
+
+void Builder::AddActors( Actor toActor )
+{
+ // 'stage' is the default/by convention section to add from
+ AddActors( "stage", toActor );
+}
+
+void Builder::AddActors( const std::string §ionName, Actor toActor )
+{
+ DALI_ASSERT_ALWAYS(mParser.GetRoot() && "Builder script not loaded");
+
+ Property::Map overrideMap;
+ Replacement replacements(overrideMap, mReplacementMap);
+
+ OptionalChild add = IsChild(*mParser.GetRoot(), sectionName);
+
+ if( add )
+ {
+ for( TreeNode::ConstIterator iter = (*add).CBegin(); iter != (*add).CEnd(); ++iter )