- Smart Personal Cloud

Dynamic Configuration


Dynamic configuration is a configuration that looks like normal XML but is actually a piece of Star Script program. This configuration can contain programming logic just like any other Star Script program.

Dynamic configuration can be used to create object declaratively. User can also define multiple configurations and use the system function system.findInitMethod to dynamically choose the appropriate configuration based on the application context. This is extremely useful for internationalization and supporting multiple languages.


In the example below, a class is created and that class is instantiated through an XML structure.

class story   var title as string   var section as string[] end

To instantiate a story object, you can either use the statement syntax. such as,

var s = new story() s.title = "my story" s.section = new string[2] s.section[1] = "section 1" s.section[2] = "section 2"

Or you can use the XML syntax, which is much more readable:

var s = <story>     <title>my story</title>     <section>section 1</section>     <section>section 2</section> </story>      s.title                  // should display "my story" s.section.length         // should be 2     

The XML like syntax is allowed to contain programming logic. For example,

var s = <story>     <title>my story</title>     for i = 1 to 10             <section>section i</section>     next </story>      s.title                  // should display "my story" s.section.length         // should be 10     

You can specify multiple configurations based on context and select the appropriate one at runtime.

<init:story variation="long">   <title>my long story</title>   <section>section 1</section>   <section>section 2</section>   <section>section 3</section> </init:story> <init:story variation="short">   <title>my short story</title>   <section>section 1</section> </init:story>

To discover and use the short version of your story configuration, you can use the system.findInitMethod function. For example:

var s = new story() var initMethod = system.findInitMethod(story, null, "short") if initMethod <> null then   initMethod.invoke(s) end s.title              // should print out "my short story"    s.section.length     // should print out "1"