Configurable
|
|
Tagging a class as 'configurable' using the Configurable interace as in:
public class Rate implements Configurable {...}
tells Tricia to allow instances of thisclass to be set by an administrator via the Configurator, a web-tool used by administrators to tune the web-application.
Tricia uses Configurable heavily for all kinds of settings common to all web-applications (setting ports, choosing databases, internationalization etc.). However, your own custom configurable classes can only be implemented in the services package of your plugin.
For example, consider a web shop that offers volume discounts to customers: Beyond a certain volume of purchase, the item price changes. The rebate will change much over time, and you decide that you need the administrator to take care of updating this. You could then create the following class:
package de.infoasset.your-web-shop.services;
import de.infoasset.imf.blackbox.Configurable;
import de.infoasset.imf.blackbox.Property;
public class Rate implements Configurable {
@Property
private int price;
@Property
private int minimalVolume;
public int getMinimalVolume() {
return minimalVolume;
}
public int getPrice() {
return price;
}
}
Notice the @Property annotation. This tells Tricia which members of your class should be configurable. Only primitive types can be annotated with @Property.
Once the configurable class is declared, you can implement instances anywhere in your plugin source code:
import de.infoasset.imf.blackbox.Association;
public class PriceManagementSystem {
....
@Association
public Rate cheap;
@Association
public Rate medium;
@Association
public Rate expensive;
}
Notice the [LINK THIS:]@Association annotation, which actually makes the instance of Rate configurable with the Configurator. Implementing the Configurable interface is a necessary but not a sufficient condition for classes instances to be configured with the Configurator. Annotating with @Association will pull the Configurator's attention to the instance.
QUESTIONS FOR THOMAS:
Do the instances have to be private?
In the configurator, I can add several instances of cheap,medium and expensive. How do I distinguish these 'Instances of Instances'. Isn't this overegineered? I don't think adding instances is an administrator's job, but a developer's.
Is it correct, as I stated above, that instances of configurables can be used in any place in the sourcecode, or is it limited to XXXPlugin.java?
I think the title of the Property Wiki-Page should be changed to @Property to distinguish it from IntProperty and BooleanProperty etc.
 
Tricia - Printout