Futurescale, Inc. PureMVC Home

The PureMVC Framework Code at the Speed of Thought


Over 10 years of community discussion and knowledge are maintained here as a read-only archive.

New discussions should be taken up in issues on the appropriate projects at https://github.com/PureMVC

Pages: [1]
Print
Author Topic: XML content docking proxy solution  (Read 11334 times)
uncleunvoid
Full Member
***
Posts: 27


View Profile Email
« on: November 27, 2009, 09:39:12 »

here is what I started implementing:

a collection of 'docked' xml files that describe my content (pages.xml, layouts.xml, colors.xml, etc.)

i want to put them in separate xmlfilecontent proxies and then have search functions that retrieve the data when necessary.

problem is: some objects described in the xml have IDs instead of values. e.g. an element in the layout had the color 0xff0000. in the xml of layout.xml there is a subnode with  <color>myred</color>. The actual color value is in the color.xml as a color node.

how do I stitch that data together, so that I can use a complete layout object in flash without coupling those proxies too much?
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #1 on: November 27, 2009, 11:57:46 »

If you are working in AIR, you might want to look at the XMLDatabaseProxy Utility.

Otherwise, I'd look at doing a 'smart VO' that wraps the XML and can be smart about things like whether the field has a hex number or a text description.

See an example of a 'Smart VO' here: http://forums.puremvc.org/index.php?topic=1293.msg5973#msg5973

-=Cliff>
Logged
uncleunvoid
Full Member
***
Posts: 27


View Profile Email
« Reply #2 on: November 27, 2009, 03:47:57 »

that example is part of what I am looking for , yet the bigger question is two-fold , so lets just start with teh first:

if the color is in another VO (because it comes from another xml)  who do I infuse the color into the VO that only carries the indentifier of the color?

Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #3 on: November 28, 2009, 02:02:37 »

I guess I don't really understand what it is you're trying to do. Perhaps if you could elaborate a bit more...
Logged
uncleunvoid
Full Member
***
Posts: 27


View Profile Email
« Reply #4 on: November 28, 2009, 07:53:19 »

certainly:
I am using VOs to describe textformats, etc. by xml. At some point I then only have to use the data of the VO to populate the textformat's properties.
In the case of color, I use a either a String Id (e.g. 'darkGrey') to indicate the color value. The color value is stored on another object (on a VO) withe the Id 'darkGrey. This let's me store some kind of color palette for my projects.

Now when I populate the textformat, then I need to use the numeric value. So how best and when would I get the color value through the VO that holds the actual value. How do I merge the two VOs (textformat description and color description) to end up with a complete textformat description and with leaving the original VOs intact as much as possible.
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #5 on: November 29, 2009, 08:07:51 »

So in at least one of these xml files you must have the color name and hex code stored together. Somewhere for lookup, you must have a tag with both attributes. I'll assume this is a color vo. Then you have another xml file with references to color names, but at runtime, you want that color name expanded to a color vo. One proxy fetchs the color xml and holds the color vos, while other reads in the xml that has the color references by name. This other vo should have a color vo for a property. When its proxy is assembling the vos, it should retrieve the color proxy and request the color vo for the color name and set it (or a copy) on the new other vo. It uses the color proxy as a lookup.

-=Cliff>
Logged
uncleunvoid
Full Member
***
Posts: 27


View Profile Email
« Reply #6 on: November 30, 2009, 02:53:11 »

yes cliff, thats exactly what I need, or basically , How i have it for now, yet I would like to maintain the IDs for later saving of the xmls (where the IDs shoudl be used again, not the values)

a probably simple way would be to have a switch function that switches IDs to values and back, but then again there might be two different IDs using the same value. (as we will have external users and internal default palettes, this is a possible scenario)

So the aim is to build a getter setter system that can deliver the right values without changing the ID on the VO's data source.

Donno if that might be over-complicating things.
Maybe I should just go with the switch solution till I run into problems.

Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #7 on: November 30, 2009, 01:30:40 »

This doesn't return color vos or anything, but just quickly, if you had:

:
<colors>
  <color name="green" value="0x00FF00" />
  <color name="grass" value="0x00FF00" />
  <color name="red" value="0xFF0000"/>
</colors>


You could support lookup of color name to value and visaversa and still have multiple color names pointing to the same color value by doing something like this:
:
public class ColorProxy extends Proxy
{
public static const NAME:String = "ColorProxy";               
public function ColorProxy( xml:XML )
{
super ( NAME, xml );
}
       
// get the color value associated with the given color name
public function getColorValueByName( name:String ):String
{
var elements:XMLList = xml..color.[@name==name];
return (elements.length >  0)?elements[0].@value.toString():'';
}

// get the first color name associated with the given color value
public function getColorNameByValue( value:String ):String
{
var elements:XMLList = xml..color.[@value==value];
return (elements.length >  0)?elements[0].@name.toString():'';
}

protected function get xml():XML
{
        return data as XML;
  }
}
}

-=Cliff>
Logged
uncleunvoid
Full Member
***
Posts: 27


View Profile Email
« Reply #8 on: December 01, 2009, 02:44:44 »

wow,

thanks for that reply.

I will have a thorough look at it, but this looks fairly feasible.

Some of the docked xml are a bit more complex, but this solution should bring me a good step ahead.

thanks a  lot.
Logged
Pages: [1]
Print