close

Filter

loading table of contents...

Blueprint Developer Manual / Version 2110

Table Of Contents
4.4.1.2.3 Typed Settings Interfaces

The SettingsService is a powerful multi-purpose tool. However, genericity always comes at the price of abstraction. Assume, there is some business logic which is based on a domain specific interface Address:

          
public interface Address {
  String getName();
  String getCity();
}

public class Messages {
  public static String getHelloMessage(Address address) {
    return "Hello " +
            address.getName() +
            ", are you living in " +
            address.getCity() + "?";
  }
}
        

Example 4.28. Business Logic API


If your actual address data is provided by the SettingsService, it must be adapted to the address interface.

          
class SettingsBackedAddress implements Address {
  // [...] constructor and fields for service and provider bean
  public String getName() {
    return settingsService.setting("name", String.class, bean);
  }
  public String getCity() {
    return settingsService.setting("city", String.class, bean);
  }
}
        

Example 4.29. Settings Address Adapter


Cumbersome, isn't it? Especially, if the interfaces are larger or not yet final. Fortunately, you don't need to implement such interfaces manually, but SettingsService.createProxy does the job for you:

          
class MyCode {
  private SettingsService settingsService;

  void doSomething(BusinessBean beanWithSettings) {
    Address address = settingsService.createProxy(Address.class, beanWithSettings);
    String message = Messages.getHelloMessage(address);
  }
}
        

Example 4.30. Address Proxy


Internally the default settings service intercepts the call to getName() and getCity(). The operation getCity() is translated to settingsService.setting("city", String.class, bean). Note: The property name "city" will be derived from the operation getCity() in the interface. Be aware of this dependency when choosing names for your settings properties and for the operations of your business objects if you want to use the proxy mechanism.

Search Results

Table Of Contents
warning

Your Internet Explorer is no longer supported.

Please use Mozilla Firefox, Google Chrome, or Microsoft Edge.