Advertisement
gpinto

Default value for an array property

Mar 24th, 2011
361
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. * resource descriptor
  3. */
  4. component
  5. output="false"
  6. extends="restfulcf.framework.core.Resource"
  7. hint="resource descriptor"
  8.     {
  9.     // string properties
  10.     property name="path" type="string" default="";
  11.     property name="productName" type="string" default="";
  12.     property name="pageTitle" type="string" default="";
  13.     property name="descriptionTitle" type="string" default="";
  14.     property name="descriptionFull" type="string" default="";
  15.     property name="boxshot" type="string" default="";
  16.     property name="boxshotThumbnail" type="string" default="";
  17.     property name="boxshotMedium" type="string" default="";
  18.     property name="boxshotSmall" type="string" default="";
  19.     property name="upsellDescription" type="string" default="";
  20.     property name="productContactNumber" type="string" default="";
  21.     property name="template" type="string" default="";     
  22.     property name="configuratorTemplate" type="string" default="";
  23.     // array properties: setting the default to 'arrayNew(1)' here, and swapping with arrayNew(1) on init()
  24.     property name="marketingLinks" type="array" default="arrayNew(1)";
  25.     property name="purchaseOptions" type="array" default="arrayNew(1)";
  26.        
  27.     public store.restful.resources.Product function init(required string path = "",
  28.                                                          required string productName = "",
  29.                                                          required string pageTitle = "",
  30.                                                          required string descriptionTitle = "",
  31.                                                          required string descriptionFull = "",
  32.                                                          required string boxshot = "",
  33.                                                          required string boxshotThumbnail = "",
  34.                                                          required string boxshotMedium = "",
  35.                                                          required string boxshotSmall = "",
  36.                                                          required array purchaseOptions = arrayNew(1),
  37.                                                          required string upsellDescription = "",
  38.                                                          required string productContactNumber = "",
  39.                                                          required string template = "",
  40.                                                          required string configuratorTemplate = "",
  41.                                                          required array marketingLinks = arrayNew(1)) {
  42.        
  43.         // logic to swap the 'arrayNew(1)' string to a real empty array
  44.         // this is necessary to preserve the property name in camelCase when serialized to JSON
  45.         var local = {};
  46.         var i = 0;
  47.         var localProp = "";
  48.        
  49.         local.meta = getMetadata(this);
  50.        
  51.         for (i=1; i<=arrayLen(local.meta.properties); i++)
  52.         {
  53.             localProp = local.meta.properties[i];
  54.                
  55.             if (isArray(localProp) || isStruct(localProp))
  56.                 localProp.default = evaluate(localProp.default);
  57.         }
  58.                
  59.         super.init(argumentCollection = arguments);
  60.        
  61.         return this;
  62.     }
  63.  
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement